/*

    Copyright © 2000-2010 Apple Inc. All Rights Reserved.
    
*/

Package("apple.widget");var VIDEO="video";var IMAGE="image";var QTVR="qtvr";var TOUR="tour";var RIGHT="right";var LEFT="left";var FADE="";var MODE_INLINE="inline";var MODE_GALLERY="gallery";var MODE_ZOOMED="zoomed";var MODE_TOUR="tour";var ModeStyles={};ModeStyles[MODE_INLINE]="";ModeStyles[MODE_GALLERY]="expanded";ModeStyles[MODE_ZOOMED]="expanded zoomed";ModeStyles[MODE_TOUR]="expanded zoomed";function __src(A){if("object"!==typeof (A)){return String(A)}var B=[];var C;for(C in A){B.push(C+"="+A[C])}return B.length?("{ "+B.join(", ")+" }"):"{}"}apple.widget.ProductDetailsGallery=Class.create(coherent.View,{keyDependencies:{selectedImage:["selectedIndex"],caption:["selectedIndex","tourStop","_mode","images"]},exposedBindings:["images","metricsTemplate","locked"],__structure__:{"ul.thumbnails":coherent.ListView({contentBinding:"images",selectedIndexBinding:"selectedIndex",enabledBinding:"locked(NOT)",action:"thumbnailClicked"}),"ul.thumbnails a":coherent.Anchor({hrefBinding:"*.gallery.href"}),"ul.thumbnails img":coherent.ImageView({nullPlaceholder:"/rs/img/block1px.gif",srcBinding:"*.thumbnail.href",widthBinding:"*.thumbnail.width",heightBinding:"*.thumbnail.height"})},selectedClass:"selected",playingClass:"playing",media:Part(".media"),playButton:Part("div.playpause"),galleryLink:Part("a.inlineTourLink"),captionContent:Part(".captionContent"),closeButton:Part(".toggle"),controller:Part(".controller"),product_rating:Part(".product-rating"),microevents:{TourStopped:"StopTour",TourStarted:"StartTour",GalleryDisplayed:"EnterGallery"},tourStopDuration:2500,init:function(){this.base();this.images=coherent.KVO.adapt([]);this._image=null;this._mode=MODE_INLINE;this._imageIndex=0;this.tourStop=null;var D=this.media();if(!D){return }var B=D.getElementsByTagName("img")[0];if(!B){return }this._focusPoint={left:B.width/2,top:B.height/2};this.wrapImage(B);this.wrapImage(document.createElement("img"));this.imageTags=PartList("img",D);this.wrappers=PartList("div",D);Element.setOpacity(this.wrappers(1),0);this.hoverTrackingInfo={mouseEnter:this.mouseEnterThumbnail,mouseExit:this.mouseExitThumbnail,delay:50};Event.observe(Element.query(this.viewElement(),"ul.thumbnails"),"mouseover",this.mouseEnterThumbnail.bind(this));var C=new apple.widget.AnimatedTextWidget(this.captionContent(),this,{html:"*.caption"});var A=new coherent.View(this.captionContent().parentNode,this,{visible:"*.caption"});if(coherent.Browser.IE){Event.observe(this.closeButton(),"mouseover",(function(){this.closeButton().className="toggle toggle-hover"}).bind(this));Event.observe(this.closeButton(),"mouseout",(function(){this.closeButton().className="toggle"}).bind(this))}Event.observe(D,"mousedown",this.mediaMouseDown.bindAsEventListener(this));Event.observe(D,"click",this.mediaClicked.bindAsEventListener(this));Event.observe(this.galleryLink(),"click",this.galleryLinkClicked.bindAsEventListener(this));Event.observe(this.closeButton(),"click",this.closeButtonClicked.bindAsEventListener(this));Event.observe(this.playButton(),"click",this.playButtonClicked.bindAsEventListener(this));if(this.bindings.images&&!this.bindings.images.hasValue()&&this.images){this.bindings.images.setValue(this.images)}this.addObserverForKeyPath(this,this.observeLockedChange,"locked")},wrapImage:function(A){var B=document.createElement("div");if(A.parentNode){A.parentNode.replaceChild(B,A)}else{this.media().appendChild(B)}B.style.left="0";B.style.top="0";B.style.position="absolute";A.style.position="absolute";A.style.left="50%";A.style.top="50%";A.style.marginLeft=Math.floor(-A.width/2)+"px";A.style.marginTop=Math.floor(-A.height/2)+"px";A.galleryimg=false;B.appendChild(A)},observeLockedChange:function(C,B,A){if(this.bindings.locked){this.bindings.locked.setValue(C.newValue)}},observeImagesChange:function(D,C,A){if(coherent.ChangeType.setting!==D.changeType){return }if(D.newValue&&D.newValue.length>0&&this.images){if(this._mode==MODE_ZOOMED||this._futureMode==MODE_ZOOMED){this.setValueForKeyPath(false,"locked");this._mode=MODE_ZOOMED;this.setMode(MODE_GALLERY,null,this.observeImagesChange.bind(this,D,C,A));return }this.setValueForKey(D.newValue,"images");var B=Element.query(this.viewElement(),"ul.thumbnails");Array.forEach(B.getElementsByTagName("li"),function(F,E){switch(E){case 0:F.className="first selected";return ;case 1:F.className="image2";return ;case 2:F.className="image3";return ;default:F.className="extra";return }});switch(this.images.length){case 1:this.controller().className="controller single";this.media().className="media";break;case 2:this.controller().className="controller minimum";this.media().className="media";break;default:this.controller().className="controller";this.media().className="media";break}this.setValueForKey(0,"selectedIndex");this.showImage(0,this._mode,null,true)}},observeMetricsTemplateChange:function(C,B,A){if(coherent.ChangeType.setting!==C.changeType){return }this._metricsTemplate=C.newValue;this._triggeredActions={}},loadAlternateImage:function(B,F,I){if(!this.images){return }if(B==-1&&(this._image===null||"undefined"==typeof (this._image))){return }var J=this;function A(){H.src=C.href;if(I){I.call(J)}}var G=(this._imageIndex?0:1);var H=this.imageTags(G);var D=this.images[B];var C;if(B>=0){C=D[F]}else{C=this._image}H.width=C.dimensions.width;H.height=C.dimensions.height;H.style.width=C.dimensions.width+"px";H.style.height=C.dimensions.height+"px";H.style.marginLeft=-C.dimensions.width/2+"px";H.style.marginTop=-C.dimensions.height/2+"px";if(coherent.Browser.Safari){var E=new Image();E.onload=A;E.src=C.href}else{H.onload=function(){if(I){I.call(J)}};H.src=C.href}},selectedImage:function(){if(!this.images){return null}return this.images===null?null:this.images[this.selectedIndex]},getCaption:function(){var C=this.selectedImage();if(!C){return""}var B=C[this._mode];if(!B){return""}var A=B.caption||C.caption;if(null!==this.tourStop&&this.tourStop<(C.stops||[]).length){A=C.stops[this.tourStop].caption}return A},showImage:function(D,E,G){var A=this;if(!this.imageTags){return }var B=(A._imageIndex?0:1);var F=A._imageIndex;E=E||this._mode;function C(){var H=A.wrappers(F);var J=A.wrappers(B);A._imageIndex=B;A.setValueForKey(null,"tourStop");A.setValueForKey(D,"selectedIndex");H.style.zIndex=0;J.style.zIndex=1;function I(L){Element.setOpacity(H,0);if(G){G()}}if(MODE_GALLERY===E){var K=this.selectedImage();if(K[E].href===K[MODE_ZOOMED].href){J.style.cursor="default"}else{J.style.cursor=""}H.style.cursor=""}coherent.EventLoop.begin();coherent.Animator.setStyles(J,{opacity:1},{duration:(MODE_INLINE===A._mode?100:400),callback:I})}this.loadAlternateImage(D,E,C)},panImage:function(B,E){var D=this.imageTags(this._imageIndex);var A=this;function C(){A._focusPoint=B;if(E){E()}}coherent.EventLoop.begin();coherent.Animator.setStyles(D,{marginTop:-B.top,marginLeft:-B.left},{duration:1000,curve:coherent.easing.inOutSine,callback:C})},setMode:function(X,R,F){var P=this;var S=this.viewElement();if(this.locked){return }if(X==this._mode){Q();return }function B(){if(!S){return }var Y=S.parentNode;if(!Y){return }Y.style.display="none";var Z=Y.offsetLeft;Y.style.display="";document.getElementById("productDetails").style.position="relative"}function Q(){P.setValueForKey(false,"locked");P._futureMode=null;P.setValueForKey(X,"_mode");if(coherent.Browser.Safari2||coherent.Browser.IE){B.delay(10)}if(F){F.call(P)}}function V(){var Y=P.wrappers(E);var Z=P.wrappers(D);var a=P.imageTags(D);P._imageIndex=D;P._focusPoint=R;a.style.marginLeft=-R.left+"px";a.style.marginTop=-R.top+"px";Y.style.zIndex=0;Z.style.zIndex=1;if(MODE_GALLERY===X){var b=P.selectedImage();if(b[X].href===b[MODE_ZOOMED].href){Z.style.cursor="default"}else{Z.style.cursor=""}Y.style.cursor=""}Element.setOpacity(Z,0);coherent.EventLoop.begin();coherent.Animator.setStyles(Z,{opacity:{value:1,callback:function(){Element.setOpacity(Y,0)}}},{duration:250,callback:Q})}var A=500;var N=V.sync();var L=N.waitFor("image");var O=N.waitFor("mode");var M=this._mode;var J=this.selectedImage();if(!J[X]){return }var K=J[M].dimensions;var C=J[X].dimensions;var H=true;var T=true;var D=(P._imageIndex?0:1);var E=P._imageIndex;var I={corner:coherent.Animator.IGNORE_NODE};function W(e,f,Y){var a=false;var d=document.getElementById("product-details-form");if(d){var c=d.offsetHeight;var Z,b;if(MODE_INLINE===X){Z=parseInt(f[S.id]["height"],10);b=parseInt(f[e.id]["height"],10)}else{Z=parseInt(Y[S.id]["height"],10);b=parseInt(Y[e.id]["height"],10)}if((Z-c)<b){a=true}}if(a){if(MODE_INLINE===X){return coherent.Animator.FADE_IN_NODE}else{return coherent.Animator.FADE_OUT_NODE}}else{return coherent.Animator.FADE_NODE}}if(MODE_INLINE===this._mode||MODE_INLINE===X){I[this.controller().id]=coherent.Animator.FADE_NODE;if(this.product_rating()){I[this.product_rating().id]=W}}else{I[this.controller().id]=coherent.Animator.IGNORE_NODE;if(this.product_rating()){I[this.product_rating().id]=coherent.Animator.IGNORE_NODE}}if(MODE_ZOOMED===X&&R){R={left:Math.round(R.left*C.width/K.width),top:Math.round(R.top*C.height/K.height)}}else{if(!R){R={left:C.width/2,top:C.height/2}}}if(MODE_ZOOMED===X||MODE_TOUR===X){var U=Element.getDimensions(this.wrappers(D));var G=J[X].bounds;if(G){R.left=Math.clamp(R.left,G.left,G.right);R.top=Math.clamp(R.top,G.top,G.bottom)}if(C.width<U.width){R.left=C.width/2}else{R.left=Math.clamp(R.left,U.width/2,C.width-U.width/2)}if(C.height<U.height){R.top=C.height/2}else{R.top=Math.clamp(R.top,U.height/2,C.height-U.height/2)}}I[this.media().id]=coherent.Animator.MORPH_NODE;I[this.wrappers(E).id]=coherent.Animator.MORPH_NODE;I[this.imageTags(E).id]=coherent.Animator.IGNORE_NODE;I[this.imageTags(D).id]=coherent.Animator.IGNORE_NODE;if(MODE_ZOOMED===this._mode&&MODE_GALLERY===X){A=300}this.setValueForKeyPath(true,"locked");this._futureMode=X;this.loadAlternateImage(this.selectedIndex,X,L);Element.makeClipping(this.imageTags(E));coherent.EventLoop.begin();coherent.Animator.replaceClassName(S,ModeStyles[this._mode],ModeStyles[X],{duration:A,callback:O,curve:coherent.easing.inOutSine,actions:I,only:["top","left","width","height","display","opacity"]});coherent.Animator.setStyles(this.imageTags(E),{width:C.width,height:C.height,marginTop:-R.top,marginLeft:-R.left},{duration:A,curve:coherent.easing.inOutSine,callback:function(){Element.undoClipping(this.imageTags(E))}.bind(this)})},endTour:function(A){},beginTour:function(E,C){if(MODE_GALLERY!=this._mode){this.setMode(MODE_GALLERY,null,this.beginTour.bind(this,E,true));return }if("undefined"!==typeof (E)&&E!=this.selectedIndex){this.showImage(E,MODE_GALLERY,this.beginTour.bind(this,E));return }var N=this;var K=this.viewElement();var L=N.images.length;var I=false;var P=false;var B;var J;var M;E=E||this.selectedIndex;Element.addClassName(K,N.playingClass);N.endTour=G;N.setValueForKey(true,"playing");function A(){var R=N.selectedImage();var Q=R.gallery.dimensions;N._focusPoint={left:Q.width/2,top:Q.height/2};M=R.stops||[];J=null;N.setValueForKey(J,"tourStop");if(C){H.delay(N.tourStopDuration)}else{H()}C=true}function O(){if(I){F();return }H.delay(N.tourStopDuration)}function H(){if(I){F();return }if(null===J){J=0}else{J++}N.setValueForKey(J,"tourStop");if(!M.length||J>=M.length){N.setMode(MODE_GALLERY,null,D);return }var Q={left:M[J].left,top:M[J].top};if(!J){N.setMode(MODE_TOUR,Q,O)}else{N.panImage(Q,O)}}function D(){var Q=(N.selectedIndex+1)%L;if(I||Q===E){N.showImage(Q,MODE_GALLERY,F)}else{N.showImage(Q,MODE_GALLERY,A)}}function F(){Element.removeClassName(K,N.playingClass);N.setValueForKey(null,"tourStop");N.setValueForKey(false,"playing");N.setMode(MODE_GALLERY,null,B)}function G(Q){I=true;B=Q;Element.removeClassName(K,N.playingClass);N.setValueForKey(null,"tourStop");N.setValueForKey(false,"playing")}A()},thumbnailClicked:function(B,C){Event.stop(C);if(this.locked){return }if(this.playing){this.reportEvent(this.microevents.TourStopped)}var A=this.selectedIndex;switch(this._mode){case MODE_INLINE:this.reportEvent(this.microevents.GalleryDisplayed);this.showImage(A,null,this.setMode.bind(this,MODE_GALLERY));break;case MODE_GALLERY:if(this.playing){this.endTour(this.showImage.bind(this,A))}else{this.showImage(A)}break;case MODE_ZOOMED:this.setMode(MODE_GALLERY,null,this.showImage.bind(this,A));break;case MODE_TOUR:this.endTour(this.showImage.bind(this,A));break;default:break}},_updateViewport:function(E,A){var B=A.node;var D=A.focusPoint.left-A.delta.left;var C=A.focusPoint.top-A.delta.top;if(A.minFocusPoint.left>A.maxFocusPoint.left){D=A.maxFocusPoint.left+(A.minFocusPoint.left-A.maxFocusPoint.left)/2}else{D=Math.clamp(D,A.minFocusPoint.left,A.maxFocusPoint.left)}if(A.minFocusPoint.top>A.maxFocusPoint.top){C=A.maxFocusPoint.top+(A.minFocusPoint.top-A.maxFocusPoint.top)/2}else{C=Math.clamp(C,A.minFocusPoint.top,A.maxFocusPoint.top)}this._focusPoint={left:D,top:C};B.style.marginLeft=-D+"px";B.style.marginTop=-C+"px"},mediaMouseDown:function(C){Event.stop(C);if(this.locked){return }if(MODE_ZOOMED!==this._mode){return }var D=this.imageTags(this._imageIndex);var E=this.wrappers(this._imageIndex);var A=Element.getDimensions(E);var B={update:this._updateViewport.bind(this),focusPoint:this._focusPoint,minFocusPoint:{left:A.width/2,top:A.height/2},maxFocusPoint:{left:D.width-A.width/2,top:D.height-A.height/2}};this.trackMouse(D,C,B)},mediaClicked:function(C){Event.stop(C);if(this.locked){return }var B;var D;var A;switch(this._mode){case MODE_INLINE:this.reportEvent(this.microevents.GalleryDisplayed);this.setMode(MODE_GALLERY);break;case MODE_GALLERY:var E=this.selectedImage();if(E[MODE_GALLERY].href===E[MODE_ZOOMED].href){break}A=this.imageTags(this._imageIndex);B=Element.getRect(A);D={left:Math.clamp(C.clientX-B.left,0,A.width),top:Math.clamp(C.clientY-B.top,0,A.height)};this.setMode(MODE_ZOOMED,D);break;case MODE_ZOOMED:this.setMode(MODE_GALLERY);break;default:break}},galleryLinkClicked:function(A){Event.stop(A);if(this.locked){return }this.reportEvent(this.microevents.GalleryDisplayed);this.setMode(MODE_GALLERY)},playButtonClicked:function(A){Event.stop(A);if(this.locked){return }this.playButton().blur();if(this.playing){this.reportEvent(this.microevents.TourStopped);this.endTour()}else{this.reportEvent(this.microevents.TourStarted);this.beginTour()}},closeButtonClicked:function(A){Event.stop(A);if(this.locked){return }if(this.playing){this.reportEvent(this.microevents.TourStopped);this.endTour(this.setMode.bind(this,MODE_INLINE));return }this.setMode(MODE_INLINE)},mouseEnterThumbnail:function(C){var D=C.target||C.srcElement;while(D.nodeName!="LI"&&D.parentNode){D=D.parentNode}if(MODE_INLINE===this._mode&&!this.locked){var B=Element.queryAll(this.viewElement(),"ul.thumbnails li");var A=Array.indexOf(B,D);if(A>=0){this.showImage(A)}}},mouseExitThumbnail:function(){},reportEvent:function(C){if(!this._triggeredActions){this._triggeredActions={}}if(C in this._triggeredActions){return }this._triggeredActions[C]=true;var D={index:this.selectedIndex,action:C};var B=apple.util.expandTemplate(this._metricsTemplate,D);var A=this.viewElement();if("metrics" in apple&&"Metrics" in apple.metrics){apple.metrics.Metrics.reportCustomLink(A,B)}},_hoverMouseOver:function(E){var G=E.target||E.srcElement;var C=this._hoverCache;if(!G||!C||!C.count){return }var A=document.body;while(G&&G!=A&&!(G.id&&G.id in C)){G=G.parentNode}if(!G||G==A){return }var B=this._hoverCache[G.id];if(!B.mouseEnter||B.containsPointer){return }var D=B.delay;if(!D){B.containsPointer=true;B.mouseEnter.call(this,G,E)}else{function F(H){B.containsPointer=true;B.mouseEnter.call(this,G,E);B._delayTimer=0}B._delayTimer=window.setTimeout(F.bind(this),D)}},_hoverMouseOut:function(D){var E=D.target||D.srcElement;var C=this._hoverCache;if(!E||!C||!C.count){return }var A=document.body;while(E&&E!=A&&!(E.id&&E.id in C)){E=E.parentNode}if(!E||E==A){return }var B=this._hoverCache[E.id];if(!B.mouseExit){return }var F=D.relatedTarget||D.toElement;while(F&&F!=E&&F!=A){F=F.parentNode}if(F==E){return }B.containsPointer=false;if(!B.delay||!B._delayTimer){B.mouseExit.call(this,E,D)}else{window.clearTimeout(B._delayTimer);B._delayTimer=0}},trackHover:function(F,G){F=document.getElementById(F);if(F._trackHover){return }F._trackHover=true;var E=Element.assignId(F);var B=this._hoverCache;if(!B){B=this._hoverCache={};B.count=0;var D=this._hoverMouseOver.bindAsEventListener(this);var A=this._hoverMouseOut.bindAsEventListener(this);var C=this.viewElement();Event.observe(C,"mouseover",D);Event.observe(C,"mouseout",A)}B[E]=G;B.count++},stopTrackingHover:function(B){B=document.getElementById(B);if(!B._trackHover){return }B._trackHover=false;var A=this._hoverCache;if(!A){return }delete A[B.id];A.count--},_trackingMouseUp:function(B,A){Event.stop(B);A._lastPos={left:B.clientX,top:B.clientY};A._updateHandler(B);this.endTrackingMouse(A)},_trackingMouseMoved:function(B,A){A._lastPos={left:B.clientX,top:B.clientY};A._moveTimeout=A._moveTimeout||window.setTimeout(A._updateHandler,10);Event.stop(B)},_trackingUpdatePosition:function(B,A){var C={left:A._lastPos.left-A.origin.left,top:A._lastPos.top-A.origin.top};A.delta={left:C.left-A.startPos.left,top:C.top-A.startPos.top};if(!A.isDrag&&(5<Math.abs(A.delta.left)||5<Math.abs(A.delta.top))){A.isDrag=true;this._createTrackingGuardDiv(A)}A.update(C,A);A._moveTimeout=0},_createTrackingGuardDiv:function(A){var B=document.createElement("DIV");B.className="mouse-tracking-guard";B.style.position="absolute";B.style.left="0";B.style.top="0";B.style.width="100%";B.style.height="100%";B.style.zIndex="9999";if(coherent.Browser.IE){B.style.background="white";B.style.filter="alpha(opacity=1)";B.style.setExpression("height","parentNode.scrollHeight");B.setCapture(true)}B.onmouseup=function(C){C=C||window.event;B.onmouseup=null;B.parentNode.removeChild(B);if(coherent.Browser.IE){B.releaseCapture()}A._mouseUpHandler(C);Event.stop(C);return false};document.body.appendChild(B)},endTrackingMouse:function(A){Event.stopObserving(document,"mouseup",A._mouseUpHandler);Event.stopObserving(document,"mousemove",A._mouseMoveHandler);A.finish(A)},trackMouse:function(C,B,A){var E=Element.getRect(C,true);A=A||{};var D={node:C,update:function(){},finish:function(){},origin:{left:E.left-document.body.scrollLeft-document.documentElement.scrollLeft,top:E.top-document.body.scrollTop-document.documentElement.scrollTop},_lastPos:{left:B.clientX,top:B.clientY},_updateHandler:this._trackingUpdatePosition.bindAsEventListener(this,A),_mouseMoveHandler:this._trackingMouseMoved.bindAsEventListener(this,A),_mouseUpHandler:this._trackingMouseUp.bindAsEventListener(this,A)};D.startPos={left:D._lastPos.left-D.origin.left,top:D._lastPos.top-D.origin.top};Object.applyDefaults(A,D);Event.observe(document,"mousemove",A._mouseMoveHandler);Event.observe(document,"mouseup",A._mouseUpHandler);Event.stop(B);return A}});Package("apple.widget");apple.widget.ProductVariationsGroup=Class.create(coherent.View,{exposedBindings:["content","value","locked","maximum"],keyDependencies:{value:["content"],selection:["content"]},__structure__:{legend:coherent.View({textBinding:"content.name"}),select:coherent.SelectField({nameBinding:"content.key",enabledBinding:"showSelect",visibleBinding:"showSelect",contentBinding:"content.values",displayValuesBinding:"content.values.label",contentValuesBinding:"content.values.value",selectedObjectBinding:"selectedObject"}),div:coherent.ListView({visibleBinding:"showSelect(NOT)",contentBinding:"content.values"}),input:coherent.ToggleButton({nameBinding:"content.key",selectionBinding:"value",valueBinding:"*.value"}),"label span.swatch img":coherent.ImageView({nullPlaceholder:"/rs/img/block1px.gif",srcBinding:"*.imageUrl",altBinding:"*.label",widthBinding:"*.width",heightBinding:"*.height"}),"label span.swatch":coherent.View({visibleBinding:"*.imageUrl"}),"label span.label":coherent.View({htmlBinding:"*.label",visibleBinding:"*.imageUrl(NOT)"})},constructor:function(E,C,D){this.base(E,C,D);this.showSelect=false;this._content=new coherent.KVO();var A=Element.query(this.viewElement(),"select");if(A&&A.options.length){this._content.limit=A.options.length}if(coherent.Browser.IE){var F=document.createElement("div");F.className="shim";var B=this.viewElement().parentNode;B.parentNode.insertBefore(F,B)}},init:function(){if(this.bindings.content&&!this.bindings.content.hasValue()){this.bindings.content.setValue(this._content)}if(this.bindings.value&&!this.bindings.value.hasValue()){this.bindings.value.setValue(this._value)}},getContent:function(){return this._content},setContent:function(C){this._content=C;if(this.bindings.content){this.bindings.content.setValue(this._content)}if(!C||!C.values){return }var B=this.viewElement();var A=C.limit||this._content.limit||0;if(A){this.setValueForKey(C.values.length>=A,"showSelect")}else{this.setValueForKey(false,"showSelect")}if(coherent.Browser.IE){(function(){Array.forEach(Element.queryAll(this.viewElement(),"input"),function(D){D.parentNode.htmlFor=D.id});Array.forEach(Element.queryAll(this.viewElement(),"img"),function(D){D.onclick=function(){this.parentNode.click()}})}).bindAndDelay(this,10)}},getValue:function(){return this._value},setValue:function(D){this.forceChangeNotificationForKey("selectedObject");if(this._value===D){return }this._value=D;if(this.bindings.value){this.bindings.value.setValue(D)}if(!D||!this._content||!this._content.values){return }var A=this._content.values.length;var C;for(var B=0;B<A;B++){if(this._content.values[B].value==D){C=this._content.values[B];break}}this.setSelection(C)},getSelection:function(){return this._selection},setSelection:function(A){if(this._selection===A){return }this._selection=A;var B=A?A.value:"";this.setValue(B)},getSelectedObject:function(){if(!this._content||!this._content.values){return null}var A=this._content.values.length;var C;for(var B=0;B<A;B++){if(this._content.values[B].value==this._value){return this._content.values[B]}}return null},setSelectedObject:function(A){this._selectedObject=A;if(A){this.setValueForKey(A.value,"value")}}});Package("apple.widget");apple.widget.ProductDetailsViewController=Class.create(coherent.ViewController,{exposedBindings:["reviews"],detailsGallery:apple.widget.ProductDetailsGallery("#productInfo",{imagesBinding:"gallery.images",metricsTemplateBinding:"gallery.metrics",lockedBinding:"locked"}),__structure__:{"#productInfo h2":apple.widget.AnimatedTextWidget({htmlBinding:"title"}),"#productInfo div.product-rating":apple.widget.AnimatedTextWidget({htmlBinding:"rating"}),"#price":apple.widget.AnimatedTextWidget({htmlBinding:"price"}),"#shipping":apple.widget.AnimatedTextWidget({htmlBinding:"availability"}),"#productPartNumber":coherent.TextField({valueBinding:"partNumber"}),"fieldset.product-variations-1":apple.widget.ProductVariationsGroup({contentBinding:"variations.variant_1",valueBinding:"selection.variant_1",lockedBinding:"locked"}),"fieldset.product-variations-2":apple.widget.ProductVariationsGroup({contentBinding:"variations.variant_2",valueBinding:"selection.variant_2",lockedBinding:"locked"}),"div.purchase-actions":coherent.View({visibleBinding:"showBuyButton",animated:true}),"p.gifting-checkbox-label":coherent.View({visibleBinding:"isGiftable",animated:true})},part:null,variationChangeURL:null,variationMetrics:null,metricsContext:null,showBuyButton:true,isGiftable:false,reviews:null,locked:false,saveButton:coherent.View("#save-cart-btn",{visibleBinding:"showBuyButton",animated:true}),constructor:function(B,A){if(document.getElementById("product-details-form")){document.getElementById("product-details-form").reset()}this.base(B,A);this.variations=new coherent.KVO();this.selection=new coherent.KVO();if(Element.query("div.purchase-actions")){this.showBuyButton=(Element.query("div.purchase-actions").style.display!=="none")}if(Element.query("p.gifting-checkbox-label")){this.isGiftable=(Element.query("p.gifting-checkbox-label").style.display!=="none")}},init:function(){this.registerWithName("productDetails");this.addObserverForKeyPath(this,this.performQuery,"selection.variant_1","variant_1");this.addObserverForKeyPath(this,this.performQuery,"selection.variant_2","variant_2");this.addObserverForKeyPath(this,this.lockedChange,"locked");this.addObserverForKeyPath(this,this.observeSaveItemUrlChange,"saveItemUrl")},lockedChange:function(C,B,A){if(C.newValue===false&&this.deferQuery){this.performQuery(null,null,this.deferQuery)}},performQuery:function(J,K,A){if(this.locked){this.deferQuery=A;return }this.deferQuery=null;if(this._updatingAfterQuery||(this.variationChangeURL===null)){return }var M=this.valueForKey("variations");var D=M.mutableKeys();var G=D.length;var L;var B=this.valueForKey("partNumber");var H={};if(this.extraArgs){Object.applyDefaults(H,this.extraArgs)}for(var E=0;E<G;++E){L=this.valueForKeyPath("variations."+D[E]+".key");H[L]=this.valueForKeyPath("selection."+D[E])}if(this.metricsContext){H.metricsContext=this.metricsContext}if(!B){return }if(this._query){this._query.cancel()}if(this.variationChangeURL.indexOf("?")!=-1){this.variationChangeURL=this.variationChangeURL.replace(/\?.*$/,"")}var C={url:this.variationChangeURL+"/"+B,urlArgs:H,success:this.querySucceeded.bind(this),error:this.queryFailed.bind(this)};this._query=apple.io.json.invoke(C);var I=this.valueForKeyPath("variations."+A+".key").replace(/.*\./,"");var F=this.valueForKeyPath("selection."+A);this.reportEvent(I,F)},querySucceeded:function(E){this._updatingAfterQuery=true;this._query=null;var A=E.body;if(!A){return }var C,B;for(var F in A){var D=A[F];var G=coherent.typeOf(D);if("function"===G){continue}if(!(G in coherent.KVO.typesOfKeyValuesToIgnore)){D=coherent.KVO.adaptTree(D)}if(F=="selection"){C=D;continue}if(F=="reviews"){B=D;continue}this.setValueForKey(D,F)}if(C){this.setValueForKey(C,"selection")}if(B){B=coherent.Scripts.extract(B);this.setValueForKey(B.toString(),"reviews");coherent.Scripts.install.delay(500,B.scripts)}this.showOrHideProductRating.bindAndDelay(this,300);this._updatingAfterQuery=false},queryFailed:function(A){this._query=null},showOrHideProductRating:function(){if(this.detailsGallery._mode===MODE_INLINE){return }var C=false;var A=Element.query(".product-rating");if(!A){return }var F=document.getElementById("product-details-form");if(F){var E=F.offsetHeight;var B=parseInt(Element.getStyle(this.detailsGallery.viewElement(),"height"),10);var D=parseInt(Element.getStyle(A,"height"),10);if((B-E)<D){C=true}}if(C){coherent.Animator.setStyles(A,{opacity:0},{duration:200})}else{coherent.Animator.setStyles(A,{opacity:1},{duration:200})}},reportEvent:function(B,A){if(!this.variationMetrics){return }if(!this._triggeredActions){this._triggeredActions={}}if(B in this._triggeredActions){return }this._triggeredActions[B]=true;var C=apple.util.expandTemplate(this.variationMetrics,{type:B,index:A});try{apple.metrics.Metrics.reportCustomLink(this.viewElement(),C)}catch(D){}},itemSaved:function(){if(!this.overlay){this.overlay=new coherent.Overlay(this.overlayId);this.overlay.setNextResponder(this)}if(!this.overlay||!this.itemSavedOverlayUrl){return }this.overlay.display({classname:"overlay",displayCloseWidget:false,url:this.itemSavedOverlayUrl})},observeSaveItemUrlChange:function(){if(this.saveItemUrl){this.saveButton.action=this.saveItem.bind(this)}else{this.saveButton.action=null}},saveItem:function(){var C=String(this.saveItemUrl).split("?");var B={};if(C.length>1){B=Object.fromQueryString(C[1])}B.product=Element.query("#product-details-form input[name='product']").value;var A=JSONRPC.post(C[0],B);apple.metrics.fireEvent({events:"event10"});A.addCallback(this.itemSaved.bind(this))}});