/*
 * @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={};}this.RokGallery.Showcase=new Class({options:{onJump:function(d){this.animation.index=this.current;
this.animation.setBackground(this.slices[d].getElement("img").getProperty("src"));this.animation.setAnimation(this.options.animation);this.animation.play();
if(this.captions.length){this.adjustHeight(d);this.captionsAnimation.setAnimation(this.options.captions.animation);this.captionsAnimation.setFromTo(this.current,d);
this.captionsAnimation.play();}},animation:"random",duration:500,imgpadding:0,captions:{fixedheight:false,animated:true,animation:"crossfade"},autoplay:{enabled:true,delay:5000,complete:function(){this.progress.reset();
this.next();}}},initialize:function(e,d){this.setOptions(d);this.element=$(e)||$E(e)||null;this.rtl=document.body.getStyle("direction")=="rtl";if(!this.element){throw new Error('The element "'+e+'" has not been found in the page.');
}this.current=0;this.container=$E(".rg-sc-slice-container",this.element);this.main=$E(".rg-sc-main");this.imglist=$E(".rg-sc-img-list");this.slices=$ES(".rg-sc-slice",this.element);
this.captions=$ES(".rg-sc-info",this.element);this.arrows=$ES(".rg-sc-controls .next, .rg-sc-controls .prev",this.element);this.loaderBar=$E(".rg-sc-loader",this.element);
this.progressBar=$E(".rg-sc-progress",this.element);if(this.options.autoplay.enabled){var f=this.progressBar;if(!f){f=new Element("div",{styles:{display:"none",position:"absolute"}}).inject(document.body);
}this.progress=new RokGallery.Showcase.Progress(f,{duration:this.options.autoplay.delay,width:this.loaderBar?this.loaderBar.getSize().size.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();}this.jump(0,true);},setup:function(){this.animation=new RokGallery.Showcase.Animations(this.element,{container:this.imglist,width:this.container.getSize().size.x,height:this.container.getSize().size.y,duration:this.options.duration,transition:Fx.Transitions.Quad.easeInOut,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.captionsAnimation=new RokGallery.Showcase.CaptionsAnimations(this.captions,{duration:this.options.duration});if(this.options.captions.fixedheight){var d=0;
this.captions.each(function(e){if(e.offsetHeight>d){d=e.offsetHeight;}});this.main.setStyle("height",d);}}this.fireEvent("onSetup");},setArrows:function(){var d;
this.arrows.each(function(e){d=e.className.contains("next")?"next":"previous";e.addEvent("click",this[d].bind(this));},this);},adjustHeight:function(h){if(this.options.captions.fixedheight){return;
}var g=this.captions[h].offsetHeight,f=this.container.getSize().size.y,e=this.main.offsetHeight,d=Math.max(g,f);if(e!=d){if(this.options.captions.animated){this.main.effect("height",{duration:this.options.duration,transition:Fx.Transitions.Quad.easeInOut}).start(d);
}else{this.main.setStyle("height",d);}}},next:function(){var d=this.getNext();this.jump(d);if(this.options.autoplay.enabled&&!this.progress.isPaused){this.progress.play();
}return this;},previous:function(){var d=this.getPrevious();this.jump(d);return this;},jump:function(d,e){if(d==this.current&&!e){return this;}if(this.animation.timer){return this;
}this.fireEvent("onJump",d);if(this.scrollerContainer){this.scroller.setActive(d);this.scroller.toThumb(d);}this.current=d;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.Showcase.implement(new Events,new Options);this.RokGallery.Showcase.Progress=Fx.Style.extend({options:{transition:Fx.Transitions.linear,fps:24,width:100},initialize:function(e,d){this.element=$(e);
this.isPaused=false;this.property="width";this.reset();this.setOptions(d);this.parent(d);},increase:function(){if(this.element){this.element.setStyle(this.property,this.css.getValue(this.now,this.options.unit,this.property));
}},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;},stopTimer:function(){if(!this.timer){return false;}this.time=$time()-this.time;
this.timer=$clear(this.timer);return true;},startTimer:function(){if(this.timer){return false;}this.time=$time()-this.time;this.timer=this.step.periodical(Math.round(1000/this.options.fps),this);
return true;}});this.RokGallery.Showcase.Animations=Fx.Base.extend({options:{duration:1000,transition:Fx.Transitions.Expo.easeInOut,animation:"crossfade",container:"",background:"",width:0,height:0,blinds:24,boxes:{rows:10,cols:24}},animations:{},animationsKeys:[],initialize:function(e,d){this.isPaused=false;
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.parent(d);this.setOptions(d);this.container=new Element("div",{"class":"rg-sc-slice-animations"}).inject(this.options.container);
this.setAnimation(this.options.animation);},setNow:function(){for(var f in this.from){var j=this.from[f],h=this.to[f],e=this.css[f],d=this.now[f]={};for(var g in j){d[g]=e[g].getNow(j[g],h[g],this);
}}},set:function(k){var e={};this.css={};for(var g in k){var j=k[g],f=this.css[g]={},d=e[g]={};for(var h in j){f[h]=Fx.CSS.select(h,j[h]);d[h]=f[h].parse(j[h]);
}}return this.parent(e);},start:function(g){if(this.timer&&this.options.wait){return this;}this.now={};this.css={};var m={},n={};for(var h in g){var k=g[h],d=m[h]={},l=n[h]={},f=this.css[h]={};
for(var e in k){var j=Fx.CSS.parse(this.elements[h],e,k[e]);d[e]=j.from;l[e]=j.to;f[e]=j.css;}}return this.parent(m,n);},increase:function(){for(var f in this.now){var d=this.now[f],e=this.css[f];
for(var g in d){this.elements[f].setStyle(g,e[g].getValue(d[g],this.options.unit,g));}}},build:function(d){this.container.empty();this.slides=[];this["build"+d.capitalize()]();
this.elements=$$(this.slides);},addAnimation:function(d,e){if(!this.animations[d]){this.animations[d]=e;}this.animationsKeys.include(d);},setAnimation:function(d){if(d=="random"){d=this.animationsKeys.getRandom();
}if(!this.animations[d]){this.setOptions({animation:"crossfade"});}for(var e in this.animations[d]){this[e]=this.animations[d][e];}if(!this.animations[d]["blinds"]){this.blinds=this.options.blinds;
}if(!this.animations[d]["boxes"]){this.boxes=this.options.boxes;}if(!this.animations[d]["reorder"]){this.reorder=false;}this.build(this.type);},buildBlinds:function(){var f={width:this.options.width,height:this.options.height},e=this.background,d=this.blinds,g=Math.round(f.width/d);
this.sliceSize={width:g,height:f.height};(d).times(function(j){var h=((g+(j*g))-g);var k=new Element("div",{styles:{opacity:0,position:"absolute",top:0,left:(g*j)+"px",height:f.height+"px",width:(j==d-1)?f.width-(g*j):g,background:"url("+e+") no-repeat -"+h+"px 0%"}}).inject(this.container);
this.slides.push(k);}.bind(this));},buildBoxes:function(){var f={width:this.options.width,height:this.options.height},e=this.background,d=this.boxes,g={width:Math.round(f.width/d.cols),height:Math.round(f.height/d.rows)};
this.sliceSize={width:g.width,height:g.height};(d.rows).times(function(h){(d.cols).times(function(j){var i={x:(g.width+(j*g.width))-g.width,y:(g.height+(h*g.height))-g.height};
var k=new Element("div",{styles:{opacity:0,position:"absolute",top:(g.height*h)+"px",left:(g.width*j)+"px",width:(j==d.cols-1)?f.width-(g.width*j):g.width,height:g.height,background:"url("+e+") no-repeat -"+i.x+"px -"+i.y+"px"}}).inject(this.container);
this.slides.push(k);}.bind(this));}.bind(this));},setBackground:function(d){this.background=d;},reset:function(d,e){var f={};(this.elements.length).times(function(g){f[g]=d;
},this);this.set(f,e);},play:function(e){var f={};e=e||this.properties;if(this.direction=="left"){this.elements.reverse();}if(this.reorder){this.elements=this.reorder.pass([this.elements],this)();
}for(var g in e){switch(typeof e[g]){case"object":case"array":var d=e[g];d.each(function(j,h){if(typeof j=="string"){e[g][h]=j.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":e[g]=e[g].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(h){f[h]=e;});this.start(f);return this;},clean:function(){this.slides.each(function(d){d.remove();});this.slides=[];
return this;}});this.RokGallery.Showcase.CaptionsAnimations=Fx.Elements.extend({options:{duration:1000,transition:Fx.Transitions.Quad.easeInOut,wait:false,animation:"crossfade"},animations:{},animationsKeys:[],initialize:function(e,d){this.parent(d);
this.isPaused=false;this.elements=this.subject=$$(e);this.properties={};this.setAnimation(this.options.animation);this.setFromTo(0,0);},addAnimation:function(d,e){if(!this.animations[d]){this.animations[d]=e;
}this.animationsKeys.include(d);},setAnimation:function(d){if(d=="random"){d=this.animationsKeys.getRandom();}if(!this.animations[d]){this.setOptions({animation:"crossfade"});
}this.properties={};for(var e in this.animations[d]){this.properties[e]=this.animations[d][e];}},setFromTo:function(e,d){this.fromCaption=this.elements[e]?e:0;
this.toCaption=this.elements[d]?d:0;},reset:function(d,e){var f={};(this.elements.length).times(function(g){f[g]=d;},this);this.set(f,e);},play:function(e){var i={},h={},g={};
e=e||this.properties;var f={width:this.elements[this.fromCaption].offsetWidth,height:this.elements[this.fromCaption].offsetHeight},d={width:this.elements[this.toCaption].offsetWidth,height:this.elements[this.toCaption].offsetHeight};
if(this.fromCaption!=this.toCaption){i[this.fromCaption]=e.current;i[this.toCaption]=e.next;}else{i[this.toCaption]=e.next;}for(var j in i[this.fromCaption]){i[this.fromCaption][j].each(function(l,k){if(typeof l=="string"){i[this.fromCaption][j][k]=l.replace("%height2%",f.width*2).replace("%width2%",f.width*2).replace("%height%",f.height).replace("%width%",f.width).toInt();
}},this);}for(var j in i[this.toCaption]){i[this.toCaption][j].each(function(l,k){if(typeof l=="string"){i[this.toCaption][j][k]=l.replace("%height2%",d.height*2).replace("%width2%",d.width*2).replace("%height%",d.height).replace("%width%",d.width).toInt();
}},this);}this.start(i);return this;}});var a={crossfade:{current:{opacity:[1,0]},next:{opacity:[0,1]}},topdown:{current:{opacity:[1,0],top:[0,"%height%"]},next:{opacity:[0,1],top:["-%height%",0]}},bottomup:{current:{opacity:[1,0],top:[0,"-%height%"]},next:{opacity:[0,1],top:["%height2%",0]}}};
var c={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(g){var f=[];
for(var e=0,d=g.length-1;e<g.length/2;e++,d--){f.push(g[e]);f.push(g[d]);}return $$(f);},delay:6,properties:{opacity:[0,1],width:[0,"%width%"],height:[0,"%height%"]}},boxesRandom:{type:"boxes",direction:"right",reorder:function(e){var d=e;
d.sort(function(){return 0.5-Math.random();});return $$(d);},delay:4,properties:{opacity:[0,1]}},blindsMirrorIn:{type:"blinds",direction:"left",reorder:function(g){var f=[];
for(var e=0,d=g.length-1;e<g.length/2;e++,d--){f.push(g[e]);f.push(g[d]);}return $$(f);},delay:50,properties:{opacity:[0,1],width:[0,"%width%"],height:[0,"%height%"]}},blindsMirrorOut:{type:"blinds",direction:"left",reorder:function(g){var f=[];
for(var e=0,d=g.length-1;e<g.length/2;e++,d--){f.push(g[e]);f.push(g[d]);}f.reverse();return $$(f);},delay:50,properties:{opacity:[0,1],width:[0,"%width%"],height:[0,"%height%"]}},blindsRandom:{type:"blinds",direction:"right",reorder:function(e){var d=e;
d.sort(function(){return 0.5-Math.random();});return $$(d);},delay:35,properties:{opacity:[0,1]}}};for(var b in c){this.RokGallery.Showcase.Animations.prototype.addAnimation(b,c[b]);
}for(var b in a){this.RokGallery.Showcase.CaptionsAnimations.prototype.addAnimation(b,a[b]);}}());
