

var ItemHandler = function() {

	var activeId = 0;
	
	// positions for all tabs
	var animationObj = {"args" : [
		{left:"320px", top:"6px"},
		{left:"-20px", top:"21px"},
		{left:"0px", top:"57px"},
		{left:"51px", top:"93px"},
		{left:"19px", top:"129px"},
		{left:"-3px", top:"166px"}
	]
	};

	return {
	
		animateItem : function (idx) {
		
			// set style
			$("ul#rotating-tabs li span").removeClass();
									
			// animate out the clicked item
			$('li#tab'+idx+' img').fadeTo( 500, .0);
			$('li#tab'+idx).animate(animationObj.args[0], 500, function (){
			
				$("ul#rotating-tabs li#tab"+idx+" span").addClass('nowActive');
			
			
			});
			$('li#tab'+idx).css("z-index","1");
			
			// animate in the previous item
			$('li#tab'+activeId+' img').fadeTo( 500, 1.0);
			$('li#tab'+activeId).animate(animationObj.args[activeId], 500).css;
			
			$('li#tab'+activeId).css("z-index","2");
			activeId = idx;
			
			// show content associated with the clicked item
			var to2 = setTimeout(function(){
				$("div#tab-content div.content-copy").fadeIn();			
			},500);
			
		},
		
		initTabs : function () {
		
			// place the green bg images into each tab
			$('ul#rotating-tabs li').each(function(i){
				$(this).append("<img src='/SiteCollectionImages/Tampax/en-US/home/green-bar-3.png' class='png-fixed' />");
			});
			
			ItemHandler.animateItem(1);
			$("div#tab-content div.content-copy").show();
			
			var to2 = setTimeout(function(){
				$("div#tab-container").css("visibility","visible");
			},1000);
		
			
		}	
	};
}();

$(document).ready(function() {

	ItemHandler.initTabs();
	
	$("ul#rotating-tabs li span").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);
	
	$("ul#rotating-tabs li").click(function() {
	
		// hide the tab content 
		$("div#tab-content div.content-copy").fadeOut();
		
		// get the index value from the tab ID
		var itemIndex = parseFloat(this.id.split("tab")[1]);
		
		// wait a sec, then animate the tab
		var to2 = setTimeout(function(){
			ItemHandler.animateItem(itemIndex);
		},100);
		
		
	    	
	});
});	