/* JavaScript Document
$(document).ready(function ()
{
	$("#head").hide().after("<div id=\"flash\"></div>");
	$("#flash").flash(
			{ src: './img/flash.swf',
			  width: 948,
			  height: 328 }
		);
});
*/

function directions()
{
	$(".directionsForm").slideToggle();	
}

var hideTimer = setTimeout("", 100);

//BEGIN AMENITIES FUNCTIONS AND VARIABLES
var popupTimer = setTimeout("", 100); //for amenities popup
function hidePopup()
{
	$("#popupWrapper").removeShadow();
	$("#popupWrapper").fadeOut('fast', function ()
	{
		$("#popupPhoto img").attr('src', "images/clear.gif");
	});
}
//END AMENITIES FUNCTIONS AND VARIABLES


function hideColumn()
{
	$("#columnInfo").fadeOut('fast', function()
	{
		$("body").attr("class", "siteplan");
		$("#columnInfo").html("");
		$("#columnInfo").hide();
		$("#siteDirections").fadeIn();
	});
}
$(document).ready(function(){
						   
	//POPUP IMAGES ON AMENITIES	  
	/*
			left    : integer (default = 4)
		top     : integer (default = 4)
		blur    : integer (default = 2)
		opacity : decimal (default = 0.5)
		color   : string (default = "black")
		swap    : boolean (default = false)
		*/
		
	$(document).click(function()
	{
		popupTimer = setTimeout("hidePopup()", 200);
	});
	
	$("#popupWrapper").dropShadow({top:1, left:1, blur:4});
	$("#popupWrapper").removeShadow();
	$("a.photo").click(function ()
	{
		
		var y = $(this).offset();
		var top = y.top - 100;
		//alert(y.top);
		$("#popupWrapper").css({'top': top +'px'});
		$("#popupWrapper").stop(true, true);
		clearTimeout(popupTimer);
		$("#popupPhoto img").attr('src', $(this).attr('href'));
		$("#popupWrapper").fadeIn('normal', function()
		{
			$("#popupWrapper").redrawShadow();
		});
		return false; //don't follow the link
	});
	
	/*
	$("#popupPhoto").hover(function ()
	{
		clearTimeout(popupTimer);
	},
	function ()
	{
		popupTimer = setTimeout("hidePopup()", 200);
	});				
	*/
				
				
	$("#resetForm").click();
						   
	//Include homepage flash
	if($("#home").val() == "yes")
	{
		$("#logo").remove();
		$("#header").html("").css({"height":"328px"}).flash(
			{ src: './flash/flash_home.swf',
			  width: 938,
			  height: 328 }
		);
	}
	
	$("#registerFlash").flash(
			{ src: './flash/affordable_homes.swf',
			  width: 369,
			  height: 59 }
		);
	
	$("#home-house").html("").flash(
			{ src: './flash/home_slideshow.swf',
			  width: 287,
			  height: 215 }
		);
	$("#other-slideshow").html("").flash(
			{ src: './flash/other_slideshow.swf',
			  width: 258,
			  wmode: 'transparent',
			  height: 177 }
		);	
	
	$("#prequalifyFlash").flash({
		src: './flash/preQualify.swf',
		width: 230,
		height: 95
	});
	
		$("#prequalifyFlashHome").flash({
		src: './flash/preQualify_home.swf',
		width: 230,
		height: 40
	});
	
	//Mark current page as active
	var location = new String(document.location); 
	var page = location.split('/'); 
	var currentPage = page[3];
	var currentPage_noQ = page[3].split("?");
	var noQ = currentPage_noQ[0];
	$("a").each(function()
	{
		if($(this).attr('href') == currentPage || $(this).attr('href') == "/"+currentPage || $(this).attr('href') == noQ || $(this).attr('href') == "/"+noQ)
		{
			$(this).addClass("currentPage");	
		}
	});

	
	//hightlight Floorplan for res1 res2 and res3
	$(".currentPage").each(function()
	{
		if($(this).attr('href') == "./residence1.php" || $(this).attr('href') == "./residence2.php" || $(this).attr('href') == "./residence3.php" || $(this).attr('href') == "./residence4.php")
		{
			$("#floorplanLink").addClass("currentPage");	
		}
	});
	
	//Hide Columin info initially
	$("#columnInfo").hide();
	
	$("area").click(function ()
	{
		var residenceNumber = $(this).attr('alt').substr(10, 1);
		var reversed = $(this).attr('alt').indexOf("Reversed");
		var url = "residence" + residenceNumber + ".php";
		if(reversed > 0)
			url = url+"?flip=1";
		window.location=url;
		return false;
	});
	$("area").hover(function ()
	{
		$("#siteDirections").hide();
		clearTimeout(hideTimer);
		var residenceNumber = $(this).attr('alt').substr(10, 1);
		var file = $(this).attr('alt').substr($(this).attr('alt').indexOf("| ")+2, 5);
		$("#left").attr("class", "plan" + residenceNumber);
		$("#columnInfo").show();
		//$("#columnInfo").load("site_plan/" + file + ".html", '', function()
		//{
			$("#columnInfo").html($("#textHolder").children("#" + file ).html());
			$("#siteDirections").hide();
			$("#columnInfo").show();
		//});
	}, function ()
	{
		hideTimer = setTimeout("hideColumn()", 300);
	});
	
	$("#Driving_Directions").hover(function ()
	{
		$("#Driving_Directions").attr('src', 'images/directionsb.gif');
	}, function ()
	{
		$("#Driving_Directions").attr('src', 'images/directionsa.gif');
	});
	
	$(".directionsForm").hide();
	$("#toggleDirections").html("").flash(
			{ src: './flash/driving_directions.swf',
			  width: 381,
			  height: 32
			 }
		);	
	
});
