/*****************/
/* JQUERY onload */
/*****************/

jQuery(document).ready(function() 
{
	//add logo div
	jQuery("BODY").append("<div id='century21-logo'></div>");


	
	//add home page top (home page only)
  	if(jQuery("BODY.home").length)
  	{
		jQuery("#content").prepend("<div id='content-top'><div id='content-top-content'>&nbsp;</div></div>");
		jQuery("#content-top-content").append(jQuery("#searchListings"));
		jQuery("#content-top-content").append("<div id='content-top-buttons'><a href='?act=cst' class='button'>Management Services</a><a href='?act=cst' class='button'>Owners</a></div>");
		
		jQuery("#home-maint A").html('Tenants');		

		jQuery("#content-top-buttons").append(jQuery("#home-maint A"));		
		jQuery("#content-top-content A").wrap("<p></p>");

		jQuery("#content-top-content").append(jQuery("#home-contact"));

	}		
	
		
	//add rounded cxorners to featured (home page only)
  	if(jQuery("BODY.home").length)
  	{
		jQuery("#specialFeatures").prepend("<div id='specialFeatures-top'>&nbsp;</div>");
		jQuery("#specialFeatures").append("<div id='specialFeatures-bottom'>&nbsp;</div>");
	}
	

	//add top/bottom to building (rentals page only)
  	if(jQuery("BODY.rentals ").length)
  	{
		jQuery("BODY.rentals TABLE.ColumnLayout").before("<div id='BuildingTop'>&nbsp;</div>");
		jQuery("BODY.rentals TABLE.ColumnLayout").after("<div id='BuildingBottom'>&nbsp;</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");});
   	}
	 	
	 	

	//add rounded corners to content
	jQuery("#content").append("<div id='content-bottom'>&nbsp;</div>");

	//move the footer to the end of the content area
	jQuery("#content").append(jQuery("#footer"));


});


/**********************************/
/* 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;
	});
}
