var simpleVScrollBar=new Class({Implements:Options,options:{stepDelta:20},initialize:function(sliderDiv,knobDiv,upButton,downButton,scrollArea,scrollContainer,options){this.setOptions(options);this.sfx=new Fx.Scroll(scrollArea,{wait:false});this.slider=new Slider(sliderDiv,knobDiv,{steps:scrollArea.scrollHeight-scrollContainer.clientHeight,wheel:true,mode:"vertical",onChange:function(pos){this.sfx.set(0,pos);}.bind(this)}).set(0);scrollArea.addEvent('mousewheel',function(e){e.stop();this.slider.set(this.slider.step+(e.wheel<=0?this.options.stepDelta:-this.options.stepDelta));}.bind(this));upButton.set({'events':{'mousedown':this.startVScrolling.bindWithEvent(this,'up'),'mouseup':this.stopScrolling.bind(this)}});downButton.set({'events':{'mousedown':this.startVScrolling.bindWithEvent(this,'down'),'mouseup':this.stopScrolling.bind(this)}});},stopScrolling:function(){$clear(this.periodScrollTimer);},startVScrolling:function(e,direction){e.stop();$clear(this.periodScrollTimer);if(direction=='up'){this.periodScrollTimer=this.scrollVertical.periodical(20,this,-this.options.stepDelta/5);}else{this.periodScrollTimer=this.scrollVertical.periodical(20,this,this.options.stepDelta/5);}},scrollVertical:function(d){this.slider.set(this.slider.step+d);}});var features=new Class({jsonData:null,dict:null,currentViewIdx:null,currentViewBulletCount:null,currentDetailIdx:null,featuredDetails:null,viewIsActive:false,fxChain:null,Implements:Options,options:{linkFeaturedDetails:true},initialize:function(jsonUrl,xlatDictionary,options){this.setOptions(options);this.dict=xlatDictionary.words;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 features 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.currentDetailIdx!=null)?this.moveDetailRight():null;return false;case'right':(this.currentDetailIdx!=null)?this.moveDetailLeft():this.moveViewRight();return false;default:return true;}},preloadImages:function(){},presentBulletPoints:function(){var BULLET_OFS_TOP=28;var BULLET_OFS_LEFT=17;$('bulletContainer').empty();var currentView=this.jsonData.views[this.currentViewIdx];var bulletContainer=$('bulletContainer');this.featuredDetails.each(function(feature,idx){if((feature.parentView==currentView)&&(feature.isFeaturedDetail=="true")){var div=new Element('div',{'id':'bullet'+idx,'class':'newbullet','styles':{'opacity':0,'left':(feature.diagramCoords.left-BULLET_OFS_LEFT)+176,'top':(feature.diagramCoords.top-28)-5},'morph':{'duration':500}}).injectTop(bulletContainer);var span1=new Element('span',{'class':'leftSide','tween':{'duration':150,'link':'chain'}}).injectTop(div);var span2=new Element('span',{'class':'rightSide','tween':{'duration':150,'link':'chain'}}).injectTop(span1);var span3=new Element('span',{'class':'bulletOverflow','tween':{'duration':150,'link':'chain'}}).injectTop(span2);var span4=new Element('span',{'class':'wideSpan','tween':{'duration':150,'link':'chain'}}).injectTop(span3);var span5=new Element('span',{'html':feature.shortTitle,'styles':{'opacity':0},'tween':{'duration':150,'link':'chain'}}).injectTop(span4);var a=new Element('a',{'href':'#','events':{'mouseover':function(){div.setStyle('zIndex',99);span1.tween('left',[0,-(span5.offsetWidth/2)]);span2.tween('width',[20,span5.offsetWidth+7]);span3.tween('width',[20,span5.offsetWidth+7]);span4.tween('background-position',['-190 -28',(-190+(span5.offsetWidth/2))+' -28']);span5.set('opacity',1);},'mouseout':function(){div.setStyle('zIndex',98);span1.tween('left',[-(span5.offsetWidth/2),0]);span2.tween('width',[span5.offsetWidth+7,20]);span3.tween('width',[span5.offsetWidth+7,20]);span4.tween('background-position',[(-190+(span5.offsetWidth/2))+' 0','-190 0']);span5.set('opacity',0);}}}).injectTop(div);if(this.options.linkFeaturedDetails){a.addEvent('click',(function(b,obj){return function(){obj.currentDetailIdx=b;obj.presentDetailAt(b,-774);return false;}})(idx,this));}
var img=new Element('img',{'src':'/_media/images/common/spacer.gif','width':34,'height':28}).injectTop(a);div.morph.delay(150*(idx++),div,{'opacity':[0,1],'top':[(feature.diagramCoords.top-BULLET_OFS_TOP)-5,(feature.diagramCoords.top-BULLET_OFS_TOP)]});}}.bind(this));},prepare:function(){this.currentViewIdx=0;this.currentDetailIdx=null;$$('.viewContainer').setStyle('left',-980);this.currentViewBulletCount=0;this.featuredDetails=Array();this.jsonData.features.each(function(feature,idx){if(feature.isFeaturedDetail=="true"){this.featuredDetails[this.currentViewBulletCount++]=feature;}}.bind(this));this.fxChain=new Chain();$$('.viewContainer').each(function(el){el.set('tween',{transition:Fx.Transitions.Quint.easeOut,duration:1000,onComplete:function(){this.fxChain.callChain();}.bind(this)});}.bind(this));$$('.viewContainer .buttons').each(function(el){el.set('tween',{transition:Fx.Transitions.linear,duration:1000,onComplete:function(){this.fxChain.callChain();}.bind(this)});}.bind(this));var vs=this.jsonData.views;this.fxChain.chain(function(){$(vs[this.currentViewIdx]).tween('left',[-980,0]);$(vs[this.currentViewIdx]).getElement('.rightButton').tween('right',[150,16]);}.bind(this),function(){this.presentBulletPoints(this.currentViewIdx);this.fxChain.callChain();}.bind(this));this.fxChain.callChain();$$('.viewContainer .buttons .rightButton').addEvent('click',function(){this.moveViewRight();return false;}.bind(this));},moveViewRight:function(){if(!this.viewIsActive){this.viewIsActive=true;$('bulletContainer').empty();var vs=this.jsonData.views;this.fxChain.chain(function(){$(vs[this.currentViewIdx]).tween('left',[0,980])}.bind(this),function(){this.currentViewIdx=((this.currentViewIdx-1)<0)?this.jsonData.views.length-1:this.currentViewIdx-1;$(vs[this.currentViewIdx]).tween('left',[-980,0]);$(vs[this.currentViewIdx]).getElement('.rightButton').tween('right',[100,16]);}.bind(this),function(){this.presentBulletPoints(this.currentViewIdx);this.fxChain.callChain();}.bind(this),function(){this.viewIsActive=false;}.bind(this));this.fxChain.callChain();}},presentDetailAt:function(idx,startPoint){var feature=this.featuredDetails[idx];var div1=new Element('div',{'id':'featureDetail'+idx,'class':'featureWindow','styles':{'left':startPoint}}).injectTop('feautureWindowScroller');var div2=new Element('div',{'class':'imageViewPort'}).injectTop(div1);var img1=new Element('img',{'src':'','id':'featureImage','width':750,'height':750,'styles':{'top':-(2*84),'left':-(3*84)}}).injectTop(div2);var div3=new Element('div',{'class':'textViewPort'}).injectBottom(div1);var div4=new Element('div',{'class':'closeBox'}).injectBottom(div3);var a1=new Element('a',{'href':'#','html':this.dict.close,'events':{'click':function(){this.closeDetail(div1);return false;}.bind(this)}}).injectTop(div4);var div5=new Element('div',{'class':'smallBikeMap '+feature.parentView}).injectBottom(div3);var img2=new Element('div',{'class':'miniBullet','styles':{'top':feature.miniDiagramCoords.top-7,'left':feature.miniDiagramCoords.left-7}}).injectTop(div5);var scrollContainer=new Element('div',{'class':'featureCopyContainer'}).injectBottom(div3);var scrollArea=new Element('div',{'class':'featureCopy','html':feature.detailDescription}).injectBottom(scrollContainer);var h3=new Element('h3',{'html':feature.detailTitle}).injectTop(scrollArea);var div6=new Element('div',{'class':'pageControls','html':(this.currentDetailIdx+1)+' '+this.dict['of']+' '+this.currentViewBulletCount}).injectBottom(div3);var a2=new Element('a',{'class':'previous','href':'#','html':this.dict['previous'],'events':{'click':function(){this.moveDetailRight();return false;}.bind(this)}}).injectTop(div6);var a3=new Element('a',{'class':'next','href':'#','html':this.dict['next'],'events':{'click':function(){this.moveDetailLeft();return false;}.bind(this)}}).injectTop(div6);if(scrollArea.scrollHeight>scrollContainer.clientHeight){var div10=new Element('div',{'class':'scrollBarContainer'}).injectBottom(div3);var upButton=new Element('button',{'class':'scrollUp'}).injectTop(div10);var sliderDiv=new Element('div',{'class':'scrollBar'}).injectTop(div10);var knobDiv=new Element('div',{'class':'scrollDrag'}).injectTop(sliderDiv);var downButton=new Element('button',{'class':'scrollDown'}).injectTop(div10);var ssb=new simpleVScrollBar(sliderDiv,knobDiv,upButton,downButton,scrollArea,scrollContainer,{'stepDelta':20});}
img1.src=new Asset.image(this.jsonData.imageBasePath+feature.imagePath,{onload:function(){div1.set('tween',{onComplete:function(){this.detailImgChain=new Chain();this.detailImgChain.chain(function(){$('featureImage').set('morph',{'duration':3500,transition:Fx.Transitions.Quint.easeOut,onComplete:function(){this.detailImgChain.callChain();}.bind(this)});$('featureImage').morph({'left':[-(3*84),-(2*84)]});}.bind(this)).callChain();}});div1.tween('left',[startPoint,190]);}.bind(this)}).src;},moveDetailLeft:function(){$('featureDetail'+this.currentDetailIdx).tween('left',[190,-(774+20)]);this.currentDetailIdx=(this.currentDetailIdx+1)%this.currentViewBulletCount;this.presentDetailAt(this.currentDetailIdx,774+774+20);},moveDetailRight:function(){$('featureDetail'+this.currentDetailIdx).tween('left',[190,774+774+20]);this.currentDetailIdx=(this.currentDetailIdx-1<0)?this.currentViewBulletCount-1:this.currentDetailIdx-1;this.presentDetailAt(this.currentDetailIdx,-(774+20));},closeDetail:function(detail){detail.set('tween',{link:'chain',duration:600,transition:Fx.Transitions.Back.easeIn});detail.tween('left',[190,774+774+20]);this.currentDetailIdx=null;}});