// JavaScript Document

// iTP = imgsToPreload array; iTPi = imgsToPreload index, this allows images to be added to the list later on
var iTP = new Array();
var iTPi = 0;
iTP[iTPi] = "../images/toggle_up_dark.png"; iTPi++;
iTP[iTPi] = "../images/rentalApphl.png"; iTPi++;

function preloadImages(imgs){
	var preloadImage;
	var c = imgs.length;
	for(i = 0; i < c; i++){
		preloadImage = $('<img />').attr('src', imgs[i]);
	}
}

var propertiesMenu = false;
var propertiesSub = false;
var tenantMenu = false;
var tenantSub = false;

$(document).ready(function() {
	
	// Sub Menu
	$('#links a[href=\"properties.php\"]').hover(function(){
		tenantMenu = tenantSub = false;
		$("#sub .tenant").hide(0);
		$("#sub .properties").fadeIn(100);
		propertiesMenu = true;
	}, function(){
		propertiesMenu = false;
		setTimeout('$("#menuWrap").trigger("checkPropertiesSub")', 250);
	});
	
	$('#sub .properties').hover(function(){
		propertiesSub = true;
	}, function(){
		propertiesSub = false;
		setTimeout('$("#menuWrap").trigger("checkPropertiesSub")', 250);
	});
	
	$("#menuWrap").bind('checkPropertiesSub', function(){
		if((!propertiesMenu) && (!propertiesSub)){
			$("#sub .properties").fadeOut(100);
		}
	});
	
	$('#links a[href=\"tenant.php\"]').hover(function(){
		propertiesMenu = propertiesSub = false;
		$("#sub .properties").hide(0);
		$("#sub .tenant").fadeIn(100);
		tenantMenu = true;
	}, function(){
		tenantMenu = false;
		setTimeout('$("#menuWrap").trigger("checkTenantSub")', 250);
	});
	
	$('#sub .tenant').hover(function(){
		tenantSub = true;
	}, function(){
		tenantSub = false;
		setTimeout('$("#menuWrap").trigger("checkTenantSub")', 250);
	});
	
	$("#menuWrap").bind('checkTenantSub', function(){
		if((!tenantMenu) && (!tenantSub)){
			$("#sub .tenant").fadeOut(100);
		}
	});
	
	// Quick Contact Form
	//$("#contact").colorbox({width: "350px", height: "400px", inline: true, href: "#contactDrop form"});
						
	// The active menu link is determined by php and given the class of "active", css is added here via jquery
	$(activeMenuLink).addClass("active");
	
	// Rollover image for the Online Rental Application image
	$("#rentalApp").find("img").hover(function(){
		$(this).attr("src", "images/rentalApphl.png");
	}, function(){
		$(this).attr("src", "images/rentalApp.png");
	});
	
	// Preload images
	preloadImages(iTP);

});

