var currentLanguage = "EN";

function buildMenuBar() {
	
	/* Drop the link that should not be displayed to the customer */
	//$("#item464").attr("href",'javascript:void(0);');	/* The Experience */
	//$("#item464").attr('style','cursor: default');
	//$("#item465").attr("href",'javascript:void(0);');	/* Practical Info */
	//$("#item470").attr("href",'javascript:void(0);');	/* Frequent Flyer */
	//$("#item468").attr("href",'javascript:void(0);');	/* E-Services */

	/* We set the plane icon on the first menu item */
	$("#item796").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 and myluxair 3rd level */
	//$('#subItem610').remove();	
	//$('#subItem483').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).mouseover(function(){

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

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

		});
	
	});
}

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

function setPlaneMenuItemOff() {
	$("#item796").children(".menu_left_on").attr("class",'menu_left');	
	$("#item796").children(".menu_middle_on").attr("class",'menu_middle');	
	$("#item796").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.lu/cms/luxair.php?page&p=" + currentLang + ",34843,,,,,";
       });	


	/* 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 + ",39781,825,,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 + ",39781,,,,,";
}

function arrangeSiteMap() {	
	var linksToDisable = new Array();
	linksToDisable[0]=824; //eServices link	
	linksToDisable[1]=803; //Frequent Flyer link		
	linksToDisable[2]=798; //After traveling link		
	linksToDisable[3]=799; //Prepare your trip link		
	linksToDisable[4]=801; //Luxembourg Airport link		
	linksToDisable[5]=797; //Practical Info link	
	linksToDisable[6]=902; //In The Air link	
	linksToDisable[7]=903; //Our Fleet link
	linksToDisable[8]=901; //The Experience link
	linksToDisable[9]=796; //Home 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]=829; //Eretail link

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