/*
 * Application wide js functions, theme independent / theme aware
 */


/*
 * remove all content area elements and show loading Flash object
 * called when posting back results in long response time (eg holiday search)
 */

if(document.documentElement.className){
// if html has a class on no-js, replace it with js optimised styling.
 document.documentElement.className = document.documentElement.className.replace("no-js", "js"); 
}

$(document).ready(function () {

	// bind interstitial display function to links to pages with long response times.
	$('a.interstitial-link').bind('click', Global.interstitial);
	
	$('#opening img').bind('mouseenter mouseleave', function() {
		$('#opening img#timesOff').toggle();
		$('#opening img#timesOn').toggle();
	});	

});

Global = {

	interstitial : function() {

		if (Global.theme == "hnjww" || Global.theme == "tww"|| Global.theme == "jetsv") {
			$('#container-content').hide();
		}

		$('#breadcrumbs').hide();
		$('#three_col_container').hide();
		$('#menu_main_long').show();
		window.scrollTo(0,0);
		
		if (Global.theme == "hnjww" || Global.theme == "tww" || Global.theme == "jetsv") {
			$('#noSearchResultsContainer').hide();
		}

		if (Global.theme == "cit") {
			$('#container-content').hide();
			$('#noSearchResultsContainer').hide();
			$('#popBook').hide();
			$('#holiday_summary_div').show();
			getFact();			
		}

		if (Global.theme == "sov") {
			$('#container-content').hide();
			$('#noSearchResultsContainer').hide();
			//$('#twoColContainer').hide();
		}

		if (Global.theme == "meon") {
			$('#contentContainer').hide();
			$('#specialOfferContainer').hide();
		}

		if (Global.theme == "austrv") {
			$('#content').hide();
			$('offerOfTheWeek').hide();
			$('div.centralColumn').hide();
		}
		
		if (Global.theme == "tmood") {
			$('#page div.col').hide();
		}
		
		$('#waiting').show();
		
		if (Global.theme == "hnjww" || Global.theme == "jetsv" || Global.theme == "austrv" || Global.theme == "tww" || Global.theme == "cit" || Global.theme == "meon" || Global.theme == "sov") {
			var waitTimeout = 500;
			setTimeout("Global.loadAnimatedIcon();",waitTimeout);
			if (Global.theme == "austrv") {
				var $tabs = $('#searchPanelTabs').tabs();
				var selected = $tabs.tabs('option', 'selected');
				switch (selected){
					case 0: //Flight Only
					var waitSearchType = 'FO';
						break;
					case 1: //Accommodation and flights
						var waitSearchType = 'SC';
						break;
					case 2: //Accommodation Only
						var waitSearchType = 'AO'; 
					default:
						break;
				}
			} else {
				
				if( document.getElementById('search_type') != null){
					var waitSearchType = document.getElementById('search_type').value;	
				}	
			}
			
			if (waitSearchType != 'AO') {
				waitTimeout+=4000;
				setTimeout("Global.setWaitText('Checking flights...');",waitTimeout);
			}
			if (waitSearchType != 'FO') {
				waitTimeout+=4000;
				setTimeout("Global.setWaitText('Checking accommodation...');",waitTimeout);
			}
			if (waitSearchType == 'SC') {
				waitTimeout+=4000;
				setTimeout("Global.setWaitText('Checking transfers...');",waitTimeout);
			}
			waitTimeout+=4000;
			setTimeout("Global.setWaitText('Finalising results...');",waitTimeout);
		}

	},

	delayedInterstitial : function() {
		window.setTimeout(Global.interstitial, 2000);
	},
	
	loadAnimatedIcon : function() {
		$('#waitAnim').attr('src', $('#waitAnim').attr('src'));
	},
	
	setWaitText : function(strText) {
		$('#waitText').html(strText);
	}

}
