var lastDropDown = "none";
var mouseOverTarget = false;
var mouseOverMenu = false;
function hideDropDownMenu()
{
	if(lastDropDown != "none")
	{
		var temp = lastDropDown;
		lastDropDown = "none";
		//$("#"+temp).slideUp();
		$("#"+temp).hide();
	}
	return true;
}
function addDropDownEventCode(targetname, menuid)
{
// Addine events to the code
	$("#" + menuid).mouseenter(function() {
		mouseOverMenu = true;
	});
	$("li[menu=\""+targetname+"\"]").mouseleave(function() {
		mouseOverTarget = false;
		setTimeout(function() {
			if(!mouseOverTarget && !mouseOverMenu)
				hideDropDownMenu();
		}, 50);
	});
	$("#" + menuid).mouseleave(function() {
		mouseOverMenu = false;
		setTimeout(function() {
			if(!mouseOverTarget && !mouseOverMenu)
				hideDropDownMenu();
		}, 50);
	});
}
function showDropDownMenu(targetname, align, menuid, offsetx, offsety)
{
	mouseOverTarget = true;

	if(lastDropDown == menuid)
		return false;

	if(lastDropDown != "none")
		hideDropDownMenu();

	mouseOverMenu = false;

	// Adds event codes
	addDropDownEventCode(targetname, menuid);

	lastDropDown = menuid;
	var target = $("li[menu=\""+targetname+"\"]");
	var menu = $("#"+menuid);

	var position = target.offset();
	var targetWidth = target.width();
	var targetHeight = target.height();
	
	var menuPosX = 0;
	var menuPosY = 0;
	switch(align)
	{
		case 'center':
			var tcenter = targetWidth / 2 + position.left;
			menuPosX = tcenter - (menu.width() / 2);
			menuPosY = position.top + targetHeight;
			break;
		case 'right':
			menuPosX = (position.left + targetWidth) - menu.width();
			menuPosY = position.top + targetHeight;

			// Offsetting
			menuPosX = menuPosX + 35;
			break;
		default:
			menuPosX = position.left;
			menuPosY = position.top + targetHeight;
			break;
	}

	// Offsetting
	menuPosY = menuPosY + 10;
	
	menu.css('left', menuPosX + offsetx);
	menu.css('top', menuPosY + offsety);

	//menu.slideDown();
	menu.show();
	return true;
}
// For the new drop down menu
$(document).ready(function(){
	$(".dropdown li").click(function() {
		if($(this).hasClass('sublist'))
			return;
		var a = $(this).find('a');
		document.location = a.attr("href");
	});
});