/* Author: 
Luca Fregoso | info@s2kagency.com
*/
$(window).load(function(){
	handleMouseMove();
});
$("html").live("mousemove",function(e){
	handleMouseMove();	
});
$(".load-item").live("click",function(e){
	handleMouseMove();	
});
function hideMenu(){
	$("#main-menu-container,.load-item").stop().fadeTo(500,0,function(){
		$(this).hide();
	});
}
function showMenu(){
	var $menu = $("#main-menu-container,.load-item");
	if($menu.css('opacity')!=1)
		$menu.stop().show().fadeTo(300,1);
}
$(".sibling-open").css("cursor","pointer").live("click",function(e){
	e.preventDefault();
	e.stopPropagation();
	var $_this = $(this);
	var level = $_this.data('level');
	var $siblings = $_this.siblings();
	var $parent = $_this.parent().parent();
	$_this.parent().not($("#main-menu>li:first-child")).toggleClass('enabled');
	if(!$_this.parent().is('.enabled')){
		margintop = 0;
	}else{
		margintop = '20px';
	}
	$_this
		.parent()
			.stop()
			.animate({'margin-top':margintop});
	$(".enabled")
		.not($_this.parent())		
			.removeClass('enabled')
			.animate({'margin-top':0});
	$(".sub-menu[data-level="+level+"]")
		.not($siblings)
			.slideUp()
			.end()
		.filter($siblings)
			.slideToggle()
			.toggleClass('expanded')
			.end();
});

function handleMouseMove(){
	showMenu();
	var $_this = $("body");
	var newTimeout = setTimeout(function(){
			hideMenu();			
	},5000);
	clearTimeout($_this.data("toHide"));
	$_this.data("toHide",newTimeout);
}




















