// JavaScript Document

//-------------------------------------
// -------- Scripts for price ---------
//-------------------------------------
$(document).ready(function() {
	$(".gallery").nivoSlider({effect: 'fade', controlNav: false});
	fillQuickBuy();
	$("#quick_buy").click(function() {
		fillQuickBuy();
	});
	$("#quick_rent").click(function() {
		fillQuickRent(); 
	});
});

function fillQuickBuy() {
	$('#pricefrom').empty().jOptions({list: buyPrices});
	$('#priceto').empty().jOptions({list: buyPrices.reverse()});
	$('#proptype').empty().jOptions({list: buyTypes});
	buyPrices.reverse();
}

function fillQuickRent() {
	$('#pricefrom').empty().jOptions({list: rentPrices});
	$('#priceto').empty().jOptions({list: rentPrices.reverse()});
	$('#proptype').empty().jOptions({list: rentTypes});
	rentPrices.reverse();
}


//-------------------------------------
//------ Scripts for menu stuff -------
//-------------------------------------

//set global variables
currMain = 0; //keep track of the main menu hovered on
currSub = 0; //keep track of the submenu hovered on

//this function will run when the page loads and change the size of the submenus
function completeMenu()
{
	//loop through the submenus, setting up hover and mouseleave
	var tempText = $("#submenuArray").html();
	var submenuArray = tempText.split("&amp;");
	var numSubmenus = submenuArray.length;
	
	for (i=1; i<=numSubmenus; i++)
	{
		$("#submenu_" + submenuArray[i]).bind("mouseleave", function() { currSub=0; hideSubmenu($(this).attr('menuNum')); });
		$("#menuTd_" + submenuArray[i]).bind("mouseenter", function() { currMain=$(this).attr('menuNum'); displaySubmenu($(this).attr('menuNum')); });
		$("#submenu_" + submenuArray[i]).bind("mouseenter", function() { currSub=$(this).attr('menuNum'); });
		$("#menuTd_" + submenuArray[i]).bind("mouseleave", function() { currMain=0; hideSubmenu($(this).attr('menuNum')); });
	}
}

//this function will be called when a main menu is hovered that has a sub menu
function displaySubmenu(showDiv)
{
	//hide all other menus
	$(".submenuDiv").hide();
	//show requested item
	$("#submenu_" + showDiv).show();
}

//this function runs when the submenu is mouseouted
function hideSubmenu(hideDiv)
{
	//hide the requested submenu
	if (currMain != hideDiv && currSub != hideDiv)
	{
		$("#submenu_" + hideDiv).hide();
	}
}

