
var fadeInDelay = 200;
	var fadeOutDelay = 100;
	var betweenMenusDelay = 700;
	var validationDelay = 800;


var menu = {
	_clearAllTimer: 0,
	_hideOthersTimer: 0,
	_showMenuDelay: 0,
	_validateTimer: 0,
	_hideAll: false,
	
	_visibleLi: null,
	
	showLiPath:function(el) {
		clearTimeout(menu._clearAllTimer);
		clearTimeout(menu._hideOthersTimer);
		
		$('#mid-menu li.current').removeClass('current');
		var current = $(el).parents().filter('li').add(el);
		current.addClass('current');
		menu.show(current.children('.sub-menu:hidden'));

		// make a timeout to remove all visible li without the current flag
		
		menu._hideOthersTimer = setTimeout(menu._clearOthers, 50);
	},
	
	
	_clearOthers: function() {
		
		$('#mid-menu .sub-menu:visible').each(function() {
			if($(this).parent('.current').length == 0) {
				menu.hide($(this));
			}
		});
		
	},
	
	_validate: function() {
		$('#mid-menu .current').each(function() {
			var child = $(this).children('.submenu:hidden');
			if(child.length != 0) {
				menu.show(child);
			}
		});
	},
	
	_checkIfShouldStayVisible: function(el) {
		//console.log($(el).parent().filter('.currnet').length);
		if($(el).parent('.current').length == 0)
			menu.hide($(el));
		
	},
	
	clearAll: function() {
		clearTimeout(menu._clearAllTimer);
		clearTimeout(menu._hideOthersTimer);
		$("#mid-menu .current").removeClass('current');
		menu._clearAllTimer = setTimeout(function() {
			menu.hide($('#mid-menu .sub-menu:visible'));
		}, betweenMenusDelay);
	},
	
	
	
	
	hide: function (el) {
		$(el).fadeOut(fadeOutDelay);
	},
	show: function (el) {
		$(el).fadeIn(fadeInDelay, function() {menu._checkIfShouldStayVisible(el);});
	}


}
$(function(){
	$('#mid-menu .sub-menu').each(function() {
//		console.log($(this).parent().outerWidth());
		$(this).css('left', $(this).parent().offset().left + 200);
		$(this).css('top', $(this).parent().offset().top);
	});

	$('#mid-menu li a').bind('click', function() {
		menu.showLiPath($(this).parent());
		
		
	}).parent().bind('mouseover', function() {
		clearTimeout(menu._clearAllTimer);
	}).bind('mouseout', function() {
		menu.clearAll();
	});
	
});