$(document).ready(function() {
		
	//Placeholder Text functionality for non supported browsers -Sign up Email Field of Homepage
	var cpEmail="Enter your email here";
	$('#cp-email').val(cpEmail);
	$('#cp-email').live('click', function(){
		$('#cp-email').css('color','#333');
		if($('#cp-email').val()=="Enter your email here"){
			cpEmail="";
			$('#cp-email').val(cpEmail);
		}
	});
	
		//Banner Slideshow
		$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
			$(pager).find('a').removeClass('activeslide').filter('a:eq('+currSlideIndex+')').addClass('activeslide'); 
			if($.browser.msie && $.browser.version < 9){
				$(pager).find('a').removeClass('ie-activeslide').filter('a:eq('+currSlideIndex+')').addClass('ie-activeslide'); 
			}	
		}; 
		

        var startSlideShow = setInterval(function(){
      	  if(jQuery("#featured-area img").length > 0) {
        	clearInterval(startSlideShow);
        	$('#featured-area script').remove();
        	$('#featured-area').cycle({
                        fx: 'fade',  // choose your transition type, ex: fade, scrollUp, shuffle, etc...
                        pager:  '#slide-numbers-with-links',
                        startingSlide: 0,
                        speed: 2000,
                        timeout:  8000,
                        next: '#next-slide', 
                        prev: '#prev-slide', 
                        pagerAnchorBuilder: function(idx, slide) { 
                        	return '<a href="javascript:void(0)" onclick="pageTracker._trackPageview(\'/home/slidetab/'+slide.id+'\');">'+(parseInt(idx)+1)+'</a>'; 
                        }
                });
      	  }
  	}, 1);


		

	 //$('#slide-numbers-with-links a:first-child').hide(); 	

	/*$('.pcfb').livequery(function(){ $(this).fancybox({
			type:  'iframe',
			modal: true,
			height:  560,
			width:  734,
			padding:  2,
			zoomSpeedIn:  600,
			zoomSpeedOut:  500,
			overlayOpacity:  0.7,
			overlayColor: '#000000',
			onStart: function(){ $('#featured-area').cycle('pause'); },
			onClosed: function(){ $('#featured-area').cycle('resume'); }
		})
		
	});*/
	

});
function specialOffersHomePage(){
	//Special Offers in homepage
	   var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	   $("#specialOffers").live('click',function(){
		    specialOffersValidate();
			return false;
		  })  
		$('#cp-email').live('keypress', function(e) {
	            code= (e.keyCode ? e.keyCode : e.which);
	            if (code == 13){
					 specialOffersValidate();
 					 return false;
				}
	        });

	function specialOffersValidate(){
		var email_field_value=$('#cp-email').val();
		if(email_field_value==''){
			alert("Please enter a valid email address");
			return false;
		}
		if(!emailReg.test(email_field_value)){
			alert("Please enter a valid email address");
			return false;
		}
		else{
			specialOffersURL="/captaincircle/specialOfferRegistration.page";
			url =$bookURL+specialOffersURL+'?email=' + $('#cp-email').val();
		    jQuery('#special-offers-signup').html('<div class="main-lightbox">&nbsp; </div>\
			<div id="special-offers-lightbox">\
			<iframe src="'+url+'" height="442" width="417" frameBorder="0"> </iframe>\
			<a href="javascript:void(0)" id="special-offers-close-btn"><img width="45" height="12" alt="Close" src="/images/'+ shared_path+'/special_popup_close_btn.gif"></a></div>\
			');
			jQuery('#special-offers-signup').show();
			center_special_offers_lightbox();
			jQuery('#special-offers-close-btn').click(function(){
				jQuery('#special-offers-signup').hide();
			})
			return false;
		}
	}
	
		
}



function p13nRestoreHome( pax ){	
	specialOffersHomePage();
	if( pax == undefined ){
		if(  getCookie("LOGIN_UID") == undefined ||  getCookie("LOGIN_UID") == "" ){
			return false; 
		}
		else{
			var pax = new Object();
			pax.name_on_top_banner = getMixedCaseName(getCookie("NAME_ON_TOP_BANNER"));
			pax.dtes = getCookie("dtes");
			pax.bN = getCookie("bN");
			pax.tN = getCookie("tN");
			pax.firstname = getCookie("firstname");
			pax.lastname = getCookie("lastname");
			
			$('#offers-brochures').hide();
			$('#shorex-box').show();			
			
		}
		
	}	
	var cpLink = "javascript:goToCP('"+pax.firstname+"','"+pax.lastname+"','"+pax.bN+"')";
	var cpGa = "pageTracker._trackPageview(\'/home/yourcruise/cp\')";	
	
	//printSignInBanner( pax );

	if( pax.dtes > 0 && pax.dtes != null  ){
		var dayVerb = pax.dtes == 1 ? "day!" : "days!";
		$('#already-booked h2').html('<img src="/images/global/welcome_back_home.png">');
		$('#already-booked h6').html('Your '+pax.tN+' cruise sets sail in <strong>'+pax.dtes+'</strong>'+dayVerb);
		//$('#already-booked-button').attr('href',cpLink).attr('onclick',cpGa);
		$('#cp-footer').attr('href', cpLink );
	}
	if( pax.bN == null  ){ 
		var myPrincessLink = "javascript:goToUrl( getBookUrl(getUrl()), 'captaincircle/myPrincess.page')";
		var myPrincessGa = "javascript:pageTracker._trackPageview(\'/home/welcomeback/myprincess\');";
		
		$('#already-booked h2').html('<img src="/images/global/welcome_back_home.png">');
		$('#already-booked h6').text('Update your preferences and see your latest offers.');
		$('#already-booked-button').attr('href',myPrincessLink).attr('onclick',myPrincessGa);
		$('#already-booked-button').text('Visit My Princess');
//		$('#already-booked-button').html('<img src="/images/global/MP_icon_home.gif" width="20" height="20" alt=""><a '+myPrincessGa+' href="'+myPrincessLink +'">Visit My Princess</a>');
		
	}
}

function goToCP(firstname, lastname, bN){
	$('input[name="firstName"]').val(firstname);
	$('input[name="lastName"]').val(lastname);
	$('input[name="bookingId"]').val(bN);
	$('#goToCP').attr('action', getBookUrl(getUrl())+'cruisepersonalizer/retrieve.page?fromMyPrincess=true').submit();
}

function downloadBrochure()
{
window.open(getBookUrl(getUrl())+"captaincircle/brochureRequest.page","_parent");
}


function doSignIn(){
	signIn( function( pax ){
			if( pax.refresh == "true" ){
				window.location.reload();
				return;
			}
			p13nRestoreHome( pax );
			$('#offers-brochures').fadeOut('fast', function(){
				$('#shorex-box').fadeIn("fast");
			 }); 
	});
	//pageTracker._trackPageview ('/home/top/signinregister');
}

function doSignOut(){
	signOut( function signOutSuccess( result ){
		$('#shorex-box').fadeOut('fast', function(){
			$('#offers-brochures').fadeIn("fast");
		});
		
		var cpLink = "javascript:goToUrl(getBookUrl(getUrl()),'cruisepersonalizer/login.page?company=PC')";
		var cpGa = "pageTracker._trackPageview(\'/home/alreadybookedsigninclick\')";
	  	$('#already-booked h2').text('Already Booked?');
	  	$('#already-booked h3').html('Prepare to escape completely with Cruise Personalizer');
		$('#cp-sign-in').html('<img src="/images/global/cp_icon.gif" width="20" height="20" alt=""><a '+cpGa+' href="'+cpLink+'">Access Cruise Personalizer</a>');

	});

}

