
// Setup namespace
if(!argos) var argos = {};
if (!argos.product) argos.product = {};

// begin: argos.product.details
if (!argos.product.details) argos.product.details = {};
argos.product.details.Tabs = {

	reviewsState: { productId: "" , numReviews: 0 , rating : "1.0" , ratingsOnlyReviewCount : 0, buyAgainPercentage : 0 },
	
	init : function() {
		// get defensive (exit if no headings found)
		if ($("#producttabs h4").length == 0) return;
		// manage the display of JavaScript tabs
		// add click events to elements

		// A class is added to this wrappper to allows the css to target the javascript enabled  styles
		// Add JS Wrapper
		$("#tabwrapper").addClass("jstabs");
		//$("#producttabs").wrap('<div id="jstabs"></div>');
		// Add additional class to JS tabs 
		$(".jstabs #producttabs h4").addClass("jstabstyle");
		$(".jstabs #producttabs div h4").removeClass("jstabstyle");
		
		// Position Special Offers Tab for no credit options scenario
		if(!$("#tab4")[0]) {
			$("h4#tab3").addClass("twotabs");
		}
		
		// positions for reviews tab if other tabs present
		if(!$("#tab3, #tab4")[0]) {
			$("h4#tabrev").addClass("twotabs");
		} else if(($("#tab3")[0]) && ($("#tab4")[0])) {
			$("h4#tabrev").addClass("fourtabs");
		} else if(($("#tab3")[0]) || ($("#tab4")[0])) {
			$("h4#tabrev").addClass("threetabs");
		}
		
		// Hide all but the default tab
		argos.product.details.Tabs.selectDefaultTab();
				
		//add cursor
		$("#producttabs h4").css(
			{cursor : 'pointer'}
		);	
		
		// END: Tab Script
		
		// Show Special Offers Tab 
		$("#showspecialoffers").click( 
			function() { 
				wrong_s_objectID='specialoffers'; 
				argos.product.details.Tabs.hideAllTabs(); 
				argos.product.details.Tabs.showTab("tab3"); 
			}
		);
		
		// Show Credit Details Tab
		$("#showcreditinfo").click( 
			function() { 
				argos.product.details.Tabs.hideAllTabs(); 
				argos.product.details.Tabs.showTab("tab4"); 
			}
		);
		// Show reviews Tab
		$("#BVSummaryReadReviewsLinkCount").click( 
			function() { 
				argos.product.details.Tabs.hideAllTabs(); 
				argos.product.details.Tabs.showTab("tabrev"); 
			}
		);
		
		
		//Add PDP RC Icons tagging click event 
		$(".rclargeimglink a").click(
			function (){
				var rcTabs = argos.richcontent.Tabs;
				var partNumber = rcTabs.getPartNumber(this.href);
				rcTabs.triggerTaggingEvent(".rclargeimglink", "iconclicked", partNumber);
			}
		);
		
		$(".rclink360 a").click(
			function (){
				var rcTabs = argos.richcontent.Tabs;
				var partNumber = rcTabs.getPartNumber(this.href);
				rcTabs.triggerTaggingEvent(".rclink360", "iconclicked", partNumber);
			}
		);
		
		$(".rcvideolink a").click(
			function (){
				var rcTabs = argos.richcontent.Tabs;
				var partNumber = rcTabs.getPartNumber(this.href);
				rcTabs.triggerTaggingEvent(".rcvideolink", "iconclicked", partNumber);
			}
		);
		//rc add event ENDS
		
		//Temporarily adding event to ratings image. This would be done using onclick once BV have modified their
		//content	
		//$("div#BVCustomerRatings table.BVRatingSummary div.BVRatingSummaryRatingsRatingSet .BVcustomerRatingFirst img")
		//.bind("click", argos.product.details.Tabs.selectReviewsTab);
		
	}, // end init()
	
	addEvents : function(){
		// add click events to headings
		$("#producttabs h4").click(
			function() {							
				argos.product.details.Tabs.doShowTab($("#producttabs h4#"+this.id));
			}
		);/***/
	},
	
	hideAllTabs : function() {
		$(".tab1").hide(); 
		$(".tab2").hide(); 
		$(".tab3").hide(); 
		$(".tab4").hide();
		$(".tabrev").hide(); 
		$(".jstabs h4#tab1").removeClass("active");
		$(".jstabs h4#tab2").removeClass("active");
		$(".jstabs h4#tab3").removeClass("active");
		$(".jstabs h4#tab4").removeClass("active");
		$(".jstabs h4#tabrev").removeClass("active");
	},
	
	/** eg: showTab("tab3") */
	showTab : function(sTabName) {
		$(".jstabs h4#"+sTabName).addClass("active");
		$("."+sTabName).show(); 
		argos.product.details.Tabs.addEvents();
		$("h4#"+sTabName).unbind();
	},
	
	removeEvents : function(){
		$("h4#tab1").unbind(); 
		$("h4#tab2").unbind(); 
		$("h4#tab3").unbind(); 
		$("h4#tab4").unbind();
		$("h4#tabrev").unbind();
	}, // END: removeEvents 
	
	triggerTaggingEvent : function(objId, strEventName){
		var tabs = argos.product.details.Tabs;
		if(strEventName=='tabclicked'){
			var taggableObj = false;
			var s=s_gi(s_account);			
			s.linkTrackVars="products,eVar28";
			if(objId=='tab3'){
				taggableObj = true;
				linkName="Special Offers";
			}else if(objId=='tabrev'){
				taggableObj = true;
				linkName="Reviews";
				s.linkTrackVars="products,eVar28,eVar30,eVar31";	
				if(window.omnitureReview!=undefined && window.omnitureReview.totalReviewCount!=undefined){
					s.eVar30=omnitureReview.totalReviewCount;
				}
	            if(window.omnitureReview!=undefined && window.omnitureReview.avgRating!=undefined){
	              	s.eVar31=omnitureReview.avgRating;
	            }
				
			}else if(objId=='tab4'){
				taggableObj = true;
				linkName="Credit Offers";
			}else if(objId=='tab1'){
				taggableObj = true;
				linkName="Details";
			}
			if(taggableObj){
				var obj = document.getElementById(objId);
				s.eVar28 = linkName;
				//alert(obj+" - "+obj.id+" - "+ linkName);				
				s.tl(obj,'o',linkName);
			}
		}	
		
	},
	
	selectDefaultTab : function (){
		var defaultTab = $("#producttabs h4#tab1"); //Default
		var selectedTab = defaultTab; //Default
		var gotoTab = $("input#gotoTab")[0];		
		
		if(typeof gotoTab !="undefined" && gotoTab.value != ""){
			if(gotoTab.value=="reviews"){				
				selectedTab = $("#producttabs h4#tabrev");
			}
		}		

		if(selectedTab.is(':visible')){			//Check if selected tab is visible			
			argos.product.details.Tabs.doShowTab(selectedTab);
		}else {									//if(typeof defaultTab[0] !="undefined")
			argos.product.details.Tabs.doShowTab(defaultTab);
		}
	},
	
	selectReviewsTab : function (){
		$("input#gotoTab").val("reviews");
		argos.product.details.Tabs.selectDefaultTab();
		//IE reviews anchor hack
		if($.browser.msie && $.browser.version === '6.0'){
			//Dirty IE 6 hack
			window.location.href="#producttabs";
		}else{
			
			window.location.href="#tabrev";
		}
	},
	
	doShowTab : function(tabObj) {	
		argos.product.details.Tabs.removeEvents(); 
		argos.product.details.Tabs.hideAllTabs(); 
		argos.product.details.Tabs.showTab(tabObj[0].id);
		argos.product.details.Tabs.triggerTaggingEvent(tabObj[0].id, "tabclicked");
	}
	

}; // end argos.productDetails.tabs (namespace)


// START: Jquery Tabs
$(document).ready(
	function() {
		argos.product.details.Tabs.init();		
	}
); // end domready