/*
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2011 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */

(function(){if(typeof this.RokGallery=="undefined"){this.RokGallery={};}Element.implement({sumStyles:function(){var e=this.getStyles(arguments),d=0;for(var c in e){d+=e[c].toInt();
}return d;}});Elements.implement({sumStyles:function(d){var c=0;this.each(function(e){c+=e.sumStyles(d);},this);return c;}});this.RokGallery.Slideshow=new Class({Implements:[Options,Events],options:{onJump:function(c){this.animation.index=this.current;
this.animation.setBackground(this.slices[c].getElement("img").get("src"));this.animation.setAnimation(this.options.animation);this.animation.play();if(this.captions.length){if(this.current==c){this.captions[c].fade("in");
}else{this.captions[this.current].fade("out");this.captions[c].fade("in");}}},animation:"random",duration:500,autoplay:{enabled:true,delay:5000,complete:function(){this.progress.reset();
this.next();}}},initialize:function(d,c){this.setOptions(c);this.element=document.id(d)||document.getElement(d)||null;this.rtl=document.body.getStyle("direction")=="rtl";
if(!this.element){throw new Error('The element "'+d+'" has not been found in the page.');}this.current=0;this.container=this.element.getElement(".rg-ss-slice-container");
this.slices=this.element.getElements(".rg-ss-slice");this.captions=this.element.getElements(".rg-ss-info");this.arrows=this.element.getElements(".rg-ss-controls .next, .rg-ss-controls .prev");
this.scrollerContainer=this.element.getElement(".rg-ss-thumb-scroller");this.loaderBar=this.element.getElement(".rg-ss-loader");this.progressBar=this.element.getElement(".rg-ss-progress");
if(this.options.autoplay.enabled){this.progress=new RokGallery.Slideshow.Progress(this.progressBar,{duration:this.options.autoplay.delay,width:this.loaderBar?this.loaderBar.getSize().x:0,onComplete:this.options.autoplay.complete.bind(this)}).play();
this.bounds={progress:{mouseenter:this.progress.pause.bind(this.progress),mouseleave:this.progress.resume.bind(this.progress)}};this.element.addEvents(this.bounds.progress);
}else{if(this.loaderBar){this.loaderBar.setStyle("display","none");}}this.setup();if(this.arrows.length){this.setArrows();}if(this.scrollerContainer){this.setNavigation();
}this.jump(0,true);},setup:function(){this.animation=new RokGallery.Slideshow.Animations(this.element,{container:this.container,width:this.container.getSize().x,height:this.container.getSize().y,duration:this.options.duration,transition:"quad:in:out",onStart:function(){if(this.options.autoplay.enabled){this.progress.pause();
}}.bind(this),onComplete:function(){this.slices[this.current].setStyle("display","block");if(this.current!=this.animation.index){this.slices[this.animation.index].setStyle("display","none");
}this.animation.clean();if(this.options.autoplay.enabled){this.progress.play();}}.bind(this)});if(this.captions.length){this.captions.setStyles({display:"block",opacity:0,visibility:"hidden"});
this.captions.set("tween",{duration:this.options.duration,transition:"quad:in:out"});}this.fireEvent("setup");},setArrows:function(){["next","previous"].each(function(d,c){this.arrows[c].addEvent("click",this[d].bind(this));
},this);},setNavigation:function(){this.scroller=new RokGallery.Slideshow.Thumbnails(this.element,this,{});},next:function(){var c=this.getNext();this.jump(c);
if(this.options.autoplay.enabled&&!this.progress.isPaused){this.progress.play();}return this;},previous:function(){var c=this.getPrevious();this.jump(c);
return this;},jump:function(c,d){if(c==this.current&&!d){return this;}if(this.animation.timer){return this;}this.fireEvent("jump",c);if(this.scrollerContainer){this.scroller.setActive(c);
this.scroller.toThumb(c);}this.current=c;return this;},getNext:function(){return(this.current+1>=this.slices.length)?0:this.current+1;},getPrevious:function(){return(this.current-1<0)?this.slices.length-1:this.current-1;
}});this.RokGallery.Slideshow.Progress=new Class({Extends:Fx,options:{transition:"linear",fps:24,width:100},initialize:function(d,c){this.element=document.id(d);
this.isPaused=false;this.parent(c);},set:function(c){if(this.element){this.element.setStyle("width",c);}return this;},reset:function(){this.set(0);return this;
},play:function(){this.start(0,this.options.width);return this;},pause:function(){this.isPaused=true;this.stopTimer();return this;},resume:function(){this.isPaused=false;
this.startTimer();return this;}});this.RokGallery.Slideshow.Thumbnails=new Class({Implements:[Options,Events],options:{onClickElement:function(c,d){if(this.base.animation.timer){return this;
}this.base.jump(d);this.setActive(d);return this;},scroller:{duration:300,transition:Fx.Transitions.Expo.easeInOut}},initialize:function(d,e,c){this.setOptions(c);
this.base=e;this.element=d;this.thumbSize=0;this.wrapper=this.element.getElement(".rg-ss-navigation-container");this.container=this.wrapper.getElement(".rg-ss-thumb-scroller");
this.arrows=this.wrapper.getElements(".rg-ss-arrow-left, .rg-ss-arrow-right");this.list=this.wrapper.getElement(".rg-ss-thumb-list");this.thumbsWrapper=this.wrapper.getElements(".rg-ss-thumb-list .rg-ss-thumb");
this.thumbs=this.wrapper.getElements(".rg-ss-thumb-list .rg-ss-thumb img");this.arrowsSize=this.arrows.sumStyles("width");this.scroller=new Fx.Scroll(this.container,this.options.scroller);
this.scroller.set(0,0);this.setup();this.attach();return this;},attach:function(){this.thumbsWrapper.each(function(c,d){c.bounds={click:this.clickElement.bindWithEvent(this,c)};
c.addEvents(c.bounds);},this);this.arrows.each(function(d,c){d.bounds={click:this.arrowsClick.bindWithEvent(this,[d,(!c?"left":"right")])};d.addEvent("dblclick",function(f){f.stop();
});d.addEvents(d.bounds);},this);},detach:function(){this.thumbsWrapper.each(function(c,d){c.removeEvents(c.bounds);},this);this.arrows.removeEvents(this.bounds.arrows);
},arrowsClick:function(e,f,g){e.stop();var c=this.container.scrollLeft+(g=="left"?-this.thumbSize:+this.thumbSize),d=this.container.scrollWidth-this.container.offsetWidth,h=this.container.scrollLeft+this.thumbSize;
if(d-h<this.thumbSize){c+=d-h;}if(h-this.thumbSize*2<this.thumbSize&&g=="left"){c=0;}this.scroller.scrollTo(c,0);},toThumb:function(c){this.scroller.scrollTo(this.thumbSize*c,0);
},clickElement:function(e,c){if(e){e.stop();}var d=this.thumbsWrapper.indexOf(c);this.fireEvent("clickElement",[c,d]);},setup:function(){var c=0,d=[];["padding-%x","border-%x-width","margin-%x"].each(function(e){["left","right"].each(function(f){d.push(e.replace(/%x/g,f));
});});this.thumbs.each(function(e,f){this.thumbSize=this.thumbsWrapper[f].sumStyles(d)+e.get("width").toInt();c+=this.thumbSize;},this);this.list.setStyle("width",c);
if(c<this.wrapper.offsetWidth-this.arrowsSize){this.wrapper.removeClass("arrows-enabled");}else{this.wrapper.addClass("arrows-enabled");}},setActive:function(c){this.thumbsWrapper.removeClass("active");
this.thumbsWrapper[c].addClass("active");}});this.RokGallery.Slideshow.Animations=new Class({Extends:Fx.CSS,options:{duration:1000,transition:"expo:in:out",animation:"crossfade",container:"",background:"",width:0,height:0,blinds:24,boxes:{rows:10,cols:24}},animations:{},animationsKeys:[],initialize:function(d,c){this.isPaused=false;
this.parent(c);this.slides=[];this.originalDuration=this.options.duration;this.delay=0;this.type="blinds";this.background=this.options.background;this.blinds=1;
this.boxes={rows:1,cols:1};this.properties={};this.direction="right";this.reorder=false;this.container=new Element("div",{"class":"rg-ss-slice-animations"}).inject(this.options.container);
this.setAnimation(this.options.animation);},build:function(c){this.container.empty();this.slides.empty();this["build"+c.capitalize()]();this.elements=$$(this.slides);
},addAnimation:function(c,d){if(!this.animations[c]){this.animations[c]=d;}this.animationsKeys.include(c);},setAnimation:function(c){if(c=="random"){c=this.animationsKeys.getRandom();
}if(!this.animations[c]){this.setOptions({animation:"crossfade"});}for(var d in this.animations[c]){this[d]=this.animations[c][d];}if(!this.animations[c]["blinds"]){this.blinds=this.options.blinds;
}if(!this.animations[c]["boxes"]){this.boxes=this.options.boxes;}if(!this.animations[c]["reorder"]){this.reorder=false;}this.build(this.type);},buildBlinds:function(){var e={width:this.options.width,height:this.options.height},d=this.background,c=this.blinds,f=Math.round(e.width/c);
this.sliceSize={width:f,height:e.height};(c).times(function(h){var g=((f+(h*f))-f);var j=new Element("div",{styles:{opacity:0,position:"absolute",top:0,left:(f*h)+"px",height:e.height+"px",width:(h==c-1)?e.width-(f*h):f,background:"url("+d+") no-repeat -"+g+"px 0%"}}).inject(this.container);
this.slides.push(j);},this);},buildBoxes:function(){var e={width:this.options.width,height:this.options.height},d=this.background,c=this.boxes,f={width:Math.round(e.width/c.cols),height:Math.round(e.height/c.rows)};
this.sliceSize={width:f.width,height:f.height};(c.rows).times(function(g){(c.cols).times(function(i){var h={x:(f.width+(i*f.width))-f.width,y:(f.height+(g*f.height))-f.height};
var j=new Element("div",{styles:{opacity:0,position:"absolute",top:(f.height*g)+"px",left:(f.width*i)+"px",width:(i==c.cols-1)?e.width-(f.width*i):f.width,height:f.height,background:"url("+d+") no-repeat -"+h.x+"px -"+h.y+"px"}}).inject(this.container);
this.slides.push(j);},this);},this);},setBackground:function(c){this.background=c;},compute:function(j,k,l){var e={};for(var f in j){var c=j[f],g=k[f],h=e[f]={};
for(var d in c){h[d]=this.parent(c[d],g[d],l);}}return e;},set:function(e,g){var c=this.buffer=0;for(var f in e){if(!this.elements[f]){continue;}var d=e[f];
for(var h in d){this.render.delay(g?0:c,this,[this.elements[f],h,d[h],this.options.unit]);}c+=this.delay;}this.buffer=c;return this;},step:function(){var d=$time();
var c=(this.delay||1)*this.slides.length+this.options.duration;if(d<this.time+this.options.duration){var e=this.transition((d-this.time)/this.options.duration);
this.set(this.compute(this.from,this.to,e));}else{if(d>this.time+c){this.set(this.compute(this.from,this.to,1));this.complete();}}},start:function(e){if(!this.check(e)){return this;
}var k={},l={};for(var f in e){if(!this.elements[f]){continue;}var h=e[f],c=k[f]={},j=l[f]={};for(var d in h){var g=this.prepare(this.elements[f],d,h[d]);
c[d]=g.from;j[d]=g.to;}}return this.parent(k,l);},reset:function(c,d){var e={};(this.elements.length).times(function(f){e[f]=c;},this);this.set(e,d);},play:function(d){var e={};
d=d||this.properties;if(this.direction=="left"){this.elements.reverse();}if(this.reorder){this.elements=this.reorder.bind(this,[this.elements])();}for(var f in d){switch(typeof d[f]){case"object":case"array":var c=d[f];
c.each(function(h,g){if(typeof h=="string"){d[f][g]=h.replace("%height2%",this.sliceSize.height*2).replace("%width2%",this.sliceSize.width*2).replace("%height%",this.sliceSize.height).replace("%width%",this.sliceSize.width).toInt();
}},this);break;case"string":d[f]=d[f].replace("%height2%",this.sliceSize.height*2).replace("%width2%",this.sliceSize.width*2).replace("%height%",this.sliceSize.height).replace("%width%",this.sliceSize.width).toInt();
break;}}(this.elements.length).times(function(g){e[g]=d;},this);this.start(e);return this;},pause:function(){this.isPaused=true;this.stopTimer();return this;
},resume:function(){this.isPaused=false;this.startTimer();return this;},clean:function(){$$(this.slides).dispose();this.slides.empty();return this;}});
var b={crossfade:{type:"blinds",blinds:1,delay:0,direction:"right",properties:{opacity:[0,1]}},blindsRight:{type:"blinds",direction:"right",delay:50,properties:{opacity:[0,1]}},blindsLeft:{type:"blinds",direction:"left",delay:50,properties:{opacity:[0,1]}},blindsDownLeft:{type:"blinds",direction:"left",delay:50,properties:{width:[0,"%width%"],height:[0,"%height%"],opacity:[0,1]}},blindsDownRight:{type:"blinds",direction:"right",delay:50,properties:{width:[0,"%width%"],height:[0,"%height%"],opacity:[0,1]}},boxesOpacityRight:{type:"boxes",direction:"right",delay:6,properties:{opacity:[0,1]}},boxesOpacityLeft:{type:"boxes",direction:"left",delay:6,properties:{opacity:[0,1]}},slideDown:{type:"boxes",boxes:{cols:1,rows:1},direction:"right",delay:200,properties:{height:[0,"%height%"],opacity:[0,1]}},slideUp:{type:"boxes",boxes:{cols:1,rows:1},direction:"right",delay:200,properties:{top:["%height%",0],opacity:[0,1]}},slideLeft:{type:"boxes",boxes:{cols:1,rows:1},direction:"left",delay:200,properties:{left:["-%width%",0],opacity:[0,1]}},slideRight:{type:"boxes",boxes:{cols:1,rows:1},direction:"right",delay:200,properties:{left:["%width%",0],opacity:[0,1]}},boxesRight:{type:"boxes",direction:"right",delay:6,properties:{width:[0,"%width%"],height:[0,"%height%"],opacity:[0,1]}},boxesLeft:{type:"boxes",direction:"left",delay:6,properties:{width:[0,"%width%"],height:[0,"%height%"],opacity:[0,1]}},boxesMirror:{type:"boxes",direction:"left",reorder:function(f){var e=[];
for(var d=0,c=f.length-1;d<f.length/2;d++,c--){e.push(f[d]);e.push(f[c]);}return $$(e);},delay:6,properties:{opacity:[0,1],width:[0,"%width%"],height:[0,"%height%"]}},boxesRandom:{type:"boxes",direction:"right",reorder:function(d){var c=d;
c.sort(function(){return 0.5-Math.random();});return $$(c);},delay:4,properties:{opacity:[0,1]}},blindsMirrorIn:{type:"blinds",direction:"left",reorder:function(f){var e=[];
for(var d=0,c=f.length-1;d<f.length/2;d++,c--){e.push(f[d]);e.push(f[c]);}return $$(e);},delay:50,properties:{opacity:[0,1],width:[0,"%width%"],height:[0,"%height%"]}},blindsMirrorOut:{type:"blinds",direction:"left",reorder:function(f){var e=[];
for(var d=0,c=f.length-1;d<f.length/2;d++,c--){e.push(f[d]);e.push(f[c]);}e.reverse();return $$(e);},delay:50,properties:{opacity:[0,1],width:[0,"%width%"],height:[0,"%height%"]}},blindsRandom:{type:"blinds",direction:"right",reorder:function(d){var c=d;
c.sort(function(){return 0.5-Math.random();});return $$(c);},delay:35,properties:{opacity:[0,1]}}};for(var a in b){this.RokGallery.Slideshow.Animations.prototype.addAnimation(a,b[a]);
}}());
