Slideshow=new Class({Implements:[Chain,Events,Options],options:{captions:false,center:true,classes:[],controller:false,delay:2000,duration:750,fast:false,height:false,href:"",hu:"",linked:false,loader:{animate:["css/loader-#.png",12]},loop:true,match:/\?slide=(\d+)$/,overlap:true,paused:false,properties:["href","rel","rev","title"],random:false,replace:[/(\.[^\.]+)$/,"t$1"],resize:"width",slide:0,thumbnails:false,titles:true,transition:function(a){return -(Math.cos(Math.PI*a)-1)/2;},width:false},initialize:function(c,f,l){this.setOptions(l);this.slideshow=$(c);if(!this.slideshow){return;}this.slideshow.set("styles",{display:"block",position:"relative","z-index":0});var h=window.location.href.match(this.options.match);this.slide=(this.options.match&&h)?h[1].toInt():this.options.slide;this.counter=this.delay=this.transition=0;this.direction="left";this.paused=false;if(!this.options.overlap){this.options.duration*=2;}var g=this.slideshow.getElement("a")||new Element("a");if(!this.options.href){this.options.href=g.get("href")||"";}if(this.options.hu.length&&!this.options.hu.test(/\/$/)){this.options.hu+="/";}if(this.options.fast===true){this.options.fast=2;}var k=["slideshow","first","prev","play","pause","next","last","images","captions","controller","thumbnails","hidden","visible","inactive","active","loader"];var j=k.map(function(n,m){return this.options.classes[m]||n;},this);this.classes=j.associate(k);this.classes.get=function(){var o="."+this.slideshow;for(var n=0,m=arguments.length;n<m;n++){o+=("-"+this[arguments[n]]);}return o;}.bind(this.classes);if(!f){this.options.hu="";f={};var d=this.slideshow.getElements(this.classes.get("thumbnails")+" img");this.slideshow.getElements(this.classes.get("images")+" img").each(function(o,q){var s=o.get("src");var n=$pick(o.get("alt"),o.get("title"),"");var r=o.getParent();var p=(r.get("tag")=="a")?r.getProperties:{};var m=o.getParent().get("href")||"";var t=(d[q])?d[q].get("src"):"";f[s]={caption:n,href:m,thumbnail:t};});}var e=this.load(f);if(!e){return;}this.events=$H({keydown:[],keyup:[],mousemove:[]});var b=function(m){switch(m.key){case"left":this.prev(m.shift);break;case"right":this.next(m.shift);break;case"p":this.pause();break;}}.bind(this);this.events.keyup.push(b);document.addEvent("keyup",b);var c=this.slideshow.getElement(this.classes.get("images"));var i=(c)?c.empty():new Element("div",{"class":this.classes.get("images").substr(1)}).inject(this.slideshow);var a=i.getSize();this.height=this.options.height||a.y;this.width=this.options.width||a.x;i.set({styles:{display:"block",height:this.height,overflow:"hidden",position:"relative",width:this.width}});this.slideshow.store("images",i);this.a=this.image=this.slideshow.getElement("img")||new Element("img");if(Browser.Engine.trident&&Browser.Engine.version>4){this.a.style.msInterpolationMode="bicubic";}this.a.set("styles",{display:"none",position:"absolute",zIndex:1});this.b=this.a.clone();[this.a,this.b].each(function(m){g.clone().cloneEvents(g).grab(m).inject(i);});if(this.options.captions){this._captions();}if(this.options.controller){this._controller();}if(this.options.loader){this._loader();}if(this.options.thumbnails){this._thumbnails();}this._preload();},go:function(b,a){if((this.slide-1+this.data.images.length)%this.data.images.length==b||$time()<this.transition){return;}$clear(this.timer);this.delay=0;this.direction=(a)?a:((b<this.slide)?"right":"left");this.slide=b;if(this.preloader){this.preloader=this.preloader.destroy();}this._preload(this.options.fast==2||(this.options.fast==1&&this.paused));},first:function(){this.prev(true);},prev:function(a){var b=0;if(!a){if(this.options.random){if(this.showed.i<2){return;}this.showed.i-=2;b=this.showed.array[this.showed.i];}else{b=(this.slide-2+this.data.images.length)%this.data.images.length;}}this.go(b,"right");},pause:function(a){if($chk(a)){this.paused=(a)?false:true;}if(this.paused){this.paused=false;this.delay=this.transition=0;this.timer=this._preload.delay(100,this);[this.a,this.b].each(function(b){["morph","tween"].each(function(c){if(this.retrieve(c)){this.get(c).resume();}},b);});if(this.options.controller){this.slideshow.getElement("."+this.classes.pause).removeClass(this.classes.play);}}else{this.paused=true;this.delay=Number.MAX_VALUE;this.transition=0;$clear(this.timer);[this.a,this.b].each(function(b){["morph","tween"].each(function(c){if(this.retrieve(c)){this.get(c).pause();}},b);});if(this.options.controller){this.slideshow.getElement("."+this.classes.pause).addClass(this.classes.play);}}},next:function(a){var b=(a)?this.data.images.length-1:this.slide;this.go(b,"left");},last:function(){this.next(true);},load:function(c){this.firstrun=true;this.showed={array:[],i:0};if($type(c)=="array"){this.options.captions=false;c=new Array(c.length).associate(c.map(function(h,g){return h+"?"+g;}));}this.data={images:[],captions:[],hrefs:[],thumbnails:[]};for(var e in c){var d=c[e]||{};var b=(d.caption)?d.caption.trim():"";var a=(d.href)?d.href.trim():((this.options.linked)?this.options.hu+e:this.options.href);var f=(d.thumbnail)?d.thumbnail.trim():e.replace(this.options.replace[0],this.options.replace[1]);this.data.images.push(e);this.data.captions.push(b);this.data.hrefs.push(a);this.data.thumbnails.push(f);}if(this.options.random){this.slide=$random(0,this.data.images.length-1);}if(this.options.thumbnails&&this.slideshow.retrieve("thumbnails")){this._thumbnails();}if(this.slideshow.retrieve("images")){[this.a,this.b].each(function(g){["morph","tween"].each(function(h){if(this.retrieve(h)){this.get(h).cancel();}},g);});this.slide=this.transition=0;this.go(0);}return this.data.images.length;},destroy:function(a){this.events.each(function(c,b){c.each(function(d){document.removeEvent(b,d);});});this.pause(1);if(this.options.loader){$clear(this.slideshow.retrieve("loader").retrieve("timer"));}if(this.options.thumbnails){$clear(this.slideshow.retrieve("thumbnails").retrieve("timer"));}this.slideshow.uid=Native.UID++;if(a){this.slideshow[a]();}},_preload:function(a){if(!this.preloader){this.preloader=new Asset.image(this.options.hu+this.data.images[this.slide],{onload:function(){this.store("loaded",true);}});}if(this.preloader.retrieve("loaded")&&$time()>this.delay&&$time()>this.transition){if(this.stopped){if(this.options.captions){this.slideshow.retrieve("captions").get("morph").cancel().start(this.classes.get("captions","hidden"));}this.pause(1);if(this.end){this.fireEvent("end");}this.stopped=this.end=false;return;}this.image=(this.counter%2)?this.b:this.a;this.image.set("styles",{display:"block",height:"auto",visibility:"hidden",width:"auto",zIndex:this.counter});["src","height","width"].each(function(d){this.image.set(d,this.preloader.get(d));},this);this._resize(this.image);this._center(this.image);var b=this.image.getParent();if(this.data.hrefs[this.slide]){b.set("href",this.data.hrefs[this.slide]);}else{b.erase("href");}var c=(this.data.captions[this.slide])?this.data.captions[this.slide].replace(/<.+?>/gm,"").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"'"):"";this.image.set("alt",c);if(this.options.titles){b.set("title",c);}if(this.options.loader){this.slideshow.retrieve("loader").fireEvent("hide");}if(this.options.captions){this.slideshow.retrieve("captions").fireEvent("update",a);}if(this.options.thumbnails){this.slideshow.retrieve("thumbnails").fireEvent("update",a);}this._show(a);this._loaded();}else{if($time()>this.delay&&this.options.loader){this.slideshow.retrieve("loader").fireEvent("show");}this.timer=(this.paused&&this.preloader.retrieve("loaded"))?null:this._preload.delay(100,this,a);}},_show:function(b){if(!this.image.retrieve("morph")){var c=(this.options.overlap)?{duration:this.options.duration,link:"cancel"}:{duration:this.options.duration/2,link:"chain"};$$(this.a,this.b).set("morph",$merge(c,{onStart:this._start.bind(this),onComplete:this._complete.bind(this),transition:this.options.transition}));}var e=this.classes.get("images",((this.direction=="left")?"next":"prev"));var f=this.classes.get("images","visible");var a=(this.counter%2)?this.a:this.b;if(b){a.get("morph").cancel().set(e);this.image.get("morph").cancel().set(f);}else{if(this.options.overlap){a.get("morph").set(f);this.image.get("morph").set(e).start(f);}else{var d=function(g,h){this.image.get("morph").set(g).start(h);}.pass([e,f],this);e=this.classes.get("images",((this.direction=="left")?"prev":"next"));a.get("morph").set(f).start(e).chain(d);}}},_loaded:function(){this.counter++;this.delay=(this.paused)?Number.MAX_VALUE:$time()+this.options.duration+this.options.delay;this.direction="left";this.transition=(this.options.fast==2||(this.options.fast==1&&this.paused))?0:$time()+this.options.duration;if(this.slide+1==this.data.images.length&&!this.options.loop&&!this.options.random){this.stopped=this.end=true;}if(this.options.random){this.showed.i++;if(this.showed.i>=this.showed.array.length){var a=this.slide;if(this.showed.array.getLast()!=a){this.showed.array.push(a);}while(this.slide==a){this.slide=$random(0,this.data.images.length-1);}}else{this.slide=this.showed.array[this.showed.i];}}else{this.slide=(this.slide+1)%this.data.images.length;}if(this.image.getStyle("visibility")!="visible"){(function(){this.image.setStyle("visibility","visible");}).delay(1,this);}if(this.preloader){this.preloader=this.preloader.destroy();}this._preload();},_center:function(a){if(this.options.center){var b=a.getSize();a.set("styles",{left:(b.x-this.width)/-2,top:(b.y-this.height)/-2});}},_resize:function(b){if(this.options.resize){var e=this.preloader.get("height"),a=this.preloader.get("width");var f=this.height/e,c=this.width/a,g;if(this.options.resize=="length"){g=(f>c)?c:f;}else{g=(f>c)?f:c;}b.set("styles",{height:Math.ceil(e*g),width:Math.ceil(a*g)});}},_start:function(){this.fireEvent("start");},_complete:function(){if(this.firstrun&&this.options.paused){this.firstrun=false;this.pause(1);}this.fireEvent("complete");},_captions:function(){if(this.options.captions===true){this.options.captions={};}var b=this.slideshow.getElement(this.classes.get("captions"));var a=(b)?b.empty():new Element("div",{"class":this.classes.get("captions").substr(1)}).inject(this.slideshow);a.set({events:{update:function(d){var c=this.slideshow.retrieve("captions");var f=(this.data.captions[this.slide]==="");if(d){var g=(f)?"hidden":"visible";c.set("html",this.data.captions[this.slide]).get("morph").cancel().set(this.classes.get("captions",g));}else{var e=(f)?$empty:function(h){this.slideshow.retrieve("captions").set("html",this.data.captions[h]).morph(this.classes.get("captions","visible"));}.pass(this.slide,this);c.get("morph").cancel().start(this.classes.get("captions","hidden")).chain(e);}}.bind(this)},morph:$merge(this.options.captions,{link:"chain"})});this.slideshow.store("captions",a);},_controller:function(){if(this.options.controller===true){this.options.controller={};}var e=this.slideshow.getElement(this.classes.get("controller"));var a=(e)?e.empty():new Element("div",{"class":this.classes.get("controller").substr(1)}).inject(this.slideshow);var c=new Element("ul").inject(a);$H({first:"Shift + Leftwards Arrow",prev:"Leftwards Arrow",pause:"P",next:"Rightwards Arrow",last:"Shift + Rightwards Arrow"}).each(function(j,i){var g=new Element("li",{"class":(i=="pause"&&this.options.paused)?this.classes.play+" "+this.classes[i]:this.classes[i]}).inject(c);var h=this.slideshow.retrieve(i,new Element("a",{title:((i=="pause")?this.classes.play.capitalize()+" / ":"")+this.classes[i].capitalize()+" ["+j+"]"}).inject(g));h.set("events",{click:function(k){this[k]();}.pass(i,this),mouseenter:function(k){this.addClass(k);}.pass(this.classes.active,h),mouseleave:function(k){this.removeClass(k);}.pass(this.classes.active,h)});},this);a.set({events:{hide:function(g){if(!this.retrieve("hidden")){this.store("hidden",true).morph(g);}}.pass(this.classes.get("controller","hidden"),a),show:function(g){if(this.retrieve("hidden")){this.store("hidden",false).morph(g);}}.pass(this.classes.get("controller","visible"),a)},morph:$merge(this.options.controller,{link:"cancel"})}).store("hidden",false);var b=function(h){if(["left","right","p"].contains(h.key)){var g=this.slideshow.retrieve("controller");if(g.retrieve("hidden")){g.get("morph").set(this.classes.get("controller","visible"));}switch(h.key){case"left":this.slideshow.retrieve((h.shift)?"first":"prev").fireEvent("mouseenter");break;case"right":this.slideshow.retrieve((h.shift)?"last":"next").fireEvent("mouseenter");break;default:this.slideshow.retrieve("pause").fireEvent("mouseenter");break;}}}.bind(this);this.events.keydown.push(b);var f=function(h){if(["left","right","p"].contains(h.key)){var g=this.slideshow.retrieve("controller");if(g.retrieve("hidden")){g.store("hidden",false).fireEvent("hide");}switch(h.key){case"left":this.slideshow.retrieve((h.shift)?"first":"prev").fireEvent("mouseleave");break;case"right":this.slideshow.retrieve((h.shift)?"last":"next").fireEvent("mouseleave");break;default:this.slideshow.retrieve("pause").fireEvent("mouseleave");break;}}}.bind(this);this.events.keyup.push(f);var d=function(h){var g=this.slideshow.retrieve("images").getCoordinates();if(h.page.x>g.left&&h.page.x<g.right&&h.page.y>g.top&&h.page.y<g.bottom){this.slideshow.retrieve("controller").fireEvent("show");}else{this.slideshow.retrieve("controller").fireEvent("hide");}}.bind(this);this.events.mousemove.push(d);document.addEvents({keydown:b,keyup:f,mousemove:d});this.slideshow.retrieve("controller",a).fireEvent("hide");},_loader:function(){if(this.options.loader===true){this.options.loader={};}var a=new Element("div",{"class":this.classes.get("loader").substr(1),morph:$merge(this.options.loader,{link:"cancel"})}).store("hidden",false).store("i",1).inject(this.slideshow.retrieve("images"));if(this.options.loader.animate){for(var b=0;b<this.options.loader.animate[1];b++){img=new Asset.image(this.options.loader.animate[0].replace(/#/,b));}if(Browser.Engine.trident4&&this.options.loader.animate[0].contains("png")){a.setStyle("backgroundImage","none");}}a.set("events",{animate:function(){var c=this.slideshow.retrieve("loader");var e=(c.retrieve("i").toInt()+1)%this.options.loader.animate[1];c.store("i",e);var d=this.options.loader.animate[0].replace(/#/,e);if(Browser.Engine.trident4&&this.options.loader.animate[0].contains("png")){c.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+d+'", sizingMethod="scale")';}else{c.setStyle("backgroundImage","url("+d+")");}}.bind(this),hide:function(){var c=this.slideshow.retrieve("loader");if(!c.retrieve("hidden")){c.store("hidden",true).morph(this.classes.get("loader","hidden"));if(this.options.loader.animate){$clear(c.retrieve("timer"));}}}.bind(this),show:function(){var c=this.slideshow.retrieve("loader");if(c.retrieve("hidden")){c.store("hidden",false).morph(this.classes.get("loader","visible"));if(this.options.loader.animate){c.store("timer",function(){this.fireEvent("animate");}.periodical(50,c));}}}.bind(this)});this.slideshow.retrieve("loader",a).fireEvent("hide");},_thumbnails:function(){if(this.options.thumbnails===true){this.options.thumbnails={};}var c=this.slideshow.getElement(this.classes.get("thumbnails"));var e=(c)?c.empty():new Element("div",{"class":this.classes.get("thumbnails").substr(1)}).inject(this.slideshow);e.setStyle("overflow","hidden");var a=new Element("ul",{tween:{link:"cancel"}}).inject(e);this.data.thumbnails.each(function(k,j){var f=new Element("li").inject(a);var g=new Element("a",{events:{click:function(l){this.go(l);return false;}.pass(j,this),loaded:function(){this.data.thumbnails.pop();if(!this.data.thumbnails.length){var o=e.getCoordinates();var m=e.retrieve("props");var i=0,n=m[1],l=m[2];e.getElements("li").each(function(p){var p=p.getCoordinates();if(p[n]>i){i=p[n];}},this);e.store("limit",o[l]+o[m[0]]-i);}}.bind(this)},href:this.options.hu+this.data.images[j],morph:$merge(this.options.thumbnails,{link:"cancel"})}).inject(f);if(this.data.captions[j]&&this.options.titles){g.set("title",this.data.captions[j].replace(/<.+?>/gm,"").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"'"));}var h=new Asset.image(this.options.hu+k,{onload:function(){this.fireEvent("loaded");}.bind(g)}).inject(g);},this);e.set("events",{scroll:function(h,k){var f=this.getCoordinates();var l=this.getElement("ul").getPosition();var o=this.retrieve("props");var i=o[3],s,p=o[0],u=o[2],q;var t=this.getElement("ul").get("tween",{property:p});if($chk(h)){var r=this.getElements("li")[h].getCoordinates();s=f[p]+(f[u]/2)-(r[u]/2)-r[p];q=(l[i]-f[p]+s).limit(this.retrieve("limit"),0);if(k){t.set(q);}else{t.start(q);}}else{var g=f[o[2]]/3,m=this.retrieve("page"),j=-0.2;if(m[i]<(f[p]+g)){s=(m[i]-f[p]-g)*j;}else{if(m[i]>(f[p]+f[u]-g)){s=(m[i]-f[p]-f[u]+g)*j;}}if(s){q=(l[i]-f[p]+s).limit(this.retrieve("limit"),0);t.set(q);}}}.bind(e),update:function(f){var g=this.slideshow.retrieve("thumbnails");g.getElements("a").each(function(h,j){if(j==this.slide){if(!h.retrieve("active",false)){h.store("active",true);var l=this.classes.get("thumbnails","active");if(f){h.get("morph").set(l);}else{h.morph(l);}}}else{if(h.retrieve("active",true)){h.store("active",false);var k=this.classes.get("thumbnails","inactive");if(f){h.get("morph").set(k);}else{h.morph(k);}}}},this);if(!g.retrieve("mouseover")){g.fireEvent("scroll",[this.slide,f]);}}.bind(this)});var d=e.getCoordinates();e.store("props",(d.height>d.width)?["top","bottom","height","y"]:["left","right","width","x"]);var b=function(f){var g=this.getCoordinates();if(f.page.x>g.left&&f.page.x<g.right&&f.page.y>g.top&&f.page.y<g.bottom){this.store("page",f.page);if(!this.retrieve("mouseover")){this.store("mouseover",true);this.store("timer",function(){this.fireEvent("scroll");}.periodical(50,this));}}else{if(this.retrieve("mouseover")){this.store("mouseover",false);$clear(this.retrieve("timer"));}}}.bind(e);this.events.mousemove.push(b);document.addEvent("mousemove",b);this.slideshow.store("thumbnails",e);}});
