var currentLanguage = "IT";

function buildMenuBar() {

	/* We set the plane icon on the first menu item */
	$("#item1016").attr("class",'itemPlane');

	/* Drop all the empty 2rd level navigation */
	$("#nav li").each(function(){
		/* We first check if the menu is already selected */			
		var isPlane = $(this).children("a").hasClass("itemPlane");	

		/* We drop the link and the "hand cursor" on all the first level navigation item having sub navigation */
		if ($(this).children(".subNavigation").children("li").length > 0 && !isPlane) {
			$(this).children("a").attr("href",'javascript:void(0);');				
			$(this).children("a").attr('style','cursor: default');
			/* Add the bottom box (just to get round corners) */
			$(this).children(".subNavigation").append('<li id="subMenuBottom">&nbsp;</li>');
		}

		if ($(this).children(".subNavigation").children("li").length == 0 || isPlane) {	
			/* We didn't realy drop the ul element but put the class to emptyNavigation instead of subNavigation */
			$(this).children(".subNavigation").children("li").remove();
			$(this).children(".subNavigation").addClass("emptyNavigation");
			$(this).children(".subNavigation").removeClass("subNavigation");
		}
	});

	/* Remove webcheckin 3rd level */
	$('#subItem840').remove();	
	
	/* Drop all the empty 3rd level navigation */
	$("#nav li ul li").each(function(){
		/* We drop the link and the "hand cursor" on all the first level navigation item having sub navigation */
		if ($(this).children(".subSubNavigation").children("li").length > 0) {			
			/* Remove the link */		
			$(this).children("a").attr("href",'javascript:void(0);');
			/* Add the bottom box (just to get round corners) */
			$(this).children(".subSubNavigation").append('<li id="subSubMenuBottom">&nbsp;</li>');
			$(this).children(".subSubNavigation").children("li:first").prepend('<div class="subMenuIndicator"></div>');

		}
		if ($(this).children(".subSubNavigation").children("li").length == 0) {
			$(this).children(".subSubNavigation").remove();
		}
	});

	$('ul.sf-menu').superfish({
		hoverClass : 'sfHover',
 		pathClass : 'current',
 		pathLevels : 1,
 		delay : 300,
 		animation : {opacity:'show'},
 		speed : 0,
		autoArrows : true,
		dropShadows : false,
		disableHI : false
	});

	$('ul.sf-menu > li > a .sf-sub-indicator').remove();  
	$('.sf-sub-indicator').html("");

	/* For each menu we provide an "hover" behaviour */
	$("#nav li").each(function(){
		$(this).mouseout(function(){
			$(this).attr("class",'item');
		});

		$(this).mouseover(function(){

			/* We first check if the menu is already selected */			
			var isPlane = $(this).children("a").hasClass("itemPlane");	
			var isPromo = $(this).children("a").attr("id") == "itemPromos";

			if(!isPlane) {			
				/* If the nenu own a submenu */
				if ($(this).children(".subNavigation").children("li").length > 0 || isPromo ) {
					$(this).attr("class",'itemOver');			
				} else {
					$(this).attr("class",'itemOverFull');
				}		
			}					
		});
	
	});


}

function setPlaneMenuItemOn() {
	$("#item1016").children(".menu_left").attr("class",'menu_left_on');	
	$("#item1016").children(".menu_middle").attr("class",'menu_middle_on');	
	$("#item1016").children(".menu_right").attr("class",'menu_right_on');
}

function setPlaneMenuItemOff() {
	$("#item1016").children(".menu_left_on").attr("class",'menu_left');	
	$("#item1016").children(".menu_middle_on").attr("class",'menu_middle');	
	$("#item1016").children(".menu_right_on").attr("class",'menu_right');

}

