/*
*     		                                                                    .___.__        
*	   ____________  ______             ____   ______  _  __   _____   ____   __| _/|__|____   
*	  /     \_  __ \/  ___/   ______   /    \_/ __ \ \/ \/ /  /     \_/ __ \ / __ | |  \__  \  
*	 |  Y Y  \  | \/\___ \   /_____/  |   |  \  ___/\     /  |  Y Y  \  ___// /_/ | |  |/ __ \_
*	 |__|_|  /__|  /____  >           |___|  /\___  >\/\_/   |__|_|  /\___  >____ | |__(____  /
*	       \/           \/                 \/     \/               \/     \/     \/         \/ 
*
*	copyright @ 2011, mayr record scan
*	customer: simplon
*	devision: new media
*	teamleader: stefan hagspiel
*

*	simplon slider class
*  
*	DONT BE A DICK. DONT COPY. 
* 
*/
var simplonSlider=new Class({Implements:[Options,Events],options:{container:"",images:[],showNavigation:false,navPosition:"inside",showDescription:false,preloader:"",delay:2000,time:1000},initialize:function(b,a){this.setOptions(a);this.slideContainer;this.navContainer;this.slides=[];this.images=[];this.navElements=[];this.descElements=[];this.currentSlide=0;this.prevSlide=0;this.hasStarted=false;this.selectedItem=999;this.stopped=false;this.busy=false;this.descContainer;this.descText;this.setup()},debug:function(){this.fireEvent(debug)},setup:function(){this.slideContainer=$(this.options.container).getElement("div[id=images]");this.preloader=$(this.options.preloader);this.navContainer=$(this.options.container).getElement("div[id=navigation]");this.slides=$(this.options.container).getElements("div[class=slide]");this.slides.getElements("img").each(function(a){this.images.push(a.get("src").toString())}.bind(this));this.arrowClass="selected-inside";this.setupNav();this.setupDescription();this.setupAnimation();this.preloadImages()},setupAnimation:function(){var a=this;this.slides.each(function(b){b.set("opacity",0).setStyle("display","block");b.set("tween",{duration:a.options.time});if(a.options.showDescription){a.descElements.push(b.getElement("div[class=description]").get("html").toString())}})},setupNav:function(){var a=this;if(!this.options.showNavigation){return}this.arrowClass=this.options.navPosition=="inside"?"selected-inside":"selected-outside";var b=this.options.navPosition=="inside"?this.slideContainer.getStyle("height").toInt()-30:this.slideContainer.getStyle("height").toInt()-1;this.navContainer.setStyle("top",b);var e=new Element("ul");var g=new Chain;var f=0;for(var d=0;d<a.slides.length;d++){g.chain(function(j){var h=f==0?"selected navList":"navList";var i=f==0?"circleGreen":"circleWhite";var c=new Element("li",{"class":h,id:f}).set("opacity",0);if(a.options.navPosition!="inside"){c.addClass("outside")}var k=new Element("div",{"class":i});c.adopt(k);e.adopt(c);a.navElements.push(c);c.addEvent("click",function(l){if(!a.hasStarted||c.id==a.selectedItem||a.busy){return false}a.busy=true;a.selectedItem=c.id;a.currentSlide=c.id;l.stopPropagation();a.setItemToCurrent(c);a.stopped=true;a.slideToElement();a.prevSlide=a.currentSlide});f++;c.fade("in");this.callChain.delay(200,this,f)})}g.callChain();this.navContainer.adopt(e).show()},setupDescription:function(){if(!this.options.showDescription){return}this.descContainer=new Element("div",{id:"description"}).setStyles({height:0,display:"block",bottom:0});this.descContainer.set("tween",{duration:this.options.time});this.descText=new Element("p");this.descContainer.grab(this.descText);this.descContainer.inject(this.slideContainer,"top").show()},preloadImages:function(){var a=this;var b=Asset.images(a.images,{onComplete:function(){a.preloader.destroy();a.slide()}})},setItemToCurrent:function(a){if(!this.options.showNavigation){return}$$(".navList").each(function(b){b.getChildren()[0].set("class","circleWhite");b.removeClass(this.arrowClass)}.bind(this));a.addClass(this.arrowClass);a.getChildren()[0].set("class","circleGreen")},getNextSlide:function(){if(this.currentSlide+1>this.slides.length-1){return 0}else{return this.currentSlide.toInt()+1}},fadeOutPrevious:function(){if(!this.hasStarted){return}prevSlide=this.prevSlide;this.slides[prevSlide].tween("opacity",0)},slide:function(){var a=this;if(a.stopped){return}this.fadeOutPrevious();this.closeDescription();a.prevSlide=a.currentSlide;a.setItemToCurrent(a.navElements[a.currentSlide]);this.slides[this.currentSlide].tween("opacity",1).get("tween").chain(function(){a.hasStarted=true;a.updateDescription();a.currentSlide=a.getNextSlide();if(!a.stopped){a.slide.delay(a.options.delay,a)}})},closeDescription:function(){if(!this.options.showDescription){return}this.descContainer.tween("height",0)},updateDescription:function(){var a=this;if(!this.options.showDescription){return}this.descText.set("html",this.descElements[this.currentSlide]);this.descContainer.tween("height",this.descText.getCoordinates().height).get("tween").chain(function(){a.busy=false})},slideToElement:function(){var a=this;this.fadeOutPrevious();this.closeDescription();this.slides[this.currentSlide].tween("opacity",1).get("tween").chain(function(){a.updateDescription();a.currentSlide=a.getNextSlide()})}});
