/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var mapPopupStatus = 0;

//loading popup with jQuery magic!
function loadMapPopup(){
	
	killloop();

	//loads popup only if it is disabled
	if(mapPopupStatus==0){
		$("#backgroundPopupIntMaps").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupIntMaps").fadeIn("slow");
		$("#mapOverlayContact").fadeIn("slow");
		$("#mapOverlayContact").css('display', 'block');
		$("#openMapOverlay").css('display', 'none');
		$("#rightContainer").css('display', 'none');
		$("#overlayLogoSmallContainer").css('display', 'none');
		$(".language-selection").css('zIndex','0');
		
		// Map Animation
		// idleloop("worldmap_big");
		mapPopupStatus= 1;	
	}	

    var logoMapFlag = document.getElementById("overlayLogoContainer");
    logoMapFlag.style.display = "none";

	// Load Destinations

	$('#showDestinations').css({
		'background-image':'url(/assets/images/global/common/map-button-black.png)',
		'background-repeat':'no-repeat',					
		'color':'#fff',
		'font-weight':'normal'
	});		
	
	var logoMapFlag = document.getElementById("overlayLogoContainer");
	logoMapFlag.style.display = "none";
	window.setTimeout('showdestinations("worldmap_big")', 1250);

}

//loading popup with jQuery magic!
function loadDarkPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		// $("h2").html("&#36234;&#21335;&#25903;&#25345;&#26143;&#31354;&#32852;&#30431;&#29983;&#29289;&#22280;&#32445;&#24102;&#35745;&#21010;");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disableDarkPopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	//disables popup only if it is enabled
	if(mapPopupStatus==1){		
		$("#backgroundPopupIntMaps").fadeOut("slow");
		$("#mapOverlayContact").fadeOut("slow");
		$("#openMapOverlay").css('display', 'block');
		$("#rightContainer").css('display', 'block');
		$(".language-selection").css('zIndex','89');
		mapPopupStatus = 0;
	}

}

//centering popup
function centerDarkPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	var mapOverlayHeight = $("#mapOverlayContact").height();
	var mapOverlayWidth = $("#mapOverlayContact").width();

	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});

	$("#mapOverlayContact").css({
		"position": "absolute",
		"top": "5px",
		"left": windowWidth/2-mapOverlayWidth/2
	});

	//only need force for IE6	
	$("#backgroundPopup").css({
		"height": windowHeight
	});

	$("#backgroundPopup-IntMaps").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){


	//LOADING POPUP

	//centering with css
	centerDarkPopup();
	//load popup
	loadDarkPopup();

	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerDarkPopup();
		//load popup
		loadDarkPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disableDarkPopup();
		if($("#openMapOverlay")!==null)
		{idleloop("worldmap_small");}
	});
	$("#mapOverlayContactClose").click(function(){
		disableDarkPopup();
		if($("#openMapOverlay")!==null)
		{idleloop("worldmap_small");}
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disableDarkPopup();
		if($("#openMapOverlay")!==null)
		{idleloop("worldmap_small");}
	});
	/* $("#backgroundPopupIntMaps").click(function(){
		disableDarkPopup();
		idleloop("worldmap_small");
	});

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disableDarkPopup();
			idleloop("worldmap_small");
		}
	}); */


	//Map Overlay Form Controls

	var imageURLon = "/assets/images/global/common/dropdown-small-black.png";
	var imageURLoff = "/assets/images/global/common/dropdown-small.png";
	var imageURLon_1 = "/assets/images/global/common/dropdown-small-year-black.png";
	var imageURLoff_1 = "/assets/images/global/common/dropdown-small-year.png";
	var imageBTNon = "/assets/images/global/common/map-button-black.png";
	var imageBTNoff = "/assets/images/global/common/map-button.png";

	$('#faredropdown').change(function() {
		
		reset();
		// alert("On");
		$('#fareDropDownSelect').css({
			'background-image':'url(' + imageURLon + ')',
			'background-repeat':'no-repeat',
			'color':'#fff',
			'font-weight':'normal',
			'padding-top':'2px'
		});
	});
	$('#membersdropdown').change(function() {			
		
		reset();
		// alert("On");
		$('#membersDropDownSelect').css({
			'background-image':'url(' + imageURLon + ')',
			'background-repeat':'no-repeat',					
			'color':'#fff',
			'font-weight':'normal',
			'padding-top':'2px'
		});
	});
	$('#zoomdropdown').change(function() {
		
		reset();
		// alert("On");
		$('#zoomDropDownSelect').css({
			'background-image':'url(' + imageURLon_1 + ')',
			'background-repeat':'no-repeat',					
			'color':'#fff',
			'font-weight':'normal',
			'padding-top':'2px'
		});
	});
	
	$('#showLounges').click(function(){
	
		reset();
		$('#showLounges').css({
			'background-image':'url(' + imageBTNon + ')',
			'background-repeat':'no-repeat',					
			'color':'#fff',
			'font-weight':'normal'
		});				
	});

	$('#showDestinations').click(function(){
	
		reset();
		$('#showDestinations').css({
			'background-image':'url(' + imageBTNon + ')',
			'background-repeat':'no-repeat',					
			'color':'#fff',
			'font-weight':'normal'
		});				
	});
	$('#showCities').click(function(){
	
		reset();
		$('#showCities').css({
			'background-image':'url(' + imageBTNon + ')',
			'background-repeat':'no-repeat',					
			'color':'#fff',
			'font-weight':'normal'
		});				
	});

	function reset(){
		$('#fareDropDownSelect').css({
			'background-image':'url(' + imageURLoff + ')',
			'background-repeat':'no-repeat',					
			'color':'#333',
			'font-weight':'normal'
		});
		$('#membersDropDownSelect').css({
			'background-image':'url(' + imageURLoff + ')',
			'background-repeat':'no-repeat',					
			'color':'#333',
			'font-weight':'normal'
		});
		$('#zoomDropDownSelect').css({
			'background-image':'url(' + imageURLoff_1 + ')',
			'background-repeat':'no-repeat',					
			'color':'#333',
			'font-weight':'normal'
		});
		$('#showLounges').css({
			'background-image':'url(' + imageBTNoff + ')',
			'background-repeat':'no-repeat',					
			'color':'#333',
			'font-weight':'normal'
		});
		$('#showDestinations').css({
			'background-image':'url(' + imageBTNoff + ')',
			'background-repeat':'no-repeat',					
			'color':'#333',
			'font-weight':'normal'
		});
		$('#showCities').css({
			'background-image':'url(' + imageBTNoff + ')',
			'background-repeat':'no-repeat',					
			'color':'#333',
			'font-weight':'normal'
		});				
		return true;
	}

		$('.toolTipMe').hover(function() {
			this.tip = "The <a href='http://www.staralliance.com/en/benefits/lounges/lounge-finder/' target='_blank' class='toolTipStyle'>Star Alliance Lounge Finder</a>  includes all lounges operated by Star Alliance member carriers and all Star Alliance own lounges (CDG, LAX, LHR, NGO).";
			$(this).append(
				'<div class="toolTipWrapper">'
					+'<div class="toolTipTop"></div>'
					+'<div class="toolTipMid">'
						+this.tip
					+'</div>'
					+'<div class="toolTipBtm"></div>'
				+'</div>'
			);
			this.title = "";
			this.width = $(this).width();
			$(this).find('.toolTipWrapper').css({left:this.width-9})
			$('.toolTipWrapper').fadeIn(300);
		},
		function() {
		$('.toolTipWrapper').fadeOut(100);
			$(this).children().remove();
			$(this).append('<a href="javascript: void(0);" class="toolTipMe"><img src="/assets/images/global/common/helpButton.gif" width="24" height="20" border="0" class="helpButton" /></a>');
		});


});
