/*
  **************************************************************

 Script		: slideShow
 Version		: 1.3
 Authors		: Samuel Birch
 Desc		: transitions between images
 Licence		: Open Source MIT Licence

*/
var slideShow=new Class({getOptions:function(){return{effect:"fade",duration:2E3,transition:Fx.Transitions.linear,direction:"right",wait:5E3,loop:!0,thumbnails:!1,thumbnailCls:"outline",backgroundSlider:!1,loadingCls:"loading",onClick:!1}},initialize:function(a,b,d){this.setOptions(this.getOptions(),d);this.container=$(a);this.container.setStyles({position:"relative",overflow:"hidden"});this.options.onClick&&this.container.addEvent("click",function(){this.options.onClick(this.imageLoaded)}.bind(this));
this.imagesHolder=(new Element("div")).setStyles({position:"absolute",overflow:"hidden",top:this.container.getStyle("height"),left:0,width:"0px",height:"0px",display:"none"}).injectInside(this.container);if($type(b)=="string"&&!this.options.thumbnails){var c=[];$$("."+b).each(function(a){c.push(a.src);a.injectInside(this.imagesHolder)},this);this.images=c}else if($type(b)=="string"&&this.options.thumbnails){var c=[],e=[];this.thumbnails=$$("."+b);this.thumbnails.each(function(a,b){e.push(a.href);
c.push(a.getElement("img"));a.href="javascript:;";a.addEvent("click",function(){this.stop();this.play(b)}.bind(this,a,b))},this);this.images=e;this.thumbnailImages=c;if(this.options.backgroundSlider)this.bgSlider=new BackgroundSlider(this.thumbnailImages,{mouseOver:!1,duration:this.options.duration,className:this.options.thumbnailCls,padding:{top:0,right:-2,bottom:-2,left:0}}),this.bgSlider.set(this.thumbnailImages[0])}else this.images=b;this.loading=(new Element("div")).addClass(this.options.loadingCls).setStyles({position:"absolute",
top:0,left:0,zIndex:3,display:"none",width:this.container.getStyle("width"),height:this.container.getStyle("height")}).injectInside(this.container);this.oldImage=(new Element("div")).setStyles({position:"absolute",overflow:"hidden",top:0,left:0,opacity:0,width:this.container.getStyle("width"),height:this.container.getStyle("height")}).injectInside(this.container);this.newImage=this.oldImage.clone();this.newImage.injectInside(this.container);this.timer=0;this.image=-1;this.imageLoaded=0;this.stopped=
!0;this.animating=this.started=!1},load:function(){$clear(this.timer);this.loading.setStyle("display","block");this.image++;var a=this.images[this.image];delete this.imageObj;doLoad=!0;this.imagesHolder.getElements("img").each(function(a){if(a.src==this.images[this.image])this.imageObj=a,this.add=doLoad=!1,this.show()},this);if(doLoad)this.add=!0,this.imageObj=new Asset.image(a,{onload:this.show.bind(this)})},show:function(){this.add&&this.imageObj.injectInside(this.imagesHolder);this.newImage.setStyles({zIndex:1,
opacity:0});var a=this.newImage.getElement("img");a?this.imageObj.clone().replaces(a):this.imageObj.clone().injectInside(this.newImage);this.imageLoaded=this.image;this.loading.setStyle("display","none");this.options.thumbnails&&(this.options.backgroundSlider?(a=this.thumbnailImages[this.image],this.bgSlider.move(a),this.bgSlider.setStart(a)):this.thumbnails.each(function(a,d){a.removeClass(this.options.thumbnailCls);d==this.image&&a.addClass(this.options.thumbnailCls)},this));this.effect()},wait:function(){this.timer=
this.load.delay(this.options.wait,this)},play:function(a){if(this.stopped){if(a>-1)this.image=a-1;if(this.image<this.images.length)this.stopped=!1,this.started?this.next():this.load(),this.started=!0}},stop:function(){$clear(this.timer);this.stopped=!0},next:function(a){var b=!0;a&&this.stopped&&(b=!1);this.animating&&(b=!1);if(b)this.cloneImage(),$clear(this.timer),this.image<this.images.length-1?a?this.wait():this.load():this.options.loop?(this.image=-1,a?this.wait():this.load()):this.stopped=!0},
previous:function(){this.image=this.imageLoaded==0?this.images.length-2:this.imageLoaded-2;this.next()},cloneImage:function(){var a=this.oldImage.getElement("img");a?this.imageObj.clone().replaces(a):this.imageObj.clone().injectInside(this.oldImage);this.oldImage.setStyles({zIndex:0,top:0,left:0,opacity:1});this.newImage.setStyles({opacity:0})},effect:function(){this.animating=!0;this.effectObj=new Fx.Morph(this.newImage,{duration:this.options.duration,transition:this.options.transition});var a=["fade",
"wipe","slide"],b=["top","right","bottom","left"];this.options.effect=="fade"?this.fade():this.options.effect=="wipe"?(this.options.direction=="random"?this.setup(b[Math.floor(Math.random()*4)]):this.setup(this.options.direction),this.wipe()):this.options.effect=="slide"?(this.options.direction=="random"?this.setup(b[Math.floor(Math.random()*4)]):this.setup(this.options.direction),this.slide()):this.options.effect=="random"&&(a=a[Math.floor(Math.random()*3)],a!="fade"?(b=b[Math.floor(Math.random()*
4)],this.options.direction=="random"?this.setup(b):this.setup(this.options.direction)):this.setup(),this[a]())},setup:function(a){a=="top"?(this.top=-this.container.getStyle("height").toInt(),this.left=0,this.topOut=this.container.getStyle("height").toInt(),this.leftOut=0):a=="right"?(this.top=0,this.left=this.container.getStyle("width").toInt(),this.topOut=0,this.leftOut=-this.container.getStyle("width").toInt()):a=="bottom"?(this.top=this.container.getStyle("height").toInt(),this.left=0,this.topOut=
-this.container.getStyle("height").toInt(),this.leftOut=0):a=="left"?(this.top=0,this.left=-this.container.getStyle("width").toInt(),this.topOut=0,this.leftOut=this.container.getStyle("width").toInt()):this.leftOut=this.topOut=this.left=this.top=0},fade:function(){this.effectObj.start({opacity:[0,1]});this.resetAnimation.delay(this.options.duration+90,this);this.stopped||this.next.delay(this.options.duration+100,this,!0)},wipe:function(){this.newImage.morph({duration:this.options.duration,transition:this.options.transition,
top:[0,this.topOut],left:[0,this.leftOut]});this.effectObj.start({top:[this.top,0],left:[this.left,0],opacity:[1,1]},this);this.resetAnimation.delay(this.options.duration+90,this);this.stopped||this.next.delay(this.options.duration+100,this,!0)},slide:function(){this.effectObj.start({top:[this.top,0],left:[this.left,0],opacity:[1,1]},this);this.resetAnimation.delay(this.options.duration+90,this);this.stopped||this.next.delay(this.options.duration+100,this,!0)},resetAnimation:function(){this.animating=
!1}});slideShow.implement(new Options);slideShow.implement(new Events);
