var photogallery;window.addEvent('domready',function(){var imgDataArray=[];var imgs=$$('.thumbnail img')
if(imgs.length==0)return;imgs.each(function(img){var w=parseInt(img.getAttribute('originalwidth'));var h=parseInt(img.getAttribute('originalheight'));imgDataArray.push({title:$(img.parentNode.parentNode.parentNode).getElement('.phototxt').innerHTML,description:img.alt,src:img.src.split('?')[0],ratio:w/h,variants:[{width:320,height:240,name:'tiny'},{width:400,height:300,name:'tiny2'},{width:512,height:384,name:'tiny3'},{width:640,height:480,name:'small'},{width:800,height:600,name:'small2'},{width:1024,height:768,name:'medium'},{width:1280,height:960,name:'medium2'},{width:1600,height:1200,name:'large'}].filter(function(item){return(w>item.width||h>item.height);}).map(function(item){var ratio=w/h;if(ratio>1.3333333333){item.height=item.width/ratio;}
else{item.width=item.height*ratio;}
return item;}).include({width:w,height:h,name:'raw'})});});photogallery=new Gallery(imgDataArray);if(window.ie6){['mouseenter','mouseleave'].each(function(e){$('download').addEvent(e,function(){if($('download').hasChild((new Event()).target))return;this.toggleClass('hover');});});['mouseenter','mouseleave'].each(function(e){['#next','#previous','.thumbnail'].each(function(rule){$$(rule).addEvent(e,function(){this.toggleClass('hover');});})});}
var i=1000;if(window.ie){$$('.thumbnail').each(function(thumb){thumb.setStyle('z-index',i--);});}});var Gallery=new Class({initialize:function(imgDataArray){var gallery=this;this._images={};this._images._size=imgDataArray.length;this._firstImage=imgDataArray[0].src;for(var i=0;i<imgDataArray.length;i++){this._images[imgDataArray[i].src]=imgDataArray[i];var next=(i+1)%imgDataArray.length;var previous=(i-1)>=0?i-1:imgDataArray.length-1;this._images[imgDataArray[i].src].next=imgDataArray[next].src;this._images[imgDataArray[i].src].previous=imgDataArray[previous].src;this._images[imgDataArray[i].src].index=i;}
this.title=document.getElement('h1').innerHTML;this._preloader=new Preloader();this.grid=new Grid(this);this.displayPhoto=new DisplayPhoto(this);this.filmstrip=new Filmstrip(this);this.slideshow=new SlideShow(this);this.history=new HistoryManager();this.history.addEvent('onHistoryChange',function(hash){var mode=hash.split(':')[0]||'grid';var srcBase=location.href.slice(0,location.href.lastIndexOf('/'));var img=srcBase+'/'+decodeURIComponent(hash.split(':')[1]);gallery.changeMode(mode,img);});['grid','filmstrip','single','slideshow'].each(function(mode){$$('.mode'+mode.capitalize()).addEvent('click',function(event){new Event(event).stop();this.blur();gallery.changeMode(mode);});});this.history.fireEvent('onHistoryChange',[this.history.getCurrentLocation()]);this.addEvent('modeChange',function(mode,src){if(mode=='grid')return this.history.addState('');src=':'+encodeURIComponent(src.slice(src.lastIndexOf('/')+1));this.history.addState(mode+src);}.bind(this));this.displayPhoto.addEvent('displayPhotoChange',function(src){this.fireEvent('nextPhoto',[src]);}.bind(this));document.addEvent('keypress',function(event){gallery.keyPressed.call(gallery,event);});},getImageData:function(src){return this._images[src];},getFirst:function(){return this._firstImage;},getNext:function(src){return this._images[src].next;},getPrevious:function(src){return this._images[src].previous;},getNumberOfImages:function(){return this._images._size;},keyPressed:function(event){if(this.mode=='grid')return;event=new Event(event);switch(event.key){case'up':case'left':case'j':return this.displayPhoto.previous();case'down':case'right':case'k':return this.displayPhoto.next();case'space':if(this.mode!='grid')
this.mode=='slideshow'?this.changeMode('single'):this.changeMode('slideshow');}
switch(event.code){case 63232:case 63234:return this.displayPhoto.previous();case 63233:case 63235:return this.displayPhoto.next();}},changeMode:function(mode,img){if(this.mode==mode){if(mode!='grid')this.displayPhoto.show(img);return;}
window.scrollTo(0,0);document.body.className=mode.capitalize();img=img||this.displayPhoto._currentlyShowing||this.getFirst();this.fireEvent('modeChange',[mode,img]);$$('.modeSelector').removeClass('selected');$$('.mode'+mode.capitalize()).addClass('selected');this.mode=mode;}});Gallery.implement(new Events);var Grid=new Class({initialize:function(gallery){this._gallery=gallery;this._thumbnails=$$('.thumbnail');this._preferences=new Hash.Cookie('PhotoGalleryPreferences',{duration:365,path:'/'});this._preferences.set('thumbsSize',this._preferences.get('thumbsSize')||142);var sliderCreated=false;gallery.addEvent('modeChange',function(mode){if(mode=='grid'&&!sliderCreated){this._createSlider();sliderCreated=true;}}.bind(this));$$('.thumbnail a.shadow').addEvent('click',function(event){new Event(event).stop();this.blur();var src=this.getElement('img').src.split('?')[0];gallery.changeMode('single',src);});},resizeThumbnails:function(size){for(var i=0;i<this._thumbnails.length;i++){var thumb=this._thumbnails[i];var img=thumb.getElement('img');var ratio=this._gallery.getImageData(img.src.split('?')[0]).ratio;thumb.style.height=thumb.style.width=size+'px';if(ratio>1){img.style.width=size+'px';img.style.height=(size/ratio)+'px';}
else{img.style.height=size+'px';img.style.width=(size*ratio)+'px';}}},_createSlider:function(){var grid=this;new Slider($('resizeSlider'),$('resizeHandle'),{steps:100,onChange:function(pos){grid.resizeThumbnails(pos+92);},onComplete:function(pos){grid._preferences.set('thumbsSize',pos);}}).set(parseInt(grid._preferences.get('thumbsSize')));}});var DisplayPhoto=new Class({initialize:function(gallery){this._gallery=gallery;this._preloader=gallery._preloader;this._displayPhoto=$E('#displayPhoto .shadow');this._currentlyShowing='';this._fadeout=new Fx.Style(this._displayPhoto,'opacity',{duration:400,transition:Fx.Transitions.Sine.easeInOut});this._fadein=new Fx.Style(this._displayPhoto,'opacity',{duration:300,transition:Fx.Transitions.Sine.easeInOut});this.noResize=navigator.userAgent.test(/Windows/);var displayPhoto=this;$('next').addEvent('click',function(event){new Event(event).stop();this.blur();displayPhoto.next.call(displayPhoto);});$('previous').addEvent('click',function(event){new Event(event).stop();this.blur();displayPhoto.previous.call(displayPhoto);});gallery.addEvent('modeChange',function(mode,src){if(mode=='grid')this.exit();else this.enter(src);}.bind(this));this.exit();},findDisplayArea:function(){var upperBound=($('controlBar').getCoordinates().bottom<$('photoExtras').getCoordinates().bottom)?$('controlBar').getCoordinates().bottom:$('header').getCoordinates().bottom;var lowerBound=Math.min($('photoDescription').getCoordinates().top,$('next').getCoordinates().top)||$('photoDescription').getCoordinates().top;return this._area={width:window.getWidth()-60-($('displayPhoto').getSize().size.x-$E('#displayPhoto img').getSize().size.x),height:lowerBound-upperBound-20-($('displayPhoto').getSize().size.y-$E('#displayPhoto img').getSize().size.y),offsetTop:upperBound+10}},getVariant:function(src){var img=this._gallery.getImageData(src);var title=$('photoTitle').innerHTML;$('photoTitle').innerHTML=img.title;var description=$('photoDescription').innerHTML;$('photoDescription').innerHTML=img.description;var area=this.findDisplayArea();var criticalDimension=img.ratio*area.height>area.width?'width':'height';var variant;if(this.noResize){for(variant=img.variants.length-1;variant>0;variant--)
if(img.variants[variant][criticalDimension]<=area[criticalDimension])
break;}
else{for(variant=0;variant<img.variants.length-1;variant++)
if(img.variants[variant][criticalDimension]>=area[criticalDimension])
break;}
$('photoTitle').innerHTML=title;$('photoDescription').innerHTML=description;return img.variants[variant];},resizeDisplayImage:function(){var area=this._area;var img=document.getElement('#displayPhoto img');var imageData=this._gallery.getImageData(img.src.split('?')[0]);if(!imageData)
return;img.style.width=Math.min(area.width,imageData.ratio*area.height,img.naturalWidth)+'px';img.style.height=(parseFloat(img.style.width)/imageData.ratio)+'px';$('displayPhoto').style.top=area.offsetTop+((area.height-parseInt(img.style.height))/2)+'px';},show:function(src){if(this._currentlyShowing==src)return;var loading=$('loading');var displayPhoto=this;if(!this._preloader.priorityLoadWithCallback(src+'?variant='+this.getVariant(src).name,switchPhotos))
loading.style.display='block';function switchPhotos(){var imageData=displayPhoto._gallery.getImageData(src);displayPhoto._preloader.addToQueue(imageData.next+'?variant='+displayPhoto.getVariant(imageData.next).name);displayPhoto._preloader.addToQueue(imageData.previous+'?variant='+displayPhoto.getVariant(imageData.previous).name);displayPhoto._fadeout.start(0).chain(function(){document.title=displayPhoto._gallery.title+': '+imageData.title;$E('#displayPhoto img').replaceWith(this);displayPhoto._currentlyShowing=src;if(!this.naturalWidth){this.naturalWidth=this.width;}
$('photoTitle').innerHTML=(this.title=imageData.title);$('photoDescription').innerHTML=(this.alt=imageData.description);displayPhoto.findDisplayArea();displayPhoto.resizeDisplayImage();var downloadList=document.getElement('#download span').empty();imageData.variants.each(function(variant){var a=new Element('a');a.href=imageData.src+'?asatt=1&variant='+variant.name;a.innerHTML=parseInt(variant.width)+' x '+parseInt(variant.height);if(variant.name=='raw')a.innerHTML='Original<br />'+a.innerHTML;a.inject(downloadList);});loading.style.display='none';displayPhoto.fireEvent('displayPhotoChange',src);displayPhoto._fadein.start(1);displayPhoto._gallery.history.addState(displayPhoto._gallery.mode+':'+encodeURIComponent(src.slice(src.lastIndexOf('/')+1)));}.bind(this));}},next:function(){this.fireEvent('next');this.show(this._gallery.getNext(this._currentlyShowing));},previous:function(){this.fireEvent('previous');this.show(this._gallery.getPrevious(this._currentlyShowing));},enter:function(src){this.findDisplayArea();if(this._active)return this.resizeDisplayImage();var displayPhoto=this;function onResize(){displayPhoto._area=displayPhoto.findDisplayArea();displayPhoto.resizeDisplayImage();}
window.addEvent('resize',onResize);this.addEvent('exit',function(){window.removeEvent('resize',onResize);});this._active=true;this.show(src);},exit:function(){this._preloader.stopAllEvents().flushQueue();this._displayPhoto.setStyle('opacity',0);document.getElement('h1').innerHTML=this._gallery.title;document.title=this._gallery.title;this._active=false;this._currentlyShowing='';$('loading').style.display='none';this.fireEvent('exit');}});DisplayPhoto.implement(new Events);var Filmstrip=new Class({initialize:function(gallery){this._gallery=gallery;this._visible=false;this._strip=$('strip');this._scroll=new Fx.Scroll('strip',{duration:750,transition:Fx.Transitions.Quad.easeInOut});$$('#strip a').addEvent('click',function(event){new Event(event).stop();this.blur();gallery.displayPhoto.show(this.getElement('img').src.split('?')[0]);});gallery.displayPhoto.addEvent('displayPhotoChange',this.updateSelected.bind(this));},updateSelected:function(src){var index=this._gallery.getImageData(src).index;if(this._currentlySelected)this._currentlySelected.removeClass('selected');this._currentlySelected=this._strip.getElements('img')[index].addClass('selected');var scrollX=this._currentlySelected.getPosition().x
+this._currentlySelected.getSize().size.x/2
-this._strip.getCoordinates().left
-(this._strip.getSize().size.x
-this._strip.getStyle('border-left-width').toInt()
-this._strip.getStyle('border-right-width').toInt())/2;this._scroll.scrollTo(scrollX,false);}});var SlideShow=new Class({initialize:function(gallery){this._gallery=gallery;gallery.addEvent('modeChange',function(mode){if(mode=='slideshow')this.play();else this.pause();}.bind(this));gallery.displayPhoto.addEvent('displayPhotoChange',function(){if(!this._playing)return;this._timer=this._gallery.displayPhoto.next.delay(4500,this._gallery.displayPhoto);}.bind(this));['next','previous'].each(function(event){gallery.displayPhoto.addEvent(event,function(){$clear(this._timer);}.bind(this));}.bind(this));},play:function(){this._playing=true;if(this._gallery.displayPhoto._currentlyShowing)
this._gallery.displayPhoto.next.call(this._gallery.displayPhoto);},pause:function(){$clear(this._timer);this._playing=false;}});
1;
