/*

	Main menu management functions.

*/

initMenu();

function initMenu()
{
	if(currentMenuItem == 0)
	{
		return;
	}
	
	onTop = false;
	onBottom = false;
	
	prevNum = currentMenuItem - 1;
	nextNum = currentMenuItem + 1;
	
	if(prevNum == 1)
	{
		onTop = true;
	}
	
	if(nextNum == totalMenuItems)
	{
		onBottom = true;
	}
	
	if(onTop)
	{
		changeBgr(prevNum, 'logo_active/jpg');
		changeBgr(currentMenuItem, 'bg_active/jpg');
		changeBgr(nextNum, 'divider_active_top/jpg');
	}
	else if(onBottom)
	{
		changeBgr(prevNum, 'divider_active_bottom/jpg');
		changeBgr(currentMenuItem, 'bg_active/jpg');
		changeBgr(nextNum, 'bottom_active/jpg');
	}
	else
	{
		changeBgr(prevNum, 'divider_active_bottom/jpg');
		changeBgr(currentMenuItem, 'bg_active/jpg');
		changeBgr(nextNum, 'divider_active_top/jpg');
	}
}

function mouseOverHandler(sender)
{
	onTop = false;
	onBottom = false;
	
	parentDiv = $(sender).parent();
	
	parentDivId = parentDiv.get(0).id; 
	
	idParts = parentDivId.split("_");
	
	currentNum = parseInt(idParts[1]);
	
	prevNum = currentNum - 1;
	nextNum = currentNum + 1;
	
	if(prevNum == 1)
	{
		onTop = true;
	}
	
	if(nextNum == totalMenuItems)
	{
		onBottom = true;
	}
	
	if(onTop)
	{
		changeBgr(prevNum, 'logo_active/jpg');
		changeBgr(currentNum, 'bg_active/jpg');
		
		if(currentNum == (currentMenuItem - 2))
		{
			changeBgr(nextNum, 'divider_active_both/jpg');
		}
		else
		{
			changeBgr(nextNum, 'divider_active_top/jpg');
		}
	}
	else if(onBottom)
	{
		if(currentNum == (currentMenuItem + 2))
		{
			changeBgr(prevNum, 'divider_active_both/jpg');
		}
		else
		{
			changeBgr(prevNum, 'divider_active_bottom/jpg');
		}		
		
		changeBgr(currentNum, 'bg_active/jpg');
		changeBgr(nextNum, 'bottom_active/jpg');
	}
	else
	{
		if(currentNum == (currentMenuItem + 2))
		{
			changeBgr(prevNum, 'divider_active_both/jpg');
		}
		else
		{
			changeBgr(prevNum, 'divider_active_bottom/jpg');
		}
		
		changeBgr(currentNum, 'bg_active/jpg');
		
		if(currentNum == (currentMenuItem - 2))
		{
			changeBgr(nextNum, 'divider_active_both/jpg');
		}
		else
		{
			changeBgr(nextNum, 'divider_active_top/jpg');
		}
	}
}

function mouseOutHandler(sender)
{
	onTop = false;
	onBottom = false;
	
	parentDiv = $(sender).parent();
	
	parentDivId = parentDiv.get(0).id; 
	
	idParts = parentDivId.split("_");
	
	currentNum = parseInt(idParts[1]);
	
	prevNum = currentNum - 1;
	nextNum = currentNum + 1;
	
	if(prevNum == 1)
	{
		onTop = true;
	}
	
	if(nextNum == totalMenuItems)
	{
		onBottom = true;
	}
	
	if(onTop)
	{
		changeBgr(prevNum, 'logo_inactive/jpg');
		changeBgr(currentNum, 'bg_inactive/jpg');
		changeBgr(nextNum, 'divider_inactive_top/jpg');
	}
	else if(onBottom)
	{
		changeBgr(prevNum, 'divider_inactive_bottom/jpg');
		changeBgr(currentNum, 'bg_inactive/jpg');
		changeBgr(nextNum, 'bottom_inactive/jpg');
	}
	else
	{
		changeBgr(prevNum, 'divider_inactive_bottom/jpg');
		changeBgr(currentNum, 'bg_inactive/jpg');
		changeBgr(nextNum, 'divider_inactive_top/jpg');
	}
	
	initMenu();
}

function changeBgr(num, bgr)
{
	idStr = "#mnu_" + num;
	
	bgrUrl = "url(" + siteUrl + "cache/get/" + bgr+")";
	
	$(idStr).css("background-image", bgrUrl);
	
	/* BEGIN LEKARI FIX *
	if(bgr == 'bg_inactive/jpg')
	{
		$('#mnu_'+num+' > a').css("color", "red");
	}
	else if(bgr == 'bg_active/jpg')
	{
		$('#mnu_'+num+' > a').css("color", "white");
	}
	/* END LEKARI FIX */
}