var langCode = "fr";

function buildMenuBar() {
	//setASRFunction();

	/* We set the plane icon on the first menu item */
	$("#item532").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");
		if ($(this).children(".subNavigation").children("li").length > 0 && !isPlane) {
			$(this).children("a").attr("href",'javascript:void(0);');
		}
		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");	
		} else {
			$(this).children(".subNavigation").append('<li id="subMenuBottom">&nbsp;</li>');
		}
	});

	/* Drop all the empty 3rd level navigation */
	$("#nav li ul li").each(function(){
		if ($(this).children(".subSubNavigation").children("li").length == 0) {
			$(this).children(".subSubNavigation").remove();
		} else {	
			/* 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>');		}
	});

	$('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");

			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');
				}
			}	
		});
	
	});

}

/* Set ASR popup on the ASR link */
function setASRFunction() {
	$("#quick_seat").children("a").attr("href","javascript:void(0);");
	$("#quick_seat").children("a").click(function(event){
		displayAsrPopup();	});
	$('.date-pick').datePicker({clickInput:true});
}

/* Redirect to the right ASR Url depending on the departure flight date */
function selectASRDate() {
	var dateStr = $("#date1").val();
	dateStr += " ";
	MD_i1=dateStr.indexOf(' ');
	MD_Date=dateStr.substring(0,MD_i1);
	MD_i2=MD_Date.indexOf('/');
	MD_i3=MD_Date.indexOf('/',MD_i2+1);
	MD_D=MD_Date.substring(0,MD_i2);
	MD_M=MD_Date.substring(MD_i2+1,MD_i3);
	MD_Y=MD_Date.substring(MD_i3+1);
	
	MD_M=MD_M-1;

	DObj=new Date(MD_Y, MD_M, MD_D);

	var winterDate = new Date(2010,10,9);
	if (DObj < winterDate) {
		window.location = "http://asr.luxair.lu/servlet/jsp/index.jsp?lang=" + langCode ;
	} else {
		window.location = "http://www.luxairtours.lu/cms/luxair.php?p="+langCode +",42125,998,,1,,";
	}
	
}

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

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

function setHeaderBehaviour(currentLang) {
langCode = currentLang;	
	/* Set an hover behaviour in order to display the login / language change box */
	$("#header-top-interaction").hover(function(event){
		$(this).addClass('active');
		var content = $('.content', this);
		if(!content.is(':animated')) content.slideDown('slow');
	}, function(){
		$(this).removeClass('active');
		var content = $('.content', this);
		if(!content.is(':animated')) content.slideUp('slow');			
	}); 

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

	/* Configure the home link on the header logo */
	$("#headerLink").click(function() {
       	window.location = "http://www.luxairtours.lu/cms/luxair.php?page&p=" + currentLang + ",17756,,,,,";
       });	
                      
       $(".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();
       });

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


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

	/* Set the selected language */
	$("#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 myLuxair labels in the top header */
function setHeaderLoginText() {
}

function arrangeSiteMap() {	
	var linksToDisable = new Array();
	linksToDisable[0]=538; //Nos Destination link
	linksToDisable[1]=543; //Demandes Speciales link	
	linksToDisable[2]=599; //Autorise ou interdit link	
	linksToDisable[3]=537; //Info pratique link	
	linksToDisable[4]=561; //Aeroport de Luxembourg link	
	linksToDisable[5]=552; //Nos services compris link	
	linksToDisable[6]=594; //Vacances sereines link	
	linksToDisable[7]=534; //Nos Avions link	
	linksToDisable[8]=535; //Nos Brochures & Produits link	
	linksToDisable[9]=533; //Decouvrez LuxairTours link	
	linksToDisable[10]=532; //Reservez vos Vacances ! link	
	linksToRemove[11]=1077; //Vatry Airport
	
	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]=672; //Eretail link
	linksToRemove[1]=1002; //ASR link
	linksToRemove[2]=998; //ASR link

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

