	$(window).bind('load', function(){
		var preload = [
					   '/images/main/image_hp_01.jpg', 
					   '/images/main/image_hp_02.jpg', 
					   '/images/main/image_hp_03.jpg', 
					   '/images/main/image_hp_04.jpg', 
					   '/images/lifecycle/pretravel/image_hotspot_pretravel.jpg',
					   '/images/lifecycle/atairport/image_intro_hotspot_at_airport.jpg',
					   '/images/lifecycle/atairport/image_hotspot_airport_gate.jpg',
					   '/images/lifecycle/atairport/image_hotspot_airport_checkin.jpg',
					   '/images/lifecycle/inlounge/image_hotspot_inlounge.jpg',
					   '/images/lifecycle/onboard/image_hotspot_onboard.jpg',
					   '/images/lifecycle/posttravel/image_hotspot_posttravel.jpg'
					   ];
		$(document.createElement('img')).bind('load', function(){
		 if(preload[0]) this.src = preload.shift();
		}).trigger('load');
	});
	
	function slidey(){
		$('#homeSlider').easySlider({
			controlsShow:		true,
			speed: 			750,
			auto:			true,
			pause:			9000,
			continuous:		false, 
			allControls:	true,
			controlsPlayPause:	true,
			controlId: 		'homeSliderControls'

		});
	}
	
	//On load page, init the timer which check if the there are main slider nav changes each 300 ms
	$().ready(function(){
		setInterval('checkAnchor()', 300);
	});
	
	function checkAnchor(){
		if ($('#homeSliderControls li#homeSliderControls1.active').length){
			$('#homeSliderControls li#homeSliderControls4').css({
				'display': 'block'
			});
			$('#homeSliderControls li#homeSliderControls1').css({
				'display': 'none'
			});
		}
		else if ($('#homeSliderControls li#homeSliderControls4.active').length){
			$('#homeSliderControls li#homeSliderControls1').css({
				'display': 'block'
			});
			$('#homeSliderControls li#homeSliderControls4').css({
				'display': 'none'
			});
		}
	}
	
	
	function browserSize() {
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var mainHeight = $('#main').height();

		$('#wrapper').css({
			//'width': windowWidth,
			//'height': mainHeight
		});
	}
	
	function controlPosition(){
		var pos = $('#lifecycleNav ul li:last-child a').position();
		
		$('ul#homeSliderControls').css({
			'left': pos.left - 70
		});
	}

	function stripPx(str){
		str = str.replace('px', ' ');
		return str;
	}
	
	function initLifecycle(){
		
		$('.atGate').click(function () {
			$("#ajaxContent").load("/lifecycle/atgate.html #externalContent",'',function(){initLifecycle();});
		});
		
		$('.atCheckin').click(function () {
			$("#ajaxContent").load("/lifecycle/atcheckin.html #externalContent",'',function(){initLifecycle();});
		});
		
		
		
		function showLifecycleSlider() {
			$('.lifecycleSliderContainer, .lifecycleSlider').animate({'height': '595px'}, 200);
			$('.hotSpotIcons').hide();
			$('.hotSpotArrows').show();
			$('.hotSpotDisplay').hide();
						
		}
		
		//slide in lifecycle slider and run slider
		
		$().ready(function(){
			$('.lifecycleSlider').easySlider({
				continuous: true,
				controlsShow:		true,				
				speed: 			1000,
				pause:			10000,
				controlId: 		'lifecycleControls',
				controlsPlayPause: true,
				prevId: 'lifecycleSlider_prev',
				nextId: 'lifecycleSlider_next',
				prevText:'<img src="/images/lifecycle/lifecycle_overlay_arrow_left.png" alt="Scroll Left" width="27" height="334" />',
				nextText:'<img src="/images/lifecycle/lifecycle_overlay_arrow_right.png" alt="Scroll Right" width="27" height="334" />',
				allControls:		true
			});
			
			
		});
		
		//Append slider numbers to a unique container
		$('#lifecycleControls').appendTo('.hotSpotIcons');
		
		$('.hsOne').next('div').appendTo('#lifecycleControls1');
		$('.hsTwo').next('div').appendTo('#lifecycleControls2');
		$('.hsThree').next('div').appendTo('#lifecycleControls3');
		$('.hsFour').next('div').appendTo('#lifecycleControls4');
		$('.hsFive').next('div').appendTo('#lifecycleControls5');
		$('.hsSix').next('div').appendTo('#lifecycleControls6');
		$('.hsSeven').next('div').appendTo('#lifecycleControls7');
		$('.hsEight').next('div').appendTo('#lifecycleControls8');
		$('.hsNine').next('div').appendTo('#lifecycleControls9');
		$('.hsTen').next('div').appendTo('#lifecycleControls10');
	
		//Append slider nav arrows to a unique container
		$('li#lifecycleSlider_prev, li#lifecycleSlider_next').appendTo('.hotSpotArrows ul');

		$('.numeric').click(function () {
			showLifecycleSlider();						  
		});
		
		$('.lifecycleSlider .close').click(function () {
			$('.lifecycleSliderContainer, .lifecycleSlider').animate({'height': '0px'}, 200);
			$('.hotSpotIcons').show();
			$('.hotSpotArrows').hide();

		});
		
		//Tooltips
		$('.numeric a').mouseover(function() {
			var hotSpotPos = $(this).position();
	
			$(this).next('div').show().css({'top': hotSpotPos.top, 'left': hotSpotPos.left + 32});
		 });
		
		$('.numeric a').mouseout(function() {
			var hotSpotPos = $(this).position();
	
			$(this).next('div').hide().css({'top': hotSpotPos.top, 'left': hotSpotPos.left + 32});
		 });
		autoOpenHotSpot = null
		if ($('.asdf').length == 0) 
		{
			autoOpenHotSpot = setTimeout("setLifeCycleTimers()", 17000);
		}
		//autoOpenHotSpot = setTimeout("setLifeCycleTimers()", 5000);

		//Clear timeout if a hotspot is clicked and start slider interval
		$('.numeric a').click(function() {
			clearTimeout(autoOpenHotSpot);
		 });
		

		
		//Stop slider interval if next/prev is clicked.
		$('#lifecycleSlider_next a').click(function() {			
			$('#lifecycleControls_PlayPause a.pause').click();
		 });
		$('#lifecycleSlider_prev a').click(function() {
			$('#lifecycleControls_PlayPause a.pause').click();			
		 });
		
		
		//find dynamic height of the hot spot instruction box depending on content and set the open hot spot instruction box height equal to that
		var instructionHeight = $('.hotSpotInstructions').height();
		$('.openInstructions').css({
			'height': instructionHeight
		});
		
		hideInstructions = null
		showInstructionsTab = null
		
		if ($('.asdf').length == 0) 
		{
			//close hot spot instructions
			hideInstructions = setTimeout("$('.hotSpotInstructions').hide()", 5000);
			showInstructionsTab = setTimeout("$('.openInstructions').show()", 5000);
		}
		
		//Clear timeout if a new nav item is clicked
		$('#lifecycleNav ul li').find('img').each(function(){
			$(this).click(function() {		
				clearTimeout(autoOpenHotSpot);
				clearTimeout(hideInstructions);
				clearTimeout(showInstructionsTab);
			 });		
		});
		
		$('.collapseLifecycle').find('img').each(function(){
			$(this).click(function() {		
				clearTimeout(autoOpenHotSpot);
				clearTimeout(hideInstructions);
				clearTimeout(showInstructionsTab);
			 });		
		});
		
		$('.atairportSlider').find('a').each(function(){
			$(this).click(function() {
				clearTimeout(autoOpenHotSpot);
				clearTimeout(hideInstructions);
				clearTimeout(showInstructionsTab);
		 	});
		});
		
		$('a.launchExample').each(function(){
			$(this).click(function() {
				clearTimeout(autoOpenHotSpot);
				clearTimeout(hideInstructions);
				clearTimeout(showInstructionsTab);
		 	});
		});
		
		$('.hotSpotInstructions .close').click(function () {
			  $('.hotSpotInstructions').toggle('slide', { direction: 'left' }, 200);
			  $('.openInstructions').toggle('slide', { direction: 'right' }, 200);
		});
		
		//open hot spot instructions
		$('.openInstructions').click(function () {
			  $(this).toggle('slide', { direction: 'right' }, 200);
			  $('.hotSpotInstructions').toggle('slide', { direction: 'left' }, 200);
		});
		
			$('.lifecycleHandle').unbind('mouseenter', lifecycleHandler);
			
			
	}
	
	function setLifeCycleTimers(){

		$('#lifecycleControls1 a').click(); 
		autoScroll = setTimeout("$('#lifecycleControls_PlayPause a.play').click()", 3000);
	}
	
	function lifecycleHandler() {
		//if (stripPx($('#lifecycle').css('top')) < -395)
		if ($('.lifecycleTriggerClose').length)
		{
			hideLifecycle();
		}else{
			exposeLifecycle();
		}
	}
	
	
	function exposeLifecycle() {
			
		var lifecycleContentHeight = $('#lifecycleContent ul.samplesInfo').css('height');
		var lifecycle = $('#lifecycle').css('top');

			$('#lifecycleContent').animate({'height': lifecycleContentHeight},'slow');
			$('#lifecycle').animate({'top': stripPx(lifecycle) - stripPx(lifecycleContentHeight)},'slow');
			
			$('#lifecycleNav ul li a').removeClass('lifecycleHandle').addClass('lifecycleFullExpand');
			$('#lifecycleContent ul li a').removeClass('lifecycleHandle').addClass('lifecycleFullExpand');
			
			$('#lifecycleTrigger').addClass('lifecycleTriggerClose').addClass('asdf');
			
			$('.lifecycleFullExpand').unbind('click', lifecycleHandler);
			$('.lifecycleFullExpand').bind('click', fullExpandHandler,false);
			
			$('.collapseLifecycle').show();
			
				if ($('.asdf').length){
					//alert('advertising');
					$('li').removeClass('navHighlight');
				}
			
	}
	
	
	function hideLifecycle() {
			$('.lifecycleFullExpand').unbind('click', fullExpandHandler);
			
			$('li').removeClass('navHighlight');

			$('#lifecycleContent').animate({'height': '0px'},'slow');
			
				if ($('.interior.advertising').length){
					//alert('advertising');
					$('#lifecycle').animate({'top': '-5px'},'slow');
				}
				else if ($('.interior').length){
					//alert('interior');
					$('#lifecycle').animate({'top': '0px'},'slow');
				}
				else {
					//alert('not interior');
					$('#lifecycle').animate({'top': '-395px'},'slow');
				}
			
			$('#content').animate({"top": '0px'},'slow');
			
			$('#lifecycleTrigger').removeClass('lifecycleTriggerClose');
			$('#lifecycleTrigger').removeClass('lifecycleBg');
			
			$('.collapseLifecycle').hide();

			$('.lifecycleFullExpand').unbind('click', fullExpandHandler);
			$('.lifecycleFullExpand').bind('click', lifecycleHandler,false);
			$('#lifecycleNav ul li a').removeClass('lifecycleFullExpand').addClass('lifecycleHandler');
			$('#lifecycleContent ul li a').removeClass('lifecycleFullExpand').addClass('lifecycleHandler');
		
			$('#lifecycleNav').removeClass('lifecycleNavBg');
	}
	
	
	
	function fullExpandHandler() {
		var headerHeight = $('#header').height();
		var mainHeight = $('#main').height();
		var contentHeight = $('#content').height();
		var lifecycleContentHeight = $('#lifecycleContent ul.samplesInfo').height();
		
		$('#lifecycle').animate({'top': -(mainHeight - headerHeight)},'slow');
			
		$('#lifecycleContent').animate({'height': contentHeight},'slow');
			
		$('#content').show(function () {$(this).css({'top': - lifecycleContentHeight})});
		
		
		$('#lifecycleTrigger').addClass('lifecycleBg').removeClass('asdf');
		
		
		$('.collapseLifecycle').show();
		
		$('html, body').animate({scrollTop:0}, 'slow');
		
		$('#lifecycleNav').addClass('lifecycleNavBg');
	}





