jQuery(document).ready(function() 
{
	//add bg image
	jQuery("BODY").append("<div id='bg-image'></div>");
	
	//move featured elements around (home page only)
  	if(jQuery("BODY.home").length)
  	{
		jQuery("DIV.featuredListing h2").prependTo("DIV.featuredListing DIV.location");
		jQuery("DIV.featuredListing A.button").appendTo("DIV.featuredListing DIV.location");
		jQuery("DIV.featuredListing A.button").wrap("<p></p>");
	}
	
	//move search to header
  	if(jQuery("BODY.home").length)
  	{
		jQuery("#searchListings").prependTo(jQuery("#header"));
	}
	else //fill the void
  	{
		jQuery("#header").append("<div id='header_filler'></div>");
	}
	
	//add image to content
  	if(jQuery("BODY.home").length)
  	{
		jQuery("#homePageContent").prepend("<div id='home-image'></div>");
	}


	//fix gallery (rentals page only - bldg/unit)
  	if(jQuery("BODY.rentals").length)
  	{
		//wrap for v-align...
 		jQuery("DIV.Thumbnail IMG").wrap("<div class='thumbnail_align'></div>");

		jQuery("DIV.Thumbnail IMG").each(function(i){
		    this.onload=function(){ImageLoaded(i);};
		});
 	}

	//fix row hover for IE - rentals page
  	if(jQuery("BODY.rentals").length)
	{	
   	   jQuery("TABLE.list tr").hover(
		   function(){jQuery(this).addClass("hover");},
		   function(){jQuery(this).removeClass("hover");});
   	}

	//unit/detail bordering - rentals page
  	if(jQuery("BODY.rentals").length)
	{	
		jQuery("TABLE.ColumnLayout").wrap("<div id='ColumnLayout_wrap'></div>");
   	}
	 	

	//change tenants page layout
  	if(jQuery("BODY.tenants").length)
  	{
		jQuery("#layoutDiv2").after(jQuery("#layoutDiv1"));
	}


});



/**********************************/
/* Gallery Image Loading Callback */
/**********************************/

var loaded_images=new Array();
function ImageLoaded(index)
{
	loaded_images[index]=true;

	for(var i=0;i<jQuery("DIV.Thumbnail IMG").length;i++)
	{
		if(!loaded_images[i]) return;
	}			

	//if loaded, positionbased on height
	//max image height...
	var max_h=0;
	jQuery("DIV.Thumbnail IMG").each(function(i){
		if(this.height>max_h) max_h=this.height+5;
	});
	
	//align images bottom...
	jQuery("DIV.Thumbnail DIV.thumbnail_align").each(function(i){
		this.style.marginTop = max_h-jQuery("DIV.Thumbnail IMG").get(i).height;
	});
}
