function getScriptPath( script ) {
	return window.mph.BASE_URL + "/js/" + script;
}

function getLibScriptPath ( script ) {
	return window.mph.BASE_URL + "/js/common/lib/" + script;
}

function getCompressedScriptPath( script ) {
	return window.mph.BASE_URL + "/c/" + script;
}

function setCommonsQueue() {	
	
	var scripts = new Array(), userLanguage = window.mph.$CONFIG.locale;
	
	if ( window.mph.$CONFIG.useCompressed == false ) {
	
		scripts.push( getLibScriptPath("40.jquery.ui.18.js"));
		scripts.push( getLibScriptPath("jquery.i18n.js"));
		scripts.push( getLibScriptPath("03.jquery.metadata.js"));
		scripts.push( getLibScriptPath("84.jquery.ajaxQueue.js"));
		scripts.push( getLibScriptPath("88.jquery.masked.js"));
		scripts.push( getLibScriptPath("89.bsn.autosuggest.js"));
		scripts.push( getLibScriptPath("90.jquery.watermarkinput.js"));
		scripts.push( getLibScriptPath("jquery.blockUI.js"));
		scripts.push( getLibScriptPath("jquery.rsv.js"));
		scripts.push( getLibScriptPath("shadowbox." + userLanguage + ".js"));
		
		$LAB.queueScript(scripts);
		$LAB.queueWait();
		
		scripts = new Array();
		
		scripts.push( getScriptPath("mph." + userLanguage + ".js"));
		scripts.push( getScriptPath("mph.json.js"));
		scripts.push( getScriptPath("mph.util.js"));
		scripts.push( getScriptPath("nemo.common.js"));
		scripts.push( getScriptPath("mph.common.js"));
		scripts.push( getScriptPath("mph.destinationsSearch.js"));
		
	}
	else {
		scripts.push( getCompressedScriptPath("00-common-" + userLanguage + ".js") );
	}
	
	$LAB.queueScript(scripts);
}

function getStep1Scripts() {

	var pageScripts = new Array();

	if ( window.mph.$CONFIG.useCompressed == false ) {
		pageScripts.push( getLibScriptPath("85.jquery.scrollable.js"));
		pageScripts.push( getLibScriptPath("86.jquery.bgiframe.js"));
		pageScripts.push( getLibScriptPath("87.jquery.scrollpanel.js"));
		pageScripts.push( getLibScriptPath("96.jquery.imageslide.js"));
		pageScripts.push( getLibScriptPath("swfobject/swfobject.js"));
		pageScripts.push( getScriptPath("mph.search-form.js"));
	}
	else {
		pageScripts.push( getCompressedScriptPath("01-home.js") );
	}

	return pageScripts;
}

function getStep2Scripts() {

	var
		pageScripts = new Array();

	if ( window.mph.$CONFIG.useCompressed == false ) {

		var libScripts =
			[
	          "98.jquery.pagination.js",	          
	          "91.jquery.scrollTo.js",
	          "83.jquery.tools.js",
	          "82.jquery.jmap.js"
	        ];

		var scripts =
			[
			 	"mph.comparator.js",
			 	"mph.budget.js",
			 	"mph.search-form.js"
		    ];

		for(var i = 0; i < libScripts.length; i++) {
			pageScripts.push( getLibScriptPath(libScripts[i]));
		}

		for(i = 0; i < scripts.length; i++ ) {
			pageScripts.push( getScriptPath(scripts[i]));
		}
	}
	else {
		pageScripts.push( getCompressedScriptPath("02-searchResults.js"))
	}

	return pageScripts;
}

function getLiteStep2Scripts() {

	var pageScripts = new Array();

	if ( window.mph.$CONFIG.useCompressed == false ) {		
		pageScripts.push( getLibScriptPath("98.jquery.pagination.js"));
		pageScripts.push( getScriptPath("mph.search-form.js"));
	}
	else {
		pageScripts.push( getCompressedScriptPath("02-searchResults-lite.js"));
	}

	return pageScripts;
}

function getStep3Scripts() {
	return new Array();
}

function getMyBookingsScripts() {

	var pageScripts = new Array();

	if ( window.mph.$CONFIG.useCompressed == false ) {
		pageScripts.push(getLibScriptPath("98.jquery.pagination.js"));
		pageScripts.push(getLibScriptPath("table.sorter.js"));
	}

	return pageScripts;
}

function getBookingDetailsScripts() {

	var pageScripts = new Array();

	if ( window.mph.$CONFIG.useCompressed == false ) {
		pageScripts.push( getScriptPath("mph.booking-common.js"));
	}
	else {
		pageScripts.push( getCompressedScriptPath("14-booking-details.js"));
	}

	return pageScripts;
}

function getDisplayMapScripts() {

	var pageScripts = new Array();

	return pageScripts;
}

function getComparatorScripts() {
	return new Array();
}

function getWebTerminalScripts() {
	return new Array();
}

function loadScripts(pageScripts, callback) {
	
	var timeout = 75;	
	
	if(jQuery.browser.msie) {
		timeout = 500;
	}
	
	setTimeout(function(){
		scriptsLoaderUsingLab(pageScripts, callback)
	}, timeout);
};

function scriptsLoaderUsingLab(pageScripts,callback) {
	
	$LAB.setGlobalDefaults({
		AlwaysPreserveOrder : true
	});
	
	setCommonsQueue();	
	
	if(pageScripts.length > 0) {
		$LAB.queueWait();
		$LAB.queueScript(pageScripts)
	}
	
	$LAB.runQueue().wait( function() {
			
		var timeout = 0;	
		
		if(jQuery.browser.msie) {
			timeout = 250;
		}			
		
		setTimeout(callback, timeout);
		
		var event = jQuery.Event("pageLoaded.priceSurfer");
		jQuery(document).trigger(event);
	});
}
