var NivooSlider=new Class({Implements:[Events,Options],caption:null,children:null,containerSize:0,count:0,currentSlide:0,currentImage:"",effects:{horizontal:["fade","fold","sliceLeftUp","sliceLeftDown","sliceLeftRightDown","sliceLeftRightUp","sliceRightDown","sliceRightUp","wipeDown","wipeUp"],vertical:["fade","fold","sliceDownLeft","sliceDownRight","sliceUpDownLeft","sliceUpDownRight","sliceUpLeft","sliceUpRight","wipeLeft","wipeRight"]},holder:null,hover:false,interval:null,paused:false,running:false,totalSlides:0,options:{animSpeed:500,autoPlay:true,directionNav:true,directionNavHide:false,directionNavWidth:"20%",effect:"sliceDown",interval:3000,orientation:"vertical",pauseOnHover:true,slices:15,preLoadImages:false},initialize:function(a,b){this.container=$(a);this.setOptions(b);this.initSlider();this.createSlices();if(this.options.autoPlay){this.play()}},getImages:function(){return this.holder.getElements("img")},getSlices:function(){return this.holder.getElements(".nivoo-slice")},setBackgroundImage:function(){this.holder.setStyle("background-image","url("+this.currentImage.get("src")+")")},setCaptionText:function(a){this.caption.set("text",a)},setLink:function(){var a=this.currentImage.getParent();if(a.get("tag")=="a"){var b=a.clone(false).cloneEvents(a);b.replaces(this.linkHolder);this.linkHolder=b;this.linkHolder.addClass("nivoo-link").setStyle("display","block")}else{this.linkHolder.setStyle("display","none")}},initSlider:function(){this.holder=new Element("div.nivoo-slider-holder").adopt(this.container.getChildren()).inject(this.container);this.containerSize=this.holder.getSize();this.children=this.getImages();this.totalSlides=this.children.length;this.children.setStyle("display","none");this.currentImage=this.children[0];this.createLinkHolder();this.setLink();this.holder.setStyle("background-image","url("+this.currentImage.get("src")+")");this.createCaption();this.showCaption();if(this.options.pauseOnHover&&this.options.autoPlay){this.holder.addEvents({mouseenter:function(){this.pause()}.bind(this),mouseleave:function(){this.play()}.bind(this)})}if(this.options.directionNav){this.createDirectionNav()}},createCaption:function(){this.caption=new Element("p",{styles:{opacity:0}}).inject(this.holder);this.caption.store("fxInstance",new Fx.Morph(this.caption,{duration:200,wait:false}))},createDirectionNav:function(){var c=this.options.directionNavWidth;var a={height:this.containerSize.y,width:c};var d=new Element("div.direction-nav-left",{styles:a}).inject(this.holder);var b=new Element("div.direction-nav-right",{styles:a}).inject(this.holder);this.leftNav=new Element("a",{events:{click:function(f){f.stop();if(this.options.autoPlay){this.pause();if(!this.options.pauseOnHover){this.play()}}this.previous()}.bind(this)},href:"#",styles:{height:a.height}}).inject(d);this.rightNav=new Element("a",{events:{click:function(f){f.stop();if(this.options.autoPlay){this.pause();if(!this.options.pauseOnHover){this.play()}}this.next()}.bind(this)},href:"#",styles:{height:a.height}}).inject(b);if(this.options.directionNavHide){$$(this.leftNav,this.rightNav).setStyle("opacity",0);this.holder.addEvents({mouseout:function(){$$(this.leftNav,this.rightNav).fade(0)}.bind(this),mouseover:function(){$$(this.leftNav,this.rightNav).fade(1)}.bind(this)})}},createLinkHolder:function(){this.linkHolder=new Element("a.nivoo-link",{href:"#"}).inject(this.holder)},createSlices:function(){if(["fade","wipeLeft","wipeRight"].contains(this.options.effect)){this.options.slices=1}var a={x:(this.containerSize.x/this.options.slices).round(),y:(this.containerSize.y/this.options.slices).round()};this.options.slices.each(function(d){var f=new Element("div.nivoo-slice").inject(this.holder);var c={left:this.options.orientation=="vertical"?a.x*d:0,top:this.options.orientation=="horizontal"?a.y*d:0};if(this.options.orientation=="horizontal"){var b=d==this.options.slices-1?this.containerSize.y-(a.y*d):a.y;var e="100%";f.setStyles({height:b,top:c.top,width:e})}else{var b=0;var e=d==this.options.slices-1?this.containerSize.x-(a.x*d):a.x;f.setStyles({left:c.left,width:e})}f.store("fxInstance",new Fx.Morph(f,{duration:this.options.animSpeed})).store("coordinates",Object.merge(c,{height:b,width:e}))},this)},hideCaption:function(){this.caption.retrieve("fxInstance").start({bottom:this.caption.getHeight()*-1,opacity:0.5})},showCaption:function(){var a=this.currentImage.get("title");if(!a){this.hideCaption();return}this.setCaptionText(a);this.caption.retrieve("fxInstance").start({bottom:0,opacity:1})},next:function(){this.currentSlide++;if(this.currentSlide==this.totalSlides){this.currentSlide=0}this.slide()},pause:function(){window.clearInterval(this.interval)},play:function(){this.interval=this.next.periodical(this.options.interval,this)},previous:function(){if(this.options.autoPlay){this.pause();if(!this.options.pauseOnHover){this.play()}}this.currentSlide--;if(this.currentSlide<0){this.currentSlide=(this.totalSlides-1)}this.slide()},slide:function(c){if(this.running){return}if(c!=undefined){this.currentSlide=c}this.currentImage=this.children[this.currentSlide];this.setLink();this.showCaption();var g=this.getSlices();var a=0;var b=this.options.orientation;g.each(function(j){var i=j.retrieve("coordinates");j.setStyles({background:"url("+this.currentImage.get("src")+") no-repeat -"+i.left+"px "+i.top*-1+"px",bottom:"",height:i.height,left:i.left,opacity:0,right:"",top:i.top,width:i.width});var h=b=="horizontal"?"width":"height";j.setStyle(h,0)},this);this.start();this.running=true;var d=this.options.effect;if(d=="random"){d=this.effects[b].getRandom()}if(["sliceDownRight","sliceDownLeft"].contains(d)){if(d=="sliceDownLeft"){g=g.reverse()}g.each(function(h){h.setStyle("top",0);this.animate.delay(100+a,this,[h,{height:this.containerSize.y,opacity:1}]);a+=50},this)}else{if(["sliceUpRight","sliceUpLeft"].contains(d)){if(d=="sliceUpLeft"){g=g.reverse()}g.each(function(i){var h=i.retrieve("fxInstance");i.setStyle("bottom",0);this.animate.delay(100+a,this,[i,{height:this.containerSize.y,opacity:1}]);a+=50},this)}else{if(["sliceUpDownRight","sliceUpDownLeft"].contains(d)){if(d=="sliceUpDownLeft"){g=g.reverse()}g.each(function(j,h){if(h%2==0){j.setStyle("top",0)}else{j.setStyles({bottom:0,top:""})}this.animate.delay(100+a,this,[j,{height:this.containerSize.y,opacity:1}]);a+=50},this)}else{if(["wipeLeft","wipeRight"].contains(d)){var e={height:this.containerSize.y,opacity:1,width:0};if(d=="wipeRight"){Object.append(e,{backgroundPosition:"top right",left:"",right:0})}var f=g[0];f.setStyles(e);this.animate(f,{width:this.containerSize.x},true)}else{if(["sliceLeftUp","sliceLeftDown","sliceRightDown","sliceRightUp"].contains(d)){if(d=="sliceLeftUp"||d=="sliceRightUp"){g=g.reverse()}if(d=="sliceRightDown"||d=="sliceRightUp"){g.setStyles({left:"",right:0})}else{g.setStyles({left:0,right:""})}g.each(function(h){this.animate.delay(100+a,this,[h,{opacity:1,width:this.containerSize.x}]);a+=50},this)}else{if(["sliceLeftRightDown","sliceLeftRightUp"].contains(d)){if(d=="sliceLeftRightUp"){g=g.reverse()}g.each(function(j,h){if(h%2==0){j.setStyles({left:0,right:""})}else{j.setStyles({left:"",right:0})}this.animate.delay(100+a,this,[j,{opacity:1,width:this.containerSize.x}]);a+=50},this)}else{if(["wipeDown","wipeUp"].contains(d)){var e={height:0,opacity:1,width:this.containerSize.x};if(d=="wipeUp"){Object.append(e,{backgroundPosition:"bottom left",bottom:0,top:""})}var f=g[0];f.setStyles(e);this.animate(f,{height:this.containerSize.y},true)}else{if(d=="fold"){g.each(function(i){var h={opacity:1};if(b=="horizontal"){h.height=i.getHeight();i.setStyles({height:0,width:this.containerSize.x})}else{h.width=i.getWidth();i.setStyles({height:this.containerSize.y,top:0,width:0})}this.animate.delay(100+a,this,[i,h]);a+=50},this)}else{var f=g[0];f.setStyles({height:this.containerSize.y,width:this.containerSize.x});this.animate(f,{opacity:1},true)}}}}}}}}},animate:function(e,d,b){var a=e.retrieve("fxInstance");var c=b!=undefined&&b==true;a.start(d).chain(function(){this.count++;if(this.count==this.options.slices||c){this.running=false;this.finish();this.setBackgroundImage();this.count=0}}.bind(this))},finish:function(){this.fireEvent("finish")},start:function(){this.fireEvent("start")}});
