(function(){var B=YAHOO.lang,E=YAHOO.util.Dom,F=YAHOO.util.Event,C=ZC.Util;var A=function(){var H=this.UniqueID();var J=E.get("carousel-"+H);this.bDragging=false;this.iCursorX;this.iCarouselPosition=0;this.iCarouselStart;this.iLastActionAt;this.iLastTickAt;this.iSpeed;this.iTickRate=50;this.fDecelerationRate=0;this.fFriction=0.2;this.iCarouselTotalWidth;this.iVisibleItems;this.oCarouselTimer;this.aListItems;this.sImageFolder;this.iItemWidth;this.iImageWidth;this.iImageHeight;this.iDistanceMoved;this.bOldIE=false;if(YAHOO.env.ua.ie&&YAHOO.env.ua.ie<=6){return false}this.elList=J.getElementsByTagName("ul")[0];F.addListener(this.elList,"mousedown",this.startDragMouse,this,true);F.addListener(this.elList,"touchstart",this.startDragTouch,this,true);F.addListener(document,"mouseup",this.stopDrag,this,true);F.addListener(document,"touchend",this.stopDrag,this,true);this.left=J.getElementsByTagName("a")[0];this.right=J.getElementsByTagName("a")[J.getElementsByTagName("a").length-1];F.addListener(this.left,"click",this.moveLeft,this,true);F.addListener(this.right,"click",this.moveRight,this,true);this.iCarouselWidth=(this.right.offsetLeft)-(this.left.offsetLeft+this.left.offsetWidth)-2*(this.elList.offsetLeft-this.left.offsetWidth);this.elList.style.width=this.iCarouselWidth+"px";this.iCarouselWidth=this.elList.offsetWidth;this.iCarouselHeight=this.elList.offsetHeight;this.elList.style.whiteSpace="nowrap";this.elList.style.clip="rect(0,"+this.iCarouselWidth+"px,"+this.iCarouselHeight+"px,0)";this.elList.style.width="auto";this.elList.style.overflow="visible";this.iCarouselStart=this.elList.offsetLeft;this.iCarouselTotalWidth=this.elList.offsetWidth;this.left.style.visibility="visible";this.right.style.visibility="visible";this.iItemWidth=this.elList.getElementsByTagName("li")[0].offsetWidth;this.iVisibleItems=parseInt((this.iCarouselWidth/this.iItemWidth),10);this.iImageWidth=this.elList.getElementsByTagName("img")[0].width;this.iImageHeight=this.elList.getElementsByTagName("img")[0].height;this.aListItems=this.GetAttrib("items");this.sImageFolder=this.GetAttrib("imagefolder");this.aItemsToKeep=[];for(var G=0;G<this.elList.getElementsByTagName("li").length;G++){if(G<this.iVisibleItems*2){this.aItemsToKeep[G]=this.elList.getElementsByTagName("li")[G]}}while(this.elList.childNodes.length>0){this.elList.removeChild(this.elList.firstChild)}for(var G in this.aItemsToKeep){var I=this.aItemsToKeep[G].getElementsByTagName("a");if(I.length!=0){F.addListener(this.aItemsToKeep[G],"mouseup",this.clickItem,{obj:this,target:I[0].href},true);F.addListener(this.aItemsToKeep[G],"touchend",this.clickItem,{obj:this,target:I[0].href},true);I[0].removeAttribute("href")}this.elList.appendChild(this.aItemsToKeep[G])}if(YAHOO.env.ua.ie){F.on(this.elList,"dragstart",function(K){F.stopEvent(K)});if(YAHOO.env.ua.ie<=7){this.bOldIE=true}}return true};var D=ZC.Core.Block.Create("CrashRepairParts_Carousel","Imperial");D.prototype.CustomSetupEnd=A;D.prototype.getAutoRotateSpeed=function(){var G=[0,20,31.5,40.8,49.6];if(this.iVisibleItems<4){return G[this.iVisibleItems]}else{return 40.8}};D.prototype._startDrag=function(H){this.iDistanceMoved=0;if(H.preventDefault){H.preventDefault()}this.iSpeed=0;if(this.oCarouselTimer!=null){this.oCarouselTimer.cancel()}this.fDecelerationRate=0;this.bDragging=true;if(H.pageX){this.iCursorX=H.pageX}else{if(H.touches){this.iCursorX=H.touches[0].pageX}else{this.iCursorX=H.clientX+document.documentElement.scrollTop}}var G=new Date();this.iLastActionAt=G.getTime()};D.prototype.startDragMouse=function(G){F.stopEvent(G);F.addListener(this.elList,"mousemove",this.mouseMoving,this,true);F.addListener(this.elList,"mouseclick",void (0),this,true);this._startDrag(G)};D.prototype.startDragTouch=function(G){F.stopEvent(G);F.addListener(this.elList,"mousemove",this.mouseMoving,this,true);F.addListener(this.elList,"touchmove",this.mouseMoving,this,true);F.removeListener(this.elList,"mousedown",this.startDragMouse);F.removeListener(this.elList,"mousemove",this.mouseMoving);F.removeListener(this.elList,"mouseup",this.stopDrag);this._startDrag(G)};D.prototype.mouseMoving=function(J){if(!this.bDragging){return }if(J.pageX){var K=J.pageX-this.iCursorX}else{if(J.touches){var K=J.touches[0].pageX-this.iCursorX}else{var K=J.clientX+document.documentElement.scrollTop-this.iCursorX}}this.iCarouselPosition=(this.elList.offsetLeft+K);this._setPosition(this.iCarouselPosition);var I=new Date();var H=I.getTime();var G=H-this.iLastActionAt;if(K){this.iSpeed=parseInt((K/G)*this.iTickRate,10);this.iDistanceMoved+=Math.abs(K)}this.iCursorX=this.iCursorX+K};D.prototype.stopDrag=function(H){this.bDragging=false;F.removeListener(this.elList,"mousemove",this.mouseMoving);var G=new Date();this.iLastTickAt=G.getTime();this.oCarouselTimer=B.later(this.iTickRate,this,this.continueSlide,"",false)};D.prototype.continueSlide=function(){var H=new Date();var I=H.getTime()-this.iLastTickAt;var G=Math.round(I/this.iTickRate,10);while(G>0){G--;this.fDecelerationRate+=this.fFriction}if(this.iSpeed>0){this.iSpeed-=Math.min(this.fDecelerationRate,this.iSpeed)}else{if(this.iSpeed<0){this.iSpeed+=Math.min(this.fDecelerationRate,Math.abs(this.iSpeed))}}this.iCarouselPosition=(this.elList.offsetLeft+this.iSpeed);if(!this._setPosition(this.iCarouselPosition)){this.oCarouselTimer.cancel();return }if(Math.abs(this.iSpeed)<0.1||this.iSpeed==undefined){this.oCarouselTimer.cancel();return }this.iLastTickAt=H.getTime();this.oCarouselTimer=B.later(this.iTickRate,this,this.continueSlide,"",false)};D.prototype._setPosition=function(G){if(G<this.elList.offsetLeft){var H=this.elList.getElementsByTagName("li")[this.elList.getElementsByTagName("li").length-1];if(this.bOldIE){var I=(H.offsetLeft+H.offsetParent.offsetLeft)+700-this.iCarouselWidth}else{var I=H.offsetLeft+this.elList.offsetLeft-this.iCarouselWidth}while((I<this.iItemWidth)||(this.bOldIE&&(I-(2*this.iItemWidth)<this.iItemWidth))){if(this.extendRight()){G+=this.iItemWidth}I+=this.iItemWidth}}else{if(G>this.elList.offsetLeft){var I=this.elList.offsetLeft;while((!this.bOldIE&&(I>-this.iItemWidth))||(this.bOldIE&&(I>this.iItemWidth))){this.extendLeft();G-=this.iItemWidth;I-=this.iItemWidth}}}if(isNaN(G)){return false}this.elList.style.left=G+"px";this.elList.style.clip="rect(0,"+((this.iCarouselStart-G)+this.iCarouselWidth)+"px,"+this.iCarouselHeight+"px,"+(this.iCarouselStart-G)+"px)";return true};D.prototype.moveLeft=function(){this.fDecelerationRate=0;this.iSpeed=this.getAutoRotateSpeed();if(this.oCarouselTimer!=null){this.oCarouselTimer.cancel()}this.oCarouselTimer=B.later(this.iTickRate,this,this.continueSlide,"",false)};D.prototype.moveRight=function(){this.fDecelerationRate=0;this.iSpeed=this.getAutoRotateSpeed()*-1;if(this.oCarouselTimer!=null){this.oCarouselTimer.cancel()}this.oCarouselTimer=B.later(this.iTickRate,this,this.continueSlide,"",false)};D.prototype.extendRight=function(){var H=this.elList.getElementsByTagName("li");var G=E.getElementsByClassName("title","span",H[H.length-1])[0].firstChild.nodeValue;var I=false;var J;for(i in this.aListItems){if(I){J=this.aListItems[i];break}else{if(this.aListItems[i].title==G){I=true}}}if(J==null){J=this.aListItems[0]}this.elList.appendChild(this.createNewItem(J));if(this.elList.getElementsByTagName("li").length>this.iVisibleItems*2){this.elList.removeChild(this.elList.getElementsByTagName("li")[0]);return true}return false};D.prototype.extendLeft=function(){var G=E.getElementsByClassName("title","span",this.elList.getElementsByTagName("li")[0])[0].firstChild.nodeValue;var H;for(i in this.aListItems){if(this.aListItems[i].title==G){break}else{H=this.aListItems[i]}}if(H==undefined){H=this.aListItems[this.aListItems.length-1]}this.elList.insertBefore(this.createNewItem(H),this.elList.getElementsByTagName("li")[0]);if(this.elList.getElementsByTagName("li").length>this.iVisibleItems*2){this.elList.removeChild(this.elList.getElementsByTagName("li")[this.elList.getElementsByTagName("li").length-1]);return true}return false};D.prototype.createNewItem=function(M){var J=document.createElement("li");var I=document.createElement("span");I.setAttribute("class","title");I.appendChild(document.createTextNode(M.title));var K=document.createElement("span");K.setAttribute("class","carousel-item");var H=document.createElement("img");H.width=this.iImageWidth;H.height=this.iImageHeight;H.src=this.sImageFolder+"/"+M.image;var L=E.get("carousel-"+this.UniqueID());if(L.parentNode.id=="mini-carousel"){var G=document.createElement("p");G.setAttribute("class","more");G.appendChild(document.createTextNode("More"));J.appendChild(I);K.appendChild(H);J.appendChild(K);J.appendChild(G)}else{K.appendChild(H);J.appendChild(K);J.appendChild(I)}F.addListener(J,"mouseup",this.clickItem,{obj:this,target:M.target},true);F.addListener(J,"touchend",this.clickItem,{obj:this,target:M.target},true);return J};D.prototype.clickItem=function(G,H){F.preventDefault(G);if(H.obj.iDistanceMoved>10){return false}if(H.target!=undefined){window.location=H.target}}})();