function setHeaderBehaviour(currentLang, currentSite) {
	setHeaderLoginText();

	/* Set an hover behaviour in order to display the login / language change box */
	$("#header-top-interaction").hover(function(event){
		$("#header-top-interaction").addClass('active');
		var content = $('.content', this);
		if(!content.is(':animated')) content.show();
	}, function(){
		$(this).removeClass('active');
		var content = $('.content', this);
		if(!content.is(':animated')) content.hide();			
	}); 
	
	/* Configure the home link on the header logo */
	$("#headerLink").click(function() {
       	window.location = "http://www.luxair.it/cms/luxair.php?page&p=" + currentLang + ",43577,,,,,";
       });	


	/* Configure the language dropDown */
	$(".dropdown dt a").click(function() {
                $(".dropdown dd ul").toggle();
       });

	$(".dropdown2 dt a").click(function() {
                $(".dropdown2 dd ul").toggle();
       });
			                 
       $(".dropdown dd ul li a").click(function() {
		var text = $(this).html();
              $(".dropdown dt a span").html(text);
              $(".dropdown dd ul").hide();
		window.location = $(this).children("span").text();
       });

	$(".dropdown2 dd ul li a").click(function() {
		var text = $(this).html();
              $(".dropdown2 dt a span").html(text);
              $(".dropdown2 dd ul").hide();
		window.location = $(this).children("span").text();
       });

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
              if (! $clicked.parents().hasClass("dropdown"))
              $(".dropdown dd ul").hide();
       });

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
              if (! $clicked.parents().hasClass("dropdown2"))
              $(".dropdown2 dd ul").hide();
       });

       $("#flagSwitcher").click(function() {
       	$(".dropdown img.flag").toggleClass("flagvisibility");
       });

	/* Set the selected language */
	if (currentLang) {
		currentLanguage  = currentLang;
		$("#languageSelector dd ul li").each(function() {
			if ($(this).children("a").children("span").html().toUpperCase().indexOf(currentLang.toUpperCase()) != -1) {
				var text = $(this).children("a").html();
				$("#languageSelector dt a span").html(text);
				$("#languageSelector dd ul").hide();
			}
		});
	}
	/* Set the selected site */
	if (currentSite) {
		$("#countrySelector dd ul li").each(function() {
			if ($(this).children("a").children("span").html().toUpperCase().indexOf(currentSite.toUpperCase()) != -1) {
				var text = $(this).children("a").html();
				$("#countrySelector dt a span").html(text);
				$("#countrySelector dd ul").hide();
			}
		});
	}
}

/* Set the myLuxair labels in the top header */
function setHeaderLoginText() {
	var cookieFirstName = $.cookie("lgl_reg_fn");
	var cookieLastName = $.cookie("lgl_reg_ln");
	var cookieLogin = $.cookie("lgl_reg_u");
	var cookieToken = $.cookie("lgl_reg_k");
	/* If there is one, we can login the customer automaticaly */
	if (cookieFirstName != null) {
		var welcomeMessage = $("#myLuxairLoginWelcome").html();
		var linkHREF = "/cms/luxair.php?page&p=" + currentLanguage + ",39709,729,,1,,";
		$("#myLuxairLogin").html("<a style='font-weight:bold' href='"+linkHREF+"'>" + welcomeMessage + " " + cookieFirstName + " " + cookieLastName+"</a>");	
		$("#header-profilBox").addClass("header-profilBoxLoggedIn");		
		var element=document.getElementById('myLuxairLogin');
		var padding = element.offsetWidth + 10;
		$("#languageBox").css( "padding-right", padding.toFixed(0)+"px");
		$("#loggedBox").hide();
		$("#unLoggedBox").show();	
	} else if (cookieLogin != null){
		var actionForm = "https://www.luxair.lu/profile/ProfileCheckCookieService.action";
		$("#unLoggedBox").append("<form id='cookieForm' name='cookieForm' action='" + actionForm +"' method='post'></form>");
		$("#cookieForm").append("<input type='hidden' id='lang' name='lang' value='" + currentLanguage +"'></input>");
		$("#cookieForm").submit();
	} else {
		$("#myLuxairLogin").html($("#myLuxairLoginConnexion").html());
		$("#header-profilBox").removeClass("header-profilBoxLoggedIn");
		var element=document.getElementById('myLuxairLogin');	
		var padding = element.offsetWidth + 10;	
		$("#languageBox").css( "padding-right", padding.toFixed(0) +"px");		
		$("#loggedBox").show();
		$("#unLoggedBox").hide();
	}
	var authError = $.getUrlVar('error');
	if(authError!="undefined" && authError=="true"){
		$("#smallLoginError").show();
		$(".content").show();
	}

	$('#smallLoginForminput').bind('keypress', function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code == 13) {//Enter keycode
			$('#smallLoginForminput').submit();
		}
	});

}

function doMyLuxairRefresh() {
	window.location="https://www.luxair.lu/cms/luxair.php?page&p=" + currentLanguage + ",45783,,,,,";
}

function arrangeSiteMap() {	
	var linksToDisable = new Array();
	linksToDisable[0]=728; //eServices link	
	linksToDisable[1]=738; //Voyageur Frequent link		
	linksToDisable[2]=715; //Avant le vol link		
	linksToDisable[3]=782; //Aeroport de Luxembourg link		
	linksToDisable[4]=724; //Apres le vol link		
	linksToDisable[5]=712; //Infos Pratiques link	
	linksToDisable[6]=676; //Accueil link
	
	var len=linksToDisable.length;
	for(var i=0; i<len; i++) {
		var value = linksToDisable[i];
		$("#map"+value).children("a").attr("href",'javascript:void(0);');
		$("#map"+value).children("a").attr('style','cursor: default');
	}
	
	var linksToRemove = new Array();
	linksToRemove[0]=677; //Eretail link
	linksToRemove[1]=841; //Web Check in third level link

	var len2=linksToRemove.length;
	for(var j=0; j<len2; j++) {
		var value2 = linksToRemove[j];
		$("#map"+value2).remove();	
	}
}


