// Init
var var_menu_over = 0;
var menu_over = 0;
var links_over = 0;
var menu_link;
var menu_oldlink;
var time_long = 2;
var time_short = 1;
var bottomTimeOut;

// On load

$(document).ready(function() {

	$("#upro_menu_bottom").hide(); $("#menu_product").hide(); $("#menu_lab").hide(); $("#menu_support").hide(); $("#menu_buy").hide(); $("#menu_partners").hide();

	// button for iPad
	$("#ipad_gotop").hide();
	if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		$("#ipad_gotop").show();
	}

	// For PC

	$("#upro_menu_bottom").bind('mouseover', function () {
		menu_over = 1;
	});
	$("#upro_menu_bottom").bind('mouseout', function () {
		menu_over = 0;
		setTimeout("bottom_hiding_return()", time_short); 
	});

	$('#menu_links').bind('mouseout', function () {
		// $("#upro_menu_bottom").hide();
		links_over = 0;
		setTimeout("bottom_hiding()", time_short); 
	});


	$('#menu_product_link').bind('mouseover', function () {
		links_over = 1;
		clearTimeout(bottomTimeOut);
		setTimeout("$('#menu_tiret').css({'margin-left':'200px'})", time_long); 
		bottomTimeOut = setTimeout("mouveOverMenu('product',0)", time_long); 
	});


	$('#menu_lab_link').bind('mouseover', function () {
		links_over = 1;
		clearTimeout(bottomTimeOut);
		setTimeout("$('#menu_tiret').css({'margin-left':'340px'})", time_long); 
		bottomTimeOut = setTimeout("mouveOverMenu('lab',0)", time_long); 
	});

	$('#menu_support_link').bind('mouseover', function () {
		links_over = 1;
		clearTimeout(bottomTimeOut);
		setTimeout("$('#menu_tiret').css({'margin-left':'470px'})", time_long); 
		//mouveOverMenu("support",0);
		bottomTimeOut = setTimeout("mouveOverMenu('support',0)", time_long); 
	});


	$('#menu_buy_link').bind('mouseover', function () {
		links_over = 1;
		clearTimeout(bottomTimeOut);
		setTimeout("$('#menu_tiret').css({'margin-left':'590px'})", time_long); 
		//mouveOverMenu("buy",0);
		bottomTimeOut = setTimeout("mouveOverMenu('buy',0)", time_long); 
	});


	$('#menu_partners_link').bind('mouseover', function () {
		links_over = 1;
		clearTimeout(bottomTimeOut);
		setTimeout("$('#menu_tiret').css({'margin-left':'700px'})", time_long); 
		//mouveOverMenu("partners",0);
		bottomTimeOut = setTimeout("mouveOverMenu('partners',0)", time_long); 
	});


	//$('#menu_language_link').bind('click', function () {
	//	 window.location = home_url + /fr/;
	// });


	$('#logo_upro').bind('click', function () {
		 window.location = home_url;
	});

	$('#ipad_gotop').bind('click', function () {
		menu_over = 0;
		setTimeout("bottom_hiding_return()", time_short); 
	});




	// For iPad

	$('#menu_product_link').bind('click', function () {
		links_over = 1;
		setTimeout("$('#menu_tiret').css({'margin-left':'200px'})", time_long); 
		setTimeout("mouveOverMenu('product',0)", time_long); 
	});


	$('#menu_lab_link').bind('click', function () {
		links_over = 1;
		setTimeout("$('#menu_tiret').css({'margin-left':'340px'})", time_long); 
		setTimeout("mouveOverMenu('lab',0)", time_long); 
	});

	$('#menu_support_link').bind('click', function () {
		links_over = 1;
		setTimeout("$('#menu_tiret').css({'margin-left':'470px'})", time_long); 
		//mouveOverMenu("support",0);
		setTimeout("mouveOverMenu('support',0)", time_long); 
	});


	$('#menu_buy_link').bind('click', function () {
		links_over = 1;
		setTimeout("$('#menu_tiret').css({'margin-left':'590px'})", time_long); 
		//mouveOverMenu("buy",0);
		setTimeout("mouveOverMenu('buy',0)", time_long); 
	});


	$('#menu_partners_link').bind('click', function () {
		links_over = 1;
		setTimeout("$('#menu_tiret').css({'margin-left':'700px'})", time_long); 
		//mouveOverMenu("partners",0);
		setTimeout("mouveOverMenu('partners',0)", time_long); 
	});



});



function mouveOverMenu (var_menu_link, var_menu_over) {
// if nouvelle var diff de old var
	var hauteur_bottom = $("#upro_menu_bottom").height();
	if ((var_menu_link == menu_oldlink)&&(hauteur_bottom == 140)) {
		
	} 
	else {  
		mouveOutMenu(menu_oldlink,0);
		$("#menu_product").hide(); $("#menu_lab").hide(); $("#menu_support").hide(); $("#menu_buy").hide(); $("#menu_partners").hide();
		$("#menu_"+var_menu_link).stop(true, true).show();
		$("#menu_"+var_menu_link+"_link").stop(true, true).animate({"color":"#BDCDE3"}, "slow");
		$("#upro_menu_bottom").stop(true, true).height("140px");
		$("#upro_menu_bottom").stop(true, true).show("slide", { direction: "up" }, 1000);
		menu_oldlink = var_menu_link;	

	}

}

function mouveOutMenu (var_menu_link, var_menu_over) {
// si on est pas au dessus de la zone bottom
	if(menu_over == 0) {
		$("#menu_"+var_menu_link+"_link").stop(true, true).animate({"color":"#ffffff"}, "slow");
		$("#upro_menu_bottom").stop(true, true).height("0px");
		$("#upro_menu_bottom").stop(true, true).hide();
	}
}

function bottom_hiding() {
	if(menu_over == 0) {
		mouveOutMenu(menu_oldlink,0);
	}
}
function bottom_hiding_return() {
	if((links_over == 0)&&(menu_over == 0)) {
		mouveOutMenu(menu_oldlink,0);
	}
}






// Slide vers le haut : $("#upro_menu_container").hide("slide", { direction: "up" }, 1000);
// Hide :        	$("#upro_menu_container").hide();
// HTML :		$('#aideInternaute').html('<h3>' + contentPseudo + ', vous pouvez poser vos questions :</h3>');
// Get value : 		$('#pseudo').get(0).value;