$(document).ready(function(){	
						   
	var hash = window.location.hash.substr(1);
	var href = $('.launchLifecycle ul li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content';
			$('#content').load(toLoad)
		}											
	});

	$('.launchLifecycle ul li a').click(function(){
												 
		$('li').removeClass('navHighlight');
				$(this).parent().addClass('navHighlight');

		var toLoad = $(this).attr('href')+' #ajaxContent';
		$('#content').load(toLoad,'',function(){initLifecycle();});
		
		return false;
		
	});	
	
	//find viewport and hide scrollbars
	browserSize();
	
	//find viewport and hide scrollbars after winder resize
	$(window).resize(function() {
		browserSize();
	});
			
	//run main slider
	slidey();
	
	//find last item in main nav and position the main slider controls under it
	controlPosition();
		
	//remove border on the last item in the footer
	$('ul li:last-child').css({
		'border': 'none'
	});
	
	//activate gallery nav items
	if ($('.galleriesSliderContainer').length){
		var pageClass = $('.galleriesSliderContainer').attr('class').split(' ');
		$('.internalNav').find('li a.' + pageClass[1]).addClass('active');
	}
	
	
	//Hover state on Lifecycle Nav
	$('.pretravel').hover(function () {
									
			$('.pretravel').each(function() {
				$(this).css({
				'background-image': 'url(/images/background/background_lifecycle_hover.png)'
				});
			});
		
	  },
	  function () {
			$('.pretravel').each(function() {
				$(this).css({
				'background-image': 'none'
				});
			});
	  }
	);		
	
	$('.atairport').hover(function () {
									
			$('.atairport').each(function() {
				$(this).css({
				'background-image': 'url(/images/background/background_lifecycle_hover.png)'
				});
			});
		
	  },
	  function () {
			$('.atairport').each(function() {
				$(this).css({
				'background-image': 'none'
				});
			});
	  }
	);		
	
	$('.inlounge').hover(function () {
									
			$('.inlounge').each(function() {
				$(this).css({
				'background-image': 'url(/images/background/background_lifecycle_hover.png)'
				});
			});
		
	  },
	  function () {
			$('.inlounge').each(function() {
				$(this).css({
				'background-image': 'none'
				});
			});
	  }
	);		
	
	$('.onboard').hover(function () {
									
			$('.onboard').each(function() {
				$(this).css({
				'background-image': 'url(/images/background/background_lifecycle_hover.png)'
				});
			});
		
	  },
	  function () {
			$('.onboard').each(function() {
				$(this).css({
				'background-image': 'none'
				});
			});
	  }
	);		
	
	$('.posttravel').hover(function () {
									
			$('.posttravel').each(function() {
				$(this).css({
				'background-image': 'url(/images/background/background_lifecycle_hover.png)'
				});
			});
		
	  },
	  function () {
			$('.posttravel').each(function() {
				$(this).css({
				'background-image': 'none'
				});
			});
	  }
	);	
	
	//Launch Lifecycle from Advertising Solutions page
	$('a.launchExample').click(function () {
		var exampleId = $(this).attr('id');

		lifecycleHandler();
		$('ul.lifecycleIcons li[class='+exampleId+'] a').click().parent().addClass('navHighlight');
	});
	
	//Launch Lifecycle
	$('.lifecycleHandle').bind('click',lifecycleHandler,false); 
	//$('#lifecycleTrigger').bind('click',lifecycleHandler,false); 
	
	//Replay Home Slider
	$('#homeSliderControls li#homeSliderControls1').click(function () {
		$('#homeSliderControls_PlayPause a.play').click();
	});
	
	//Activate Tabs on Where We Fly page
	$("#tabs").tabs();

});	

