function log(obj) {
	if (window.console && window.console.log)
		window.console.log(obj);
};



function serenaAnimationOne() {
	$("#serena-tennis").animate({top: '0' }, {queue:false, duration:700, easing:'easeOutCubic'});
	$("#bg-bar").animate({bottom: '0' }, {queue:false, duration:700, easing:'easeOutCubic'});
	$("#lady").animate({left: '30px', top: '10px' }, {queue:false, duration:700, easing:'easeOutCubic'});
	setTimeout("serenaAnimationTwo()",1000);
}
function serenaAnimationTwo() {
	$("#hd").fadeIn("slow").animate({left: '503px', top: '25px' }, {queue:false, duration:1000, easing:'easeOutElastic'});
	$("#cta-watch").fadeIn("slow");
	$("#serena-copy").fadeIn("slow");
	$("#cta-tryit").fadeIn("slow");
	$("#tennis-ball").fadeIn("fast").animate({left: '315px', top: '75px' }, {queue:false, duration:700, easing:'easeOutCubic'});
}


function pearlAnimationOne(){
	$("#hd-one").fadeIn(1500);
	setTimeout("pearlAnimationTwo()",1000); 
}
function pearlAnimationTwo() {
	$("#hd-two").fadeIn(1500);
	setTimeout("pearlAnimationThree()",1000);
}
function pearlAnimationThree() {
	$("#pearl-copy").fadeIn(1500);
	$("#pearls:not(:visible)").fadeIn(1500);
	$("#tryit").fadeIn(1500);
}
function downpourAnimationOne() {
	pageTracker._trackPageview('click/centerstage/betty/try_it_free');
	$("#downpour-rain").animate({top: '0'}, {queue:false, duration:4500, easing:'easeInSine'});
	setTimeout("downpourAnimationTwo()",2000);
}
function downpourAnimationTwo() {
	$("#downpour-mothernature2").fadeIn(250);
	$("#downpour-ribbon2").fadeIn(250);
	$("#downpour-mothernature1").fadeOut(250);
	$("#downpour-ribbon1").fadeOut(250);
	setTimeout("downpourAnimationThree()",2000);
}
function downpourAnimationThree() {
	$("#downpour-final").fadeIn("slow");
	setTimeout("downpourAnimationFour()",1000);
}
function downpourAnimationFour() {
	$("#downpour-tryitfree").fadeIn("slow").hover(
	      function () {
	        $(this).find("img").attr("src","/App_Themes/themeTampax/Images/en-US/home/downpour/downpour-tryitfree-hover.gif");
	      }, 
	      function () {
	        $(this).find("img").attr("src","/App_Themes/themeTampax/Images/en-US/home/downpour/downpour-tryitfree-static.gif");
	      }
	    );
	pageTracker._trackPageview('click/centerstage/betty/end');
}

$(document).ready(function() {
	
	
	if($.browser.msie && $.browser.version=="6.0") { var ie6 = true; };
	if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) { var ff2 = true; };
	
	
	var $slideholder = $('#centerstage-panels');
	var slideCount = $slideholder.children().length;
	var cycleFX = "fade";
	if ($.browser.msie && $.browser.version.substr(0,1)<7) { cycleFX = "none"; }
	
    $slideholder.cycle({
		pause: 1, // pause on hover
		pager: "#centerstage-control",
//		autostop: 1,
//		autostopCount: slideCount + 1,
//		end: cyclePause,
		pagerClick: cyclePause,
		before: cycleBefore,
		fx: cycleFX,
		timeout: 9000,
		speed: 700
	});

	function cycleBefore(currSlideElement, nextSlideElement, options, forwardFlag) {
			initAnimations(nextSlideElement.id);
	};
	function cyclePause(zeroBasedSlideIndex, slideElement) {
		$('#centerstage-panels').cycle('pause');
	};
	
	
	function initAnimations(slideid){			
		switch (slideid) {
			case 'serena':
				setTimeout("serenaAnimationOne()",1000);
			  break;

			case 'pearl':
				setTimeout("pearlAnimationOne()",1000);
			  break;
			case 'downpour':
				setTimeout("downpourAnimationOne()",500);
			  break;

			default:
			  return;
		}
	}
	
	
	if (!ff2){ // do not open link in fancybox because FF2 does not the swf file properly
		// serna video ifram link
		$("#cta-watch a").fancybox({
			'overlayShow': true,
			'frameWidth': 500,
			'frameHeight': 585,
			'padding': 0,
			'overlayOpacity': .6,
			'overlayColor': '#000'
		});
	}
		

	// More about popups
		$('.pearl').each(function () {
		    var distance = 10;
		    var time = 500;
		    var hideDelay = 150;
		    var hideDelayTimer = null;
		    var beingShown = false;
		    var shown = false;
		    var trigger = $('a.trigger', this);
		    var info = $('span', this).css('opacity', 0);
			var triggerIMG = $('.pearlIMG', this);
			var offIMG = "/App_Themes/themeTampax/Images/en-US/home/pearl/pearl-off.png"
			var onIMG = "/App_Themes/themeTampax/Images/en-US/home/pearl/pearl-on.png"
			
		    $([trigger.get(0), info.get(0)]).mouseover(function () {
		        if (hideDelayTimer) clearTimeout(hideDelayTimer);
		        if (beingShown || shown) {
		            // don't trigger the animation again
		            return;
		        } else {
		            // reset position of info box
		            beingShown = true;
					if (!ie6) {	triggerIMG.attr("src", onIMG); }
		           	info.css({
		                bottom: 20,
		                display: 'block'
		            }).animate({
		                bottom: '+=' + distance + 'px',
		                opacity: 1
		            }, time, 'swing', function() {
		                beingShown = false;
		                shown = true;
		            });
					var track = trigger.attr("track");
		        }
		        return false;
		    }).mouseout(function () {
		        if (hideDelayTimer) clearTimeout(hideDelayTimer);
		        hideDelayTimer = setTimeout(function () {
					if (!ie6) {	triggerIMG.attr("src", offIMG);	}
		            hideDelayTimer = null;
		            info.animate({
		                bottom: '-=' + distance + 'px',
		                opacity: 0
		            }, time, 'swing', function () {
		                shown = false;
		                info.css('display', 'none');
		            });
		        }, hideDelay);
		        return false;
		    });
		});

});

