/**
 * @author Marco
 */


$(document).ready(function() {
	
	
	
	$('.menu_tab').mouseenter(function() {
		id = $(this).attr("id");
		menu_open( id );
		
	});
	
	$('.menu_tab').mouseleave(function() {
		set_menu_timer();
	});
	
	$(".submenu_block").mouseenter(function(){
		clear_menu_timer();
	})
	$(".submenu_block").mouseleave(function(){
		set_menu_timer();
	})
	
});

var menu_timer, open_menu;

function menu_open( id ){
	
	menu_close()
	//console.log(open_menu)
	clear_menu_timer();
	
	open_menu = id;
	temp = $("#" + id).attr("src");
	temp2 = temp.replace("_off.", "_on.");
	$("#" + id).attr("src",temp2);
	
	sm = id + "_sub";
	$("#" + sm).slideDown();
		
}

function set_menu_timer(){
	
	menu_timer = setTimeout("menu_close()", 500)
	//menu_close();
}

function clear_menu_timer(){
	clearTimeout( menu_timer);
}

function menu_close(){
	
	if (typeof open_menu != "undefined"){
		id = open_menu;
		temp = $("#" + id).attr("src");
		temp2 = temp.replace("_on.", "_off.");
		$("#" + id).attr("src",temp2);
		
		
		sm = open_menu + "_sub";
		$("#" + sm).hide();
		
	}
}


