var accessoriesController;var AccessoriesController=function(){}
AccessoriesController.prototype={initialize:function(){this.container=document.getElementById("accessories-wrapper");this.widgetContent=true;if(this.container==null)this.widgetContent=false;this.itemsSelected={};this.itemsSelectedCount=0;this.suppressBuyBox=document.getElementById("accessories_suppressBuyBox_flag").value;this.humbler=document.getElementById("accessories_humbler_flag").value;this.isGlance=document.getElementById("accessories_glanceView_flag").value;this.scrollInterval=50;this.scrollDistanceMax=150;this.scrollDistanceDefault=25;this.scrollDistance=this.scrollDistanceDefault;this.scrollDistanceIncreaseAmount=5;this.scrollDistanceIncreaseInterval=1;this.scrollTimer=null;this.targetOffset=null;this.currentlyScrolling=false;this.distanceToScroll=null;this.scrollCounter=0;this.scrollerDivOuter=document.getElementById("accessories-scroller-outer");if(this.scrollerDivOuter){this.scrollerDivOuter.scrollLeft=0;this.scrollerDivOuter.onmouseover=function(){accessoriesController.trimInnerScrollWidth()};this.scrollerDivOuter.onmouseout=function(){accessoriesController.trimInnerScrollWidth()};}
this.scrollerDivInner=document.getElementById("accessories-scroller-inner");if(this.scrollerDivInner)
this.minimumInnerScrollerWidth=this.scrollerDivInner.offsetWidth;var itemData=document.getElementById("accessories_itemData").value;this.itemData=eval('('+itemData+')');var imageData=document.getElementById("accessories_imageData").value;this.imageData=eval('('+imageData+')');var imageAltData=document.getElementById("accessories_imageAltData").value;this.imageAltData=eval('('+imageAltData+')');this.checkForSafari();this.updateAccessories();this.updateRefTags();},updateRefTags:function(){var bbForm=document.getElementById("accessories.handleBuy");if(bbForm)bbForm.action=bbForm.action.replace('_nj','');function updateItemLinks(parent){var itemLinks=parent.getElementsByTagName("a");for(var i=0;i<itemLinks.length;i++){if(itemLinks[i].href)itemLinks[i].href=itemLinks[i].href.replace('_nj','');}}
if(this.isGlance==1)
updateItemLinks(document.getElementById("accessories-scroller-inner"));else{for(var binNum=1;binNum<=9;binNum++){var categoryDiv=document.getElementById("accessory-category-"+binNum);if(categoryDiv)updateItemLinks(categoryDiv);}}},checkForSafari:function(){if(navigator.userAgent.indexOf("Safari")>-1){this.container.className+=" safari";}},registerEventHandlers:function(){if(this.suppressBuyBox==0){this.addWindowClickEventHandler(this.checkToHidePopup);}},updateAccessories:function(){if(this.suppressBuyBox==0){this.updateItemsSelected();}
if(this.isGlance==1){var sideBarElementId="accessories-box-sidebar";if(this.humbler==1)
sideBarElementId="accessories-main-item";var sideBarHeight=document.getElementById(sideBarElementId).offsetHeight;var categoriesHeight=document.getElementById("accessories-scroller-inner").offsetHeight;if(sideBarHeight>categoriesHeight)
this.normalizeRowHeightsForGlance(sideBarHeight-categoriesHeight+availabilityRowHeight,"p","availability");}},updateItemsSelected:function(){var itemsSelectedCountElement=document.getElementById("items-selected-count");itemsSelectedCountElement.innerHTML=this.itemsSelectedCount;this.updateItemsSelectedPopup();var buybox=document.getElementById("accessories-buy-box");var addSelectedToCart=document.getElementById("add-selected-to-cart");var popoverTrigger=document.getElementById("items-selected-trigger");if(this.itemsSelectedCount>0){buybox.className="acc_enabled";addSelectedToCart.disabled=false;}else{buybox.className="";addSelectedToCart.disabled=true;this.hidePopup();}},updateItemsSelectedPopup:function(){var htmlString="";var priceTotal=0;var index=0;for(var asinString in this.itemsSelected){var asinObject=this.itemData[asinString];var style=(index==this.itemsSelectedCount-1)?" style='border:none'":"";htmlString+="<div class='selected-item'"+style+">";htmlString+="<span class='product-title'>";htmlString+="<a href='#' onclick='accessoriesController.removeItem(\""+asinString+"\"); return false; ' >";htmlString+="<img src='"+this.getImageURL("transparent-pixel")+"' class='selected-items-remove accSprite s_accClose' alt='"+this.imageAltData['remove']+"' />";htmlString+="</a>";htmlString+=asinObject.title;htmlString+="</span>";if(this.priceFormatter){htmlString+="<span class='price'>";htmlString+=this.priceFormatter.formatPrice(asinObject.price);htmlString+="</span>";}
htmlString+="<div style='clear: both; height: 0; line-height: 0;'>&nbsp;</div>";htmlString+="</div>";priceTotal+=asinObject.price;index++;}
document.getElementById("selected-items").innerHTML=htmlString;if(this.priceFormatter){priceTotal=this.priceFormatter.formatPrice(priceTotal);document.getElementById("cart-subtotal-price").innerHTML=priceTotal;}
if(this.itemsSelectedCount>4){document.getElementById("selected-items").className="scrollbars";}else{document.getElementById("selected-items").className="";}
if(this.itemsSelectedCount>0)
document.getElementById("items-selected-show-popup").href="#";else
document.getElementById("items-selected-show-popup").removeAttribute('href');},addWindowClickEventHandler:function(eventHandler){var method=window.onmousedown;if(navigator.userAgent.indexOf("MSIE")>-1){if(typeof method=='function'){document.getElementsByTagName("body")[0].onmousedown=function(e){method(e);if(accessoriesController.widgetContent)eventHandler(e);}}else{document.getElementsByTagName("body")[0].onmousedown=function(e){if(accessoriesController.widgetContent)eventHandler(e);}}}else{if(typeof method=='function'){window.onmousedown=function(e){method(e);if(accessoriesController.widgetContent)eventHandler(e);}}else{window.onmousedown=function(e){if(accessoriesController.widgetContent)eventHandler(e);}}}},selectItem:function(asin,button){this.itemsSelected[asin]=button;var img;for(var i=0;i<button.childNodes.length;i++)
if(button.childNodes[i].tagName=='IMG'){img=button.childNodes[i];break;}
if(img){img.className=img.className.replace('s_accSelectThis','s_accRemoveThis');img.alt=this.imageAltData["remove"];}
button.onclick=function(){accessoriesController.removeItem(asin);return false;}
this.itemsSelectedCount++;this.updateItemsSelected();},removeItem:function(asin){var button=this.itemsSelected[asin];var img;for(var i=0;i<button.childNodes.length;i++)
if(button.childNodes[i].tagName=='IMG'){img=button.childNodes[i];break;}
if(img){img.className=img.className.replace('s_accRemoveThis','s_accSelectThis');img.alt=this.imageAltData["select"];}
button.onclick=function(){accessoriesController.selectItem(asin,button);return false;}
var itemsSelected={};for(var selectedAsin in this.itemsSelected){if(selectedAsin!=asin){itemsSelected[selectedAsin]=this.itemsSelected[selectedAsin];}}
this.itemsSelected=itemsSelected;this.itemsSelectedCount--;this.updateItemsSelected();},clearAll:function(){for(var selectedAsin in this.itemsSelected){this.removeItem(selectedAsin);}},checkToHidePopup:function(e){var popup=document.getElementById("items-selected-popup");if(popup==null)return;if(typeof e=='undefined')
e=event;var myPos=accessoriesController.findPos(popup);var cLeft=myPos[0];var cRight=cLeft+popup.scrollWidth+25;var cTop=myPos[1];var cBottom=cTop+popup.offsetHeight+25;var ex=e.clientX;var ey=e.clientY;if(ex<cLeft||ex>cRight||(ey+myPos[3])<cTop||(ey+myPos[3])>cBottom){accessoriesController.hidePopup();}},hidePopup:function(){this.togglePopup(false);},togglePopup:function(showing){if(this.itemsSelectedCount<1){showing=false;}
var wrapper=document.getElementById("cart-wrapper");if(showing==undefined)
showing=wrapper.className!="acc_showing";wrapper.className=showing?"acc_showing":"";document.getElementById("items-selected-wrapper").style.backgroundImage=(showing)?"url("+this.getImageURL("items-selected-button-repeat")+")":"";document.getElementById("items-selected-wrapper-left").style.backgroundImage=(showing)?"url("+this.getImageURL("items-selected-button-left")+")":"";document.getElementById("items-selected-wrapper-right").style.backgroundImage=(showing)?"url("+this.getImageURL("items-selected-button-right")+")":"";if(showing){document.getElementById('items-selected-popup-title').focus();}},scrollTo:function(id){if(this.currentlyScrolling==true){return false;}
var targetElement=document.getElementById(id);this.targetOffset=this.findPos(targetElement)[0]-document.getElementById("accessories-box-sidebar").offsetWidth-40;this.distanceToScroll=Math.abs(this.scrollerDivOuter.scrollLeft-this.targetOffset);this.currentlyScrolling=true;if(this.targetOffset>this.scrollerDivOuter.scrollLeft){this.scrollTimer=setInterval(function(){var currentScrollLeft=accessoriesController.scrollerDivOuter.scrollLeft;accessoriesController.scrollRight();if(accessoriesController.targetOffset<=(accessoriesController.scrollerDivOuter.scrollLeft+accessoriesController.scrollDistance)||accessoriesController.scrollerDivOuter.scrollLeft==currentScrollLeft){accessoriesController.setScrollOffset(accessoriesController.targetOffset);accessoriesController.stopScrolling();}},this.scrollInterval);}else{this.scrollTimer=setInterval(function(){accessoriesController.scrollLeft();if(accessoriesController.targetOffset>=(accessoriesController.scrollerDivOuter.scrollLeft-accessoriesController.scrollDistance)||accessoriesController.scrollerDivOuter.scrollLeft==0){accessoriesController.setScrollOffset(accessoriesController.targetOffset);accessoriesController.stopScrolling();}},this.scrollInterval);}},scrollRight:function(){this.setScrollOffset(this.scrollerDivOuter.scrollLeft+this.scrollDistance);this.scrollCounter++;this.adjustScrollDistance();},scrollLeft:function(){this.setScrollOffset(this.scrollerDivOuter.scrollLeft-this.scrollDistance);this.scrollCounter++;this.adjustScrollDistance();},adjustScrollDistance:function(){if(this.scrollCounter%this.scrollDistanceIncreaseInterval==0){if(Math.abs(this.targetOffset-this.scrollerDivOuter.scrollLeft)<=this.distanceToScroll/2){this.scrollDistance-=this.scrollDistanceIncreaseAmount;if(this.scrollDistance<this.scrollDistanceDefault){this.scrollDistance=this.scrollDistanceDefault;}}else{this.scrollDistance+=this.scrollDistanceIncreaseAmount;if(this.scrollDistance>this.scrollDistanceMax){this.scrollDistance=this.scrollDistanceMax;}}}},stopScrolling:function(){clearInterval(accessoriesController.scrollTimer);this.currentlyScrolling=false;accessoriesController.scrollCounter=0;accessoriesController.scrollDistance=accessoriesController.scrollDistanceDefault;},setScrollOffset:function(offset){var maximumScrollOffset=this.minimumInnerScrollerWidth-this.scrollerDivOuter.offsetWidth;if(offset>maximumScrollOffset)
this.scrollerDivInner.style.width=(offset+this.scrollerDivOuter.offsetWidth)+'px';else
this.scrollerDivInner.style.width=this.minimumInnerScrollerWidth+'px';this.scrollerDivOuter.scrollLeft=offset;},trimInnerScrollWidth:function(){if(this.scrollerDivInner.offsetWidth>this.minimumInnerScrollerWidth&&this.scrollerDivOuter.scrollLeft<this.scrollerDivInner.offsetWidth-this.scrollerDivOuter.offsetWidth)
{this.scrollerDivInner.style.width=Math.max(this.scrollerDivOuter.scrollLeft+this.scrollerDivOuter.offsetWidth,this.minimumInnerScrollerWidth)+'px';}
this.delayedScrollEventTimer=null;},getImageURL:function(image){return(this.imageData[image]!=null)?this.imageData[image]:"";},findPos:function(obj){var curleft=curtop=scrolltop=scrollleft=0;if(obj==null)return;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;scrolltop=obj.scrollTop;scrollleft=obj.offsetLeft;while(obj=obj.offsetParent){curleft+=obj.offsetLeft;curtop+=obj.offsetTop;if(scrolltop<obj.scrollTop)scrolltop+=obj.scrollTop;if(scrollleft<obj.offsetLeft)scrollleft+=obj.offsetLeft;}}
if(navigator.userAgent.indexOf("Safari")>-1){var dataString=navigator.userAgent;var verString="Version/";var index=dataString.indexOf(verString);if(parseFloat(dataString.substring(index+verString.length))<3){scrolltop=0;}}
return[curleft,curtop,scrollleft,scrolltop];},accessoriesFormSubmit:function(){var accessoriesForm=document.getElementById("accessories.handleBuy");var htmlString="";if(this.itemsSelectedCount<1){return false;}
for(var asinString in this.itemsSelected){var asinObject=this.itemData[asinString];htmlString+="<input type='text' name='offeringID."+asinObject.type+"."+asinString+"' value='"+asinObject.offeringid+"' />";}
var formFields=document.getElementById("accessories-form-fields");if(accessoriesForm&&formFields)
{formFields.innerHTML=htmlString;accessoriesForm.submit();}else{return false;}}};function constructAccessoriesController(currencyCode){accessoriesController=new AccessoriesController();amznJQ.onReady('priceformatterJS',function(){accessoriesController.priceFormatter=new CurrencyFormatter(currencyCode);});accessoriesController.initialize();accessoriesController.registerEventHandlers();}
function onAjaxUpdate_accessories_and_compatible_products(childASIN){if(!accessoriesController)constructAccessoriesController();else accessoriesController.initialize();}
function onCacheUpdate_accessories_and_compatible_products(childASIN){if(!accessoriesController)constructAccessoriesController();else accessoriesController.initialize();}
if(amznJQ&&amznJQ.declareAvailable)amznJQ.declareAvailable('accessoriesJS');