<!-- Last published on : 15-Jun-11 13:59:53 -->
/**
* KLM footer siteloader
*/
function loadOtherKLMSites(sel) {
	window.open(sel.value.split('|')[0]);
}

// -------------------------------------------------------
// Client-side dynamic navigation functions
// -------------------------------------------------------
function initNavRoles() {
	if (!travelshopRolesAreInitialized) {
		$.ajax({
			cache: true,
			async: false,
			type: "GET",
			url: rolesDataUrl,
			dataType: "html",
			success: function initTravelshopRoles(data) {
				if (/bB2EAdministrator\s=\strue;/i.test(data)) roleAdministrator = "[B2EAdministrator]";
				if (/bB2EDutyTravelArranger\s=\strue;/i.test(data)) roleDutyTravelArranger = "[B2EDutyTravelArranger]";
				if (/bB2ELeisureBooker\s=\strue;/i.test(data)) roleLeisureBooker = "[B2ELeisureBooker]";
				if (/bB2ELeisureTravelArranger\s=\strue;/i.test(data)) roleLeisureTravelArranger = "[B2ELeisureTravelArranger]";
				if (/bB2E_BLUE_SKY_GROUP\s=\strue;/i.test(data)) roleRetiree = "[B2E_BLUE_SKY_GROUP]";

				travelshopRolesAreInitialized = true;
			}
		});
	}
}

function initNavXml() {
	if (navXmlObj == null) {
		$.ajax({
			cache: true,
			async: false,
			type: "GET",
			url: navXmlUrl,
			dataType: "xml",
			success: function(data) {
				navXmlObj = data;
			}
		});
	}
}

function getNavXslObj(xslUrl) {
	var xslObj = null;

	if (xslUrl != '') {
		$.ajax({
			cache: true,
			async: false,
			type: "GET",
			url: xslUrl,
			dataType: "xml",
			success: function(data) {
				xslObj = data;
			}
		});
	}

	return xslObj;
}

function showNav(navType, contextId, container) {
	if($(container).length)
	{
		var xslUrl = "";
		var topNavUri = "";
		initNavRoles();
		initNavXml();

		if (travelshopRolesAreInitialized && navXmlObj != null)
		{
			switch (navType) {
				case "leftnav":
					xslUrl = leftNavXsltUrl;
					break;
				case "topnav":
					xslUrl = topNavXsltUrl;
					break;
				case "breadcrumb":
					xslUrl = breadcrumbXsltUrl;
					break;
				case "sitemap":
					xslUrl = sitemapXsltUrl;
					break;
				case "navpage":
					xslUrl = navpageXsltUrl;
					topNavUri = mainStructureGroupID; // this var is declared in local.js
					break;
			}

			if (xslUrl != "") {
				var navXslObj = getNavXslObj(xslUrl);

				if (navXslObj != null) {
					$(container).transform({
						cache: true,
						async: false,
						xmlobj: navXmlObj,
						xslobj: navXslObj,
						xslParams: {
							ContextItemUri: contextId,
							MainNavSgUri: topNavUri,
							HomeLabel: homeLabel,
							BackToLabel: backToLabel,
							AdministratorRole: roleAdministrator,
							DutyTravelArrangerRole: roleDutyTravelArranger,
							LeisureBookerRole: roleLeisureBooker,
							LeisureTravelArrangerRole: roleLeisureTravelArranger,
							RetireeRole: roleRetiree
						}
					});
				}
			}
		}
	}
}

// -------------------------------------------------------
// Language switch
// -------------------------------------------------------
function switchLanguage(toLanguageCode) {
	var publicationUrlTrail = publicationUrl.slice(-2); // for example "nl" and "en"

	if(publicationUrlTrail == languageCode)
	{
		var newPubUrl = publicationUrl.slice(0, publicationUrl.length - 2) + toLanguageCode
		var redirectUrl = document.location.toString().replace(publicationUrl, newPubUrl);
		document.location = redirectUrl;
		
		// Redirects to homepage of the selected language
		// document.location = newPubUrl;
	}
}

