var colors=new Class({zoomLevel:1,currentColorIdx:null,currentAngleIdx:null,zoomState:false,imgZoomDim:[{'width':980,'height':437},{'width':1470,'height':656},{'width':2940,'height':1311}],directionList:['navLinkFrontRight','navLinkRight','navLinkBackRight','navLinkTop','navLinkBackLeft','navLinkLeft','navLinkFrontLeft','navLinkFront'],Implements:Options,initialize:function(jsonUrl){this.currentLocale=currentLocale;document.addEvent('keydown',this.keyboardListener.bind(this));this.result=new Request.JSON({url:jsonUrl,method:'get',onSuccess:function(jsonObj){this.jsonData=jsonObj;this.prepare();}.bind(this),onFailure:function(xhr){alert("There was difficulty in retrieving the color data.\n"+"transport.readyState = "+xhr.readyState+" / transport.status "+xhr.status);}.bind(this)});this.result.headers.extend({'Accept':'*/*'});this.result.send("json=true");},dragMouseDown:function(){this.setStyle('cursor','url(/_media/images/common/closedhand.cur), move');},dragMouseUp:function(){this.setStyle('cursor','url(/_media/images/common/openhand.cur), move');},keyboardListener:function(event){switch(event.key){case'up':this.zoomIn();return false;case'down':this.zoomOut();return false;default:return true;}},prepare:function(){this.currentAngleIdx=0;this.currentColorIdx=this.jsonData.colors.length-1;this.jsonData.colors.reverse();this.setCurrentColorDisplay(this.currentColorIdx);$$('#zoomControls .plus').addEvent('click',function(){this.zoomIn();return false;}.bind(this));$$('#zoomControls .minus').addEvent('click',function(){this.zoomOut();return false;}.bind(this));$$('#resetButton a').addEvent('click',function(){window.location.replace(unescape(window.location.pathname));return false;});$('topBufferImg').set('tween',{duration:500,transition:Fx.Transitions.linear});this.directionList.each(function(viewId,idx){$(viewId).set({'events':{'mouseover':function(){$('nav360').setStyle('background-position','0px '+(-51*(idx+1))+'px');},'mouseout':function(){$('nav360').setStyle('background-position','');},'click':function(){this.setCurrentAngleDisplay(idx);return false;}.bind(this)}});}.bind(this));$('nav360').set('class',this.directionList[this.currentAngleIdx]+'On');this.zoomSlider=new Slider('zoomControllerTrack','zoomLevel',{steps:3,snap:true,offset:0,mode:"vertical",onChange:function(pos){$('zoomLevel').set('class','x'+(3-pos.toInt()));}.bind(this),onComplete:function(pos){this.zoomFromTo(this.zoomLevel,3-pos.toInt());this.zoomLevel=3-pos.toInt();}.bind(this)}).set(2);if(Browser.Engine.trident5)document.ondragstart=function(){return false;};[0,1,2].each(function(i){new Element('a',{'styles':{'top':(i*16)+30},'class':'tierButton','html':'&nbsp;','events':{'click':function(){this.zoomSlider.set(i);return false;}.bind(this)}}).inject('zoomControls');}.bind(this))
$('dragRotator').set({'events':{'mousedown':function(e){e.preventDefault();this.mouseDown=true;$('dragRotator').setStyle('cursor','e-resize');this.mouseStartAngleOfsIdx=Math.floor((e.page.x/40)%8)-this.currentAngleIdx;}.bind(this),'mouseup':function(e){e.preventDefault();this.mouseDown=false;$('dragRotator').setStyle('cursor','url(/_media/images/common/openhand.cur), move');this.mouseStartAngleIdx=null;}.bind(this),'mouseout':function(e){e.preventDefault();this.mouseDown=false;$('dragRotator').setStyle('cursor','url(/_media/images/common/openhand.cur), move');this.mouseStartAngleIdx=null;}.bind(this),'mousemove':function(e){e.preventDefault();if(this.mouseDown){var angleIdx=Math.floor(((e.page.x+(this.mouseStartAngleOfsIdx*40))/40)%8);if(angleIdx!=this.currentAngleIdx){this.quickSetCurrentAngleDisplay(angleIdx);}}}.bindWithEvent(this)}}).setStyle('cursor','url(/_media/images/common/openhand.cur), move');},zoomFromTo:function(zoomLevelFrom,zoomLevelTo){if(zoomLevelFrom==zoomLevelTo)return;$('dragRotatorContainer').setStyle('display',(zoomLevelTo==1)?'block':'none');$('resetButton').setStyle('display',(zoomLevelTo!=1)?'block':'none');if(zoomLevelFrom==1){$('topBufferImg').makeDraggable({'container':$('zoomContainer')});$('topBufferImg').addEvents({'mousedown':this.dragMouseDown,'mouseup':this.dragMouseUp}).setStyle('cursor','url(/_media/images/common/openhand.cur), move');}
if(zoomLevelTo==1){$('topBufferImg').removeEvent('mousedown',this.dragMouseDown);$('topBufferImg').removeEvent('mouseup',this.dragMouseUp);$('topBufferImg').setStyle('cursor','default');}
zBase=this.imgZoomDim[0];zStart=this.imgZoomDim[zoomLevelFrom-1];zEnd=this.imgZoomDim[zoomLevelTo-1];var zoomBox={'heightStart':((zStart.height-zBase.height)*2)+zBase.height,'widthStart':((zStart.width-zBase.width)*2)+zBase.width,'heightEnd':((zEnd.height-zBase.height)*2)+zBase.height,'widthEnd':((zEnd.width-zBase.width)*2)+zBase.width};var zc=$('zoomContainer');var tb=$('topBufferImg');this.fxChain=new Chain();tb.set('morph',{duration:500,onComplete:function(){this.fxChain.callChain();}.bind(this)});this.fxChain.chain(function(){if(zoomLevelFrom==1){$('navbg').tween('bottom',[17,-83]);$('navColors').tween('bottom',[0,-100]);$('arrowLeft').tween('bottom',[17,-83]);}
this.fxChain.callChain();}.bind(this),function(){tb.morph({'top':(zoomBox.heightStart/2)-(zStart.height/2),'left':(zoomBox.widthStart/2)-(zStart.width/2)});}.bind(this),function(){zc.set({'styles':{'width':zoomBox.widthEnd,'height':zoomBox.heightEnd,'top':-((zoomBox.heightEnd/2)-(zBase.height/2)),'left':-((zoomBox.widthEnd/2)-(zBase.width/2))}});tb.set({'styles':{'top':(zoomBox.heightEnd/2)-(zStart.height/2),'left':(zoomBox.widthEnd/2)-(zStart.width/2)}}).morph({'width':[zStart.width,zEnd.width],'height':[zStart.height,zEnd.height],'top':[(zoomBox.heightEnd/2)-(zStart.height/2),(zoomBox.heightEnd/2)-(zEnd.height/2)],'left':[(zoomBox.widthEnd/2)-(zStart.width/2),(zoomBox.widthEnd/2)-(zEnd.width/2)]});$('topBufferImg').src=this.jsonData.basePath+this.jsonData.colors[this.currentColorIdx].views[this.currentAngleIdx].images[this.zoomLevel-1];}.bind(this),function(){if(zoomLevelTo==1){$('navbg').tween('bottom',[-83,17]);$('navColors').tween('bottom',[-100,0]);$('arrowLeft').tween('bottom',[-83,17]);}
this.fxChain.callChain();}.bind(this));this.fxChain.callChain();},zoomIn:function(){if(this.zoomLevel!=3){var zoomLevelTo=((this.zoomLevel+1)!=4)?this.zoomLevel+1:this.zoomLevel;this.zoomSlider.set(3-zoomLevelTo);}},zoomOut:function(){if(this.zoomLevel!=1){var zoomLevelTo=((this.zoomLevel-1)!=0)?this.zoomLevel-1:this.zoomLevel;this.zoomSlider.set(3-zoomLevelTo);}},setCurrentColorDisplay:function(colorIdx){this.currentColorIdx=colorIdx;var currentColor=this.jsonData.colors[this.currentColorIdx];var angleImg=this.jsonData.basePath+currentColor.views[this.currentAngleIdx].images[this.zoomLevel-1];$('bottomBufferImg').src=$('topBufferImg').src;$('topBufferImg').setStyle('opacity',0);$('topBufferImg').src=new Asset.image(angleImg,{onload:function(){$('navColors').empty();this.jsonData.colors.each(function(color,idx){var a=new Element('a',{'href':'#','id':'colorId'+idx,'events':{'click':function(){this.setCurrentColorDisplay(idx);return false;}.bind(this)}}).injectBottom('navColors');var img=new Element('img',{'src':this.jsonData.colorChitsPath+color.colorChit,'alt':color.realName,'width':40,'height':30}).injectBottom(a);}.bind(this));new Element('strong',{'html':this.jsonData.colors[this.currentColorIdx].realName}).injectBottom('navColors');$$('#navColors a').removeClass('on');$('colorId'+colorIdx).addClass('on');$('navColors').getElement('strong').set('html',currentColor.realName);$('topBufferImg').tween('opacity',[0,1]);}.bind(this)}).src;if(_hbPageView)_hbPageView(this.jsonData.colors[this.currentColorIdx].realName.replace(' ','_'),'/Bikes/'+this.jsonData.modelYear+'/'+this.jsonData.motorcycleClass+'/'+this.jsonData.model+'/Colors/');},setCurrentAngleDisplay:function(angleIdx){this.currentAngleIdx=angleIdx;$('nav360').setStyle('background-position','0px '+(-51*(this.currentAngleIdx+1))+'px').set('class',this.directionList[this.currentAngleIdx]+'On');var currentColor=this.jsonData.colors[this.currentColorIdx];var angleImg=this.jsonData.basePath+currentColor.views[this.currentAngleIdx].images[this.zoomLevel-1];$('bottomBufferImg').src=$('topBufferImg').src;$('topBufferImg').setStyle('opacity',0);$('topBufferImg').src=new Asset.image(angleImg,{onload:function(){$('topBufferImg').tween('opacity',[0,1]);}.bind(this)}).src;},quickSetCurrentAngleDisplay:function(angleIdx){this.currentAngleIdx=angleIdx;$('nav360').setStyle('background-position','0px '+(-51*(angleIdx+1))+'px').set('class',this.directionList[angleIdx]+'On');var currentColor=this.jsonData.colors[this.currentColorIdx];var angleImg=this.jsonData.basePath+currentColor.views[angleIdx].images[this.zoomLevel-1];$('topBufferImg').src=angleImg;$('bottomBufferImg').src=angleImg;}});