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

jQuery(document).ready(function() 
{
	//move more info column after description column
  	if(jQuery("BODY.rentals").length)
	{
	 	jQuery("div.column_4").each(function(i){
		   	var html4=jQuery("div.column_4").get(i).innerHTML;
		   	var html5=jQuery("div.column_5").get(i).innerHTML;
			jQuery("div.column_4").get(i).innerHTML=html5;
			jQuery("div.column_5").get(i).innerHTML=html4;
		});

		//move community info into top box (column layout/column 2)
		//if(jQuery("TD.Col2").length && jQuery("#dataSection-Community").length) 
		//	jQuery("TD.Col2").append(jQuery("#dataSection-Community"));

		jQuery("DIV.PropertyImage IMG").wrap("<div class='PropertyImageBox'></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");});
   	}
	 	
	
	jQuery("#navigation").wrap("<div id='left'></div>");
	jQuery("#navigation").wrap("<div class='nav_dropshadow'></div>");

  	//move featured elements around (home page only)
  	if(jQuery("BODY.home").length)
	{
		jQuery("DIV.featuredListing h2").prependTo(jQuery("DIV.image"));
		jQuery("DIV.featuredListing DIV.description").appendTo(jQuery("DIV.location"));

		jQuery("DIV.featuredListing A.button").appendTo(jQuery("DIV.image"));
		jQuery("DIV.featuredListing A.button").wrap("<p></p>");

		jQuery("DIV.featuredListing DIV.image IMG").wrap("<div class='dropshadow'></div>");
	}				

	jQuery("#container").append("<div id='footer-image'><a href='http://www.realpropertymgt.com'></a></div>");

  	//special home page items in left hand column, according to external JS parameters
	if(jQuery("BODY.home").length && (SHOW_SERVICE_REQUEST_LINK || SHOW_PAY_RENT_LINK))
  	{
		jQuery("#left").append("<div id='home_special'></div>");
		jQuery("#home_special").append("<div id='home_tenants_header'></div><br>");
		if(SHOW_SERVICE_REQUEST_LINK)
		{
			jQuery("#home_special").append("<div id='home_service_header'></div>");
			jQuery("#home_special").append("<div class='home_special_content'>Need to submit a maintenance requests for needed repairs? Log into your Tenant Portal to report and track any issues.<br><a href='"+TENANT_PORTAL_URL+"'>Click Here &gt;&gt;</a></div><br>");		
			jQuery("#home_special").append("<br>");
		}
		if(SHOW_PAY_RENT_LINK)
		{
			jQuery("#home_special").append("<div id='home_pay_header'></div>");
			jQuery("#home_special").append("<div class='home_special_content'>Paying your rent has never been easier.  Simply log into your Tenant Portal and pay your rent, deposits, or any other charges with your credit card or checking account 24 hours a day, 7 days a week.<br><a href='"+TENANT_PORTAL_URL+"'>Click Here &gt;&gt;</a></div><br>");				
		}	    
	}
});


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