// -------------------------------------------------------
// Carrousel slider on the home page
// -------------------------------------------------------
function KlmSlider() {
	/* initialize */
	var htmlIdentifier = '#klm_slider';
	var xmlSource = 'carrousel_data.xml';	
	var continuous = true;
	var timer = 6000;
	var hasFading = true;
	var fading = 2000;
	var continuousOption;
	var timerOption;
	var hasFadingOption;
	var fadingOption;

	/* initialise slider variables */
	var items = 0;
	var content = new Array();
	var control = '';
	var count = 1;

	/* get contents from xml */
	$.ajax({
		cache: true,
		async: false,
		type: "GET",
		url: xmlSource,
		dataType: "xml",
		success: function(data) {		  
			/* getting defaults values*/
			var $xmlRoot = $(data).find('navigation');
			$xmlRoot.find('config').each(function() {
				continuousOption = $(this).find('continuous').text();
				timerOption = $(this).find('rotation_speed').text();
				hasFadingOption = $(this).find('hasFading').text();
				fadingOption = $(this).find('fading').text();
			});

			$xmlRoot.find('item').each(function() {
				items++;
				var $slide = $(this); 
				/* create slide HTML */
		
				var navigation_title = $(this).find('navigation_title').text();
				var image = $(this).find('image').text();
				var title_colour = $(this).find('title_colour').text();
				var linktext = $(this).find('linktext').text();
				var textlink = $(this).find('link').text();
				var controls;
				if(title_colour==='0xFFFFFF')	controls= '<div class="splash-controls light" >&nbsp;</div>';
				else controls= '<div class="splash-controls">&nbsp;</div>';

				var slideHtml = '<img src="' + image + '" width="768" height="248" class="slide-image" />' + '<div class="slide-content">'+'<h2 class="title-text sIFR-replaced"><embed width="405" height="60" src="' + noalightSwfPath + '" quality="best" flashvars="txt='+navigation_title+'&amp;offsetTop=-5&amp;textcolor=#003145&amp;w=405&amp;h=60&amp;forceSingleLine=false&amp;preventWrap=false" wmode="opaque" bgcolor="#FFFFFF" sifr="true" type="application/x-shockwave-flash" class="sIFR-flash" style="width: 405px; height: 60px;">'+'<span class="sIFR-alternate">'+navigation_title+'</span></h2><a href="'+textlink+'">' + linktext + ' ></a></div>'+controls;

				/* add slide HTML to array*/
				content[items] = slideHtml;
				/* create controls */
				if(items==1) control = control + '<a href="#" class="selected" rel="'+items+'">'+items+'</a>';
				else control = control + '<a href="#" rel="'+items+'">'+items+'</a>';
			});
			
			$(htmlIdentifier+' .splash-content').html(content[count]);
		
			/* add controls	*/
			$(htmlIdentifier+' .splash-controls').html(control);
		}
	});

	/* setting defaults */
	if(continuousOption != 'true') continuous = false;
	if(timerOption != null) timer = parseInt(timerOption);
	if(hasFadingOption != 'true') hasFading = false;
	if(fadingOption != null) fading = parseInt(fadingOption);

	/* finished getting data and initialising the slider */
	
	/* control is clicked */
	$(htmlIdentifier+' .splash-controls a').live('click',function () {
		var slideID = $(this).attr('rel');
		count = Slide2Next(count,content,items,slideID);
		/* reset sliding interval */
		if (continuous == true)	{
			clearInterval(slideInterval);
			slideInterval = setInterval(function() {count = Slide2Next(count,content,items)}, timer );
		}
		return false;
	});
	
	/* set sliding interval */
	if (continuous == true)	{
		var slideInterval = setInterval(function() {count = Slide2Next(count,content,items)}, timer );
	}
	/* settings Slide2Next settings */
	if(hasFading==true)	{
		var invisible = 0;
		var opaque = 1;
	}
	else {
		var invisible = 1;
		var opaque = 1;
		fading = 0;
	}

	function Slide2Next(count,content,items,slideID) {	
		if(items > 0) {
			if(slideID>0) count = slideID;
			else if(count<items) count++;
			else count = 1; /* reached the last slide, get back to first */
			$(htmlIdentifier+' .splash-content').animate({opacity:invisible},fading, function() {
				/* animating */
				/* faded out, changing content */
				$(htmlIdentifier+ ' .splash-content').html(content[count]);
				/* add controls */
				$(htmlIdentifier+' .splash-controls').html(control);				
				/* change style of controls */
				$(htmlIdentifier+' .splash-controls a.selected').removeAttr("class");
				$(htmlIdentifier+' .splash-controls a[rel='+count+']').attr("class","selected");
				/* fading back in */
				$(htmlIdentifier+' .slide-text').css({ opacity: .0 }); 
				$(htmlIdentifier+' .splash-content').animate({opacity:opaque},fading)
				$(htmlIdentifier+' .slide-text').animate( {opacity:opaque, duration: 1500},fading);  
			});
		}
		
		return count;
	}
}

