$(document).ready(function() {

// ----  Lightbox interactivity

	//--- Changes Medium Image
	$('#block-views-property_images-block_2 img').each(function (i) {
			$(this).bind('mouseenter',function(e){
				detailimg = $(this).parent().parent().parent().parent().find('.views-field-field-property-images-fid img').attr('src');
				linkobj = $(this).parent();
				$('#block-views-property_images-block_1 img').attr('src',detailimg);
				$('#block-views-property_images-block_1 a').attr('href',linkobj.attr('href'));
			});
		});

	//--- Changes href so that lightbox shows correct image
// 	$('#block-views-property_images-block_2 img').each(function (i) {
// 		$(this).bind('mouseenter',function(e){
// 			detailhref = $(this).parent().parent().parent().parent().find('.views-field-field-property-images-fid-1 img').attr('src');
// 			fullhref = detailhref.replace("property_thumbs", "property_full");
// 			$('#block-views-property_images-block_1 a').attr('href',fullhref);
// 		});
// 	});



//--- Fixes shadow display issue with IE

	$.fn.delay = function(time, callback){
			// Empty function:
			jQuery.fx.step.delay = function(){};
			// Return meaningless animation, (will be added to queue)
			return this.animate({delay:1}, time, callback);
	}

	$('a').delay(100, function(){
		$("#l-content-border").height("100%");
		$("#r-content-border").height("100%");
	});

//--- Makes seperate lines of links function as one

	$('.view-open-house .views-row').bind('mouseenter mouseleave', function() {
		$(this).toggleClass('hover');
	});

	$('#block-views-home_four_blocks-block_1 .views-row').bind('mouseenter mouseleave', function() {
		$(this).toggleClass('hover');
	});



//----These blocks set up a mouseenter event system that replaces the visible detail image with a
	//    detail image matching the moused-over thumbnail
	// Visible Thumbnails are in  .views-field-field-images-fid-1
	// Hidden Details are in      .views-field-field-images-fid
	// Visible Detail image is    .views-field-field-images-fid-2

	var view_class = '.view-id-lightbox_multi_view';
	var visible_thumbs = '.views-field-field-images-fid-1';
	var hidden_details = '.views-field-field-images-fid';
	var visible_detail = '.views-field-field-images-fid-2';

	//Give field-images matching item numbers
	$(view_class+' .views-row').each(function() {
		var itemid = 0;
		var sibling = $(this).find(hidden_details+' .field-item:first-child');
		$(this).find(visible_thumbs+' .field-item').each(function() {
			$(this).attr('itemid',itemid);
			sibling.attr('itemid',itemid).addClass('item-'+itemid);
			sibling = sibling.next();
			itemid++;
		});
	});
	//Add mouseenter events to each of the thumbnail images
	$(view_class+' '+visible_thumbs+' img').each(function (i) {
		$(this).bind('mouseenter',function(e){
			viewsrow = $(this).parent().parent().parent().parent().parent();
			var itemid = $(this).parent().parent().attr('itemid');
			var linkobj = $(this).parent();

			previewimg = viewsrow.find(hidden_details+' .item-'+itemid+' img').attr('src');
			viewsrow.find(visible_detail+' img').attr('src',previewimg);
			viewsrow.find(visible_detail+' a').attr('href',linkobj.attr('href'));
		});
	});
	

});
