/* 

  $Revision: #4 $
  
  Copyright (c) 2006 Amazon.com, Inc.  All rights reserved.

  This component contain javascript functions related to Product Detail Section in detail
  page.
  
  The function present in this component are :

  function changeDetailPageTab(imgIndex, tabCount) : This function is changing images dynamically 
  in tab section.

  function suppressImageTab(tabCount) : This function is suppressing the Image Tab, if there is no Large Image 
  available in product directory for selected ASIN

  function changeSeeMoreInfoImage(imgIndex, tabCount) : This function is collapsing the link " See more information"
  if all the information available fits within the tab section.

  function printTab() : This function is doing browser print in tab pop up

  function openDetailPageTab() : This function create the dynamic URL by adding arguments in string query
  and open product detail section tab pop up

*/
var dpTabs=function(options){var tabCollection=jQuery("div.tab");var tabControls=document.createElement("div");tabControls.className="detailTabs tabCount"+tabCollection.length;var tabsClassRoot=tabCollection.length+"T";var tabsClassSelected="1S";var tabContainer=document.createElement("div");var tabWidget=jQuery("#scripted_tabs");tabContainer.className="detailTabsPanel";this.tabMap={};var tabList=document.createElement("ul");tabControls.appendChild(tabList);tabWidget.append(tabControls);tabWidget.append(tabContainer);var options={tabsClass:".detailTabs li",tabPanels:".tab",offscreenTabs:true};var self=this;for(var i=0;i<tabCollection.length;i++){var tab=tabCollection.eq(i);var link=document.createElement("a");link.href="#"+tab.attr("id");var tabText=tab.attr("id");if(tab.attr("rel")&&tab.attr("rel")!=""){tabText+=" "+tab.attr("rel")}link.appendChild(document.createTextNode(tabText));var li=document.createElement("li");if(i==0||tab.hasClass("default")){jQuery("li",tabList).removeClass("tabs-selected");li.className="tabs-selected";tabsClassSelected=i+1+"S"}jQuery(link).data("index",i+1);li.appendChild(link);tabList.appendChild(li);this.tabMap[tab.attr("id")]=li;this.tabMap[i]=tab.attr("id");jQuery(link).hover(function(){classes=tabControls.className.split(" ");cClass=classes.pop();cClassParts=cClass.split("_");if(cClassParts.length==2){cClassParts.push(jQuery(this).data("index")+"H")}else{cClassParts[3]=jQuery(this).data("index")+"H"}classes.push(cClassParts.join("_"));tabControls.className=classes.join(" ")},function(){classes=tabControls.className.split(" ");cClass=classes.pop();cClassParts=cClass.split("_");if(cClassParts.length==4){cClassParts.pop()}classes.push(cClassParts.join("_"));tabControls.className=classes.join(" ")});tab.addClass("tab"+i);tab.attr("tabIndex",0);tab.clone().appendTo(tabContainer);tab.remove();options["tab"+i]={onload:function(tabID){classes=tabControls.className.split(" ");cClass=classes.pop();cClassParts=cClass.split("_");cClassParts[2]=(this.getMainTabId()+1)+"S";classes.push(cClassParts.join("_"));tabControls.className=classes.join(" ");self.currentTabId=this.getMainTabId();if(this.data("active")==true){jQuery("div.tab"+this.getMainTabId(),tabContainer).focus();var rtag="pd_tab_"+this.getCurrentPanel().attr("id").toLowerCase().replace(/[^a-zA-Z 0-9]+/g,"")+"_open";vsReportActionEvent(rtag,PageUtils.Variables.get("pageAsin"))}else{}}};jQuery(".tab",tabContainer).bind("innerFocus",function(){tabWidget.data("active",false);self.showTab(this.id);tabWidget.data("active",true)});jQuery("*",tabContainer).focus(function(){jQuery(this).trigger("innerFocus")}).blur(function(){jQuery(this).trigger("innerBlur")})}tabControls.className+=" tabSpec_"+tabsClassRoot+"_"+tabsClassSelected;tabWidget.tabs(options);tabWidget.data("active",true);this.showTab=function(id,force_focus,offset){if(typeof this.tabMap[id]!="undefined"){var ff=force_focus||false;offset=offset||0;if(!ff&&id==self.tabMap[self.currentTabId]){return}tabWidget.changeTab(this.tabMap[id]);jQuery(document).scrollTop(tabWidget.offset().top+offset)}};if(typeof(target.audio.initializeTracks)=="function"){target.audio.initializeTracks()}};jQuery(function(){var cartHandler=$("#cartHandler");cartHandler.data("original_action",cartHandler.attr("action"));$("#LayersFrame").bind("LayerHidden",function(){cartHandler.attr("action",cartHandler.data("original_action"))});TabController=new dpTabs();window.setTimeout(function(){jQuery(".tabContent").hide().show()},0);$(".quickInfo").quickinfo();$("#seeMoreDescription").expander({onExpand:function(){vsReportActionEvent("pd_tab_det_moredesc",PageUtils.Variables.get("pageAsin"))},onCollapse:function(){vsReportActionEvent("pd_tab_det_lessdesc",PageUtils.Variables.get("pageAsin"))},expandLinkText:"More <span class='offscreen'>description</span> +",collapseLinkText:"Less <span class='offscreen'>description</span> -"});$("#sortReviews").autoSubmit();$("#printButton").click(function(){window.print()});$("body").append("<img src='https://images-na.ssl-images-amazon.com/images/G/16/nav/aug09_gn/bullseye._V218318638_.png' class='offscreen' id='printBullseye' alt='Target.com'/>");var emailForm=$("#emailReveal_overlay").ajaxform({checkSignInFunc:function(options,callback){var signedIn=($("#TAFSignInRequired").val()=="true")?false:true;var ajaxform=this;callback.call(ajaxform,signedIn)},checkSignInAjax:function(options,callback){var ajaxform=this;var cachebust=new Date().getTime();$.getJSON(options.postURL+"&TAFAction=display&ts="+cachebust,function(response){if(response.signedIn=="true"){$("div.yourEmail span.staticField",ajaxform).html(response.emailAddress)}callback.call(ajaxform,response.signedIn)})},postCallback:function(response,options){if(typeof response.signin!="undefined"&&response.signin=="true"){this.showSignIn()}else{if(typeof response.error=="undefined"){this.showSuccess();$(options.messageDiv,this).focus()}else{if(response.error=="TAFTo"){var errorText=(response.exceededMaxLimit)?"Too many email addresses":"Invalid email address";new PageUtils.ErrorFlag($("#friendsEmail",this),{errorText:errorText,leftOffset:261})}}}}}).bind("redraw",function(){Interface.RevealManager.getReveals().emailReveal._positionOverlay()});$("#emailReveal_button").click(function(){emailForm.checkSignIn({useAjax:true})});$("#emailReveal_overlay .sendAgain").click(function(){emailForm.showForm();return false});$("#emailReveal_overlay .signInLink").click(function(){if(window.location.protocol!="https:"){PageUtils.setVar("VariationController.clickElement",$(this).attr("id")||$(this).attr("name"));PageUtils.setVar("VariationController.serialized",VariationController.serialize());var newUrl=String(PageUtils.getNewURL("https:"));window.location=newUrl}else{var sButton=document.createElement("button");sButton.setAttribute("id","TAFSignInPostBack");$("body").append(sButton);$(sButton).hide().click(function(){$("#TAFSignInRequired").val("false");emailForm.checkSignIn({useAjax:false});$("#emailReveal_button").click()});var time=new Date();var path="/layers/click-element?htmlElementId=TAFSignInPostBack&time="+time.getTime();showLayerFromParentJSON({top:"125"});setLayerPath(path)}return false});$("#similarItemsWidget a.productTitle").truncate();$("div.upsellWidget a.productTitle").truncate();$("div.recentlyViewed div.recentlyViewedDetails a.productTitle").truncate({fitToLine:3})});function setFocusOnReviews(){var tabWidget=jQuery("#scripted_tabs");tabWidget.data("active",false);var offset=(jQuery("#buyBox").offset().top-tabWidget.offset().top)*0.75;TabController.showTab("Reviews",true,offset);tabWidget.data("active",true);vsReportActionEvent("pd_ttl_review",PageUtils.Variables.get("pageAsin"))}function showShippingAndPolicies(){var tabWidget=jQuery("#scripted_tabs");tabWidget.data("active",false);TabController.showTab("Details");tabWidget.data("active",true);location.href="#Shipping&Policies";vsReportActionEvent("pd_info_shipping",PageUtils.Variables.get("pageAsin"))}var selectedDetailTabName;function openDetailTabPopup(url,tabToSelect){if(tabToSelect!=null){url=url+"&tabToSelect="+tabToSelect}window_handle=window.open(url,"ProductDetail","location=0,menubar=0,resizable=no,height=550,width=600,scrollbars=yes,left=220,screenX=220,top=70,screenY=70");if(window_handle){window_handle.focus()}}function promotionDetailsPopup(mylink,choice){if(!window.focus){return true}var href;if(typeof(mylink)=="string"){href=mylink}else{href=mylink.href}href+="?choice="+choice;window.open(href,"OfferDetailsPopUp","location=0,menubar=0,resizable=no,height=600,width=295,scrollbars=yes,left=220,screenX=220,top=70,screenY=70");return false}function hm_popup_onclick(){var anc=document.getElementById("hm_popup_anchor");if(anc&&anc.href){var ContextWindow=window.open(anc.href,"top","width=447,height=500,scrollbars=1");ContextWindow.focus();return false}};
