$(document).ready(function() {

$('<div class="clear-left"></div>').insertAfter('.node-type-property .field-field-price');


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

	$('.view-listings-flavors-clone a .row').each(function() {
			var status = $(this).attr('status');
			$(this).attr('status','');
			$(this).parent().parent().parent().parent().addClass(status);			
		});
	
	// ---  Start Input Box Interactivity   [not used]
	
	$('#edit-submitted-phone').each(function() {
			var default_value = this.value;
			$(this).focus(function() {
					if(this.value == default_value) {
							this.value = '';
					}
			});
			$(this).blur(function() {
					if(this.value == '') {
							this.value = default_value;
					}
			});
	});

//--- Makes Listings Background Alternate

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


// --- Make links open in new window

	$(".view-folio-docs .filefield-file a").each(function() {
		$(this).attr("target", "_blank");
	});


//---- Lightbox Multi-View   [ -- Dont' forget the CSS and to enable the Lightbox 2 Module!!! -- ]
	// 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-property-images-fid-1';
	var hidden_details = '.views-field-field-property-images-fid';
	var visible_detail = '.views-field-field-property-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'));
		});
	});



// Read a page's GET URL variables and return them as an associative array.
	function getUrlVars()
	{
			var vars = [], hash;
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			for(var i = 0; i < hashes.length; i++)
			{
					hash = hashes[i].split('=');
					vars.push(hash[0]);
					vars[hash[0]] = hash[1];
			}
			return vars;
	}

//--- Grabs argument from URL and places into a text field

	var first = getUrlVars()["url"];
	$(".node-type-webform input#edit-submitted-listing-link").val("http://www.LizLauer.com" +first);
//	$("input#edit-submitted-listing-link").attr('disabled','disabled');	



// --- Ugly IE7 Hack -- hide, then show Sidebar Right
	$('#sidebar-right').css('display', 'none');			
	$('#sidebar-right').css('display', 'block');				


//--- Open links in new window

	$("li").each(function() {
		$("a[href^='http']").attr('target','_blank');
	}); 



//--- Add emphasis to some primary links

	$('#primary .links').html($('#primary .links').html().replace('>Seller','><span class="gold">Seller</span>'));
	$('#primary .links').html($('#primary .links').html().replace('>Buyer','><span class="gold">Buyer</span>'));	
	$('.node-type-property .field-field-price .field-item').prepend('$');		

});
