String.prototype.basename=function(suffix){var path=this;var b=path.replace(/^.*[\/\\]/g,'');if(typeof(suffix)=='string'&&b.substr(b.length-suffix.length)==suffix){b=b.substr(0,b.length-suffix.length);}
return b;}
var gallery=new Class({jsonData:null,panelCount:5,panelPosIdx:0,activeImageIdx:0,activeElement:null,currentLocale:null,Implements:Options,options:{startOnInit:true,duration:1000,linger:3500},initialize:function(jsonUrl,currentLocale,options){this.setOptions(options);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 gallery data.\n"+"transport.readyState = "+xhr.readyState+" / transport.status "+xhr.status);}.bind(this)});this.result.headers.extend({'Accept':'*/*'});this.result.send("json=true");},keyboardListener:function(event){switch(event.key){case'left':this.scrollLeft();return false;case'right':this.scrollRight();return false;default:return true;}},prepare:function(){this.firing=false;this.opened=false;$('galleryThumbs').empty();for(i=0;i<this.jsonData.images.length&&i<this.panelCount;i++){this.makePanel(i).setStyle('left',(146*i)+43).inject('galleryThumbs');}
this.setActiveImage(0);$('leftarrow').addEvent('click',(function(obj){return function(){obj.scrollRight();return false;}})(this));$('rightarrow').addEvent('click',(function(obj){return function(){obj.scrollLeft();return false;}})(this));$('slideLeftArrow').addEvent('click',(function(obj){return function(){obj.pause();obj.activeImageIdx=(obj.activeImageIdx-1)>=0?obj.activeImageIdx-1:obj.activeImageIdx;obj.setActiveImage(obj.activeImageIdx);return false;}})(this));$('slideRightArrow').addEvent('click',(function(obj){return function(){obj.pause();obj.activeImageIdx=(obj.activeImageIdx+1)<obj.jsonData.images.length?obj.activeImageIdx+1:obj.activeImageIdx;obj.setActiveImage(obj.activeImageIdx);return false;}})(this));$('slideDownload').set({'events':{'click':function(){this.pause();$('downloadMenu').setStyle('display',$('downloadMenu').getStyle('display')=='block'?'none':'block');$('slideDownload').toggleClass('on');return false;}.bind(this)}});$('slidePlayPause').addEvent('click',(function(obj){return function(){obj.playToggle();return false;}})(this));this.setVisibilityOfControls();$('bikeGalleryNav').set({'events':{'mouseover':function(){this.mouseOverDock()}.bind(this),'mouseout':function(event){this.mouseOutDock(event)}.bind(this)}});$('navText').set({'events':{'mouseover':function(){this.mouseOverDock()}.bind(this)}});this.dockChain=new Chain();$('bikeGalleryNav').set('tween',{onComplete:function(){this.dockChain.callChain()}.delay(3000,this)});this.dockChain.chain(function(){this.mouseOverDock();}.bind(this),function(){this.firing=true;$('bikeGalleryNav').set('tween',{'link':'ignore','onComplete':function(){this.firing=false;this.opened=false;$('navText').setStyle('display','block');}.bind(this)});$('bikeGalleryNav').tween('top',[333,333+(104-17)]);}.bind(this)).callChain();if(this.options.startOnInit){this.start();}},mouseOverDock:function(){if(!this.firing&&!this.opened){this.firing=true;$('bikeGalleryNav').set('tween',{'link':'ignore','onComplete':function(){this.firing=false;this.opened=true;}.bind(this)});$('bikeGalleryNav').tween('top',[333+(104-17),333]);$('navText').setStyle('display','none');}},mouseOutDock:function(event){if(!this.firing&&this.opened){var coords=$('bikeGalleryNav').getCoordinates();if(event.page.y>=$('bikeGallery').getCoordinates().bottom||event.page.y<=coords.top||event.page.x>=coords.right||event.page.x<=coords.left+8){this.firing=true;$('bikeGalleryNav').set('tween',{'link':'ignore','onComplete':function(){this.firing=false;this.opened=false;$('navText').setStyle('display','block');}.bind(this)});$('bikeGalleryNav').tween('top',[333,333+(104-17)]);}}},makePanel:function(idx){var panelData=this.jsonData.images[idx];var div=new Element('div',{'id':'panel'+idx,'class':'bvGalleryItem','styles':{'top':17}}).set('morph',{duration:this.options.duration});var a=new Element('a',{'id':'tb'+idx,'href':'#','events':{'click':(function(obj,i){return function(){obj.pause();obj.setActiveImage(i);return false;}})(this,idx)}}).injectTop(div);var img=new Element('img',{'src':this.jsonData.basePath+panelData.thumbnailImagePath,'alt':'','width':131,'height':71}).injectTop(a);return div;},setActiveImage:function(idx){var currentImage=this.jsonData.images[idx];$('bottomGalleryLayerImg').src=$('topGalleryLayerImg').src;$('topGalleryLayerImg').setStyle('opacity',0);var tmp=function(){new Asset.image(this.jsonData.basePath+currentImage.webImagePath,{onload:function(){$('topGalleryLayerImg').src=this.jsonData.basePath+currentImage.webImagePath;$('topGalleryLayerImg').set('tween',{duration:750,transition:Fx.Transitions.linear});$('topGalleryLayerImg').tween('opacity',[0,1]);this.activeImageIdx=idx;$$('#galleryThumbs .bvGalleryItem').removeClass('on');$$('#panel'+this.activeImageIdx).addClass('on');Array('size1024x768','size1280x1024','size1280x800','size1680x1050').each(function(size){$(size).set('href','/'+this.currentLocale+'/tools/wallpaper.asp?'+Hash.toQueryString({BikeURL:this.jsonData.basePath+currentImage.wallpapers[size],MLC:"Bikes/"+this.jsonData.motorcycleClass+"/"+this.jsonData.model+"/Gallery"+currentImage.wallpapers[size]}));}.bind(this));}.bind(this)});}.delay(20,this);},scrollLeft:function(){if((this.activeElement==null)&&(this.panelPosIdx<(this.jsonData.images.length-this.panelCount))){this.activeElement=$('panel'+(this.panelPosIdx+0));this.makePanel(this.panelPosIdx+5).setStyle('left',(146*5)+86).injectBottom('galleryThumbs');$('panel'+(this.panelPosIdx+0)).set('morph',{onComplete:function(){this.activeElement.dispose();this.activeElement=null;$$('#galleryThumbs .bvGalleryItem').removeClass('on');$$('#panel'+this.activeImageIdx).addClass('on');}.bind(this)});$('panel'+(this.panelPosIdx+0)).morph({'left':[(0*146)+43,(-1*146)-86],'opacity':[1,0]});$('panel'+(this.panelPosIdx+1)).morph({'left':[(1*146)+43,(0*146)+43]});$('panel'+(this.panelPosIdx+2)).morph({'left':[(2*146)+43,(1*146)+43]});$('panel'+(this.panelPosIdx+3)).morph({'left':[(3*146)+43,(2*146)+43]});$('panel'+(this.panelPosIdx+4)).morph({'left':[(4*146)+43,(3*146)+43]});$('panel'+(this.panelPosIdx+5)).morph({'left':[(5*146)+86,(4*146)+43],'opacity':[0,1]});this.panelPosIdx++;this.setVisibilityOfControls();}},scrollRight:function(){if((this.activeElement==null)&&((this.panelPosIdx!=0)&&(this.panelCount<this.jsonData.images.length))){this.activeElement=$('panel'+(this.panelPosIdx+4));this.makePanel(this.panelPosIdx-1).setStyle('left',(-1*146)-86).injectTop('galleryThumbs');$('panel'+(this.panelPosIdx-1)).morph({'left':[(-1*146)-86,(0*146)+43],'opacity':[0,1]});$('panel'+(this.panelPosIdx+0)).morph({'left':[(0*146)+43,(1*146)+43]});$('panel'+(this.panelPosIdx+1)).morph({'left':[(1*146)+43,(2*146)+43]});$('panel'+(this.panelPosIdx+2)).morph({'left':[(2*146)+43,(3*146)+43]});$('panel'+(this.panelPosIdx+3)).morph({'left':[(3*146)+43,(4*146)+43]});$('panel'+(this.panelPosIdx+4)).set('morph',{onComplete:function(){this.activeElement.dispose();this.activeElement=null;$$('#galleryThumbs .bvGalleryItem').removeClass('on');$$('#panel'+this.activeImageIdx).addClass('on');}.bind(this)});$('panel'+(this.panelPosIdx+4)).morph({'left':[(4*146)+43,(5*146)+86],'opacity':[1,0]});this.panelPosIdx--;this.setVisibilityOfControls();}},setVisibilityOfControls:function(){$('leftarrow').setStyle('visibility',((this.panelPosIdx!=0)&&(this.panelCount<this.jsonData.images.length))?'visible':'hidden');$('rightarrow').setStyle('visibility',((this.panelPosIdx<(this.jsonData.images.length-this.panelCount)))?'visible':'hidden');},step:function(){this.activeImageIdx=(this.activeImageIdx+1)%this.jsonData.images.length;this.setActiveImage(this.activeImageIdx);},start:function(){this.activeImageIdx=0;$('slidePlayPause').set('class','pause');this.timer=this.step.periodical(this.options.linger+this.options.duration,this);},pause:function(){$('slidePlayPause').set('class','play');$clear(this.timer);},playToggle:function(){if($('slidePlayPause').get('class')=='pause'){this.pause();}else{$('slidePlayPause').set('class','pause');this.timer=this.step.periodical(this.options.linger+this.options.duration,this);}}});