var obj = null;

function checkHover() {
	if (obj) {
		obj.find('ul').fadeOut('fast');
	}
}

$(document).ready(function() {
	$('#Nav > li').hover(function() {
		if (obj) {
			obj.find('ul').fadeOut('fast');
			obj = null;
		}

		$(this).find('ul').fadeIn('fast');
	}, function() {
		obj = $(this);
		setTimeout("checkHover()", 400);
	});

});


// delayed drop down menu for mouseover
var delay_drop=0;
var timer;
var cleaner;

function dropdownmenu(e, element, type, width, state) {
	if (state == 'run') { // IE isn't passing the event properly to the setTimeout function so need alternate way to set the state
		var tagName="IMG";
	}else {
		var tagName=eventTarget(e).tagName;
	}

	if (tagName == "IMG") {
		var htmlStr = $('#'+element).html();
		if (htmlStr == '')
			$('#'+element).load("/index/list/type/"+type).width(width);

		if (delay_drop >= 4) {
			delay_drop=0;
			$('#'+element).show("fast");
			clearInterval(timer);
			clearInterval(cleaner);
		}else {
			delay_drop++;
			clearInterval(cleaner);
			timer=setTimeout(function() {
				dropdownmenu(e, element, type, width, 'run');
			}, 100);
		}
	}else {
		clearInterval(cleaner);
	}
}

function hidemenu(e, element) {
	cancelBubble(e);
	delay_drop=0;
	clearInterval(timer);
	cleaner=setInterval(function() {
		$('#'+element).hide("fast");
		clearInterval(cleaner);
	}, 1000);
}

function cancelBubble(e) {
	if (!e)
		var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
}

function eventTarget(e) {
	var targ;
	if (!e)
		var e = window.event;
	if (e.target) // FF
		targ = e.target;
	else if (e.srcElement) {// IE
		targ = e.srcElement;
	}
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	return targ;
}