/* SlideShow Script 
 * Requires Prototype and Script.aculo.us Libraries
 * By: Henry YP Ho @ monKiKi.st
 * http://www.monkiki.st
 * This work is licensed under the Creative Commons Attribution-Share Alike 3.0
 * http://creativecommons.org/licenses/by-sa/3.0/us/
 */
 
 
if (typeof Effect == 'undefined')
  throw("You must have the script.aculo.us library to use this accordion");

var FadeSlideShow = Class.create({
							 
	initialize: function(id, defaultStartFrame, defaultDelay) {
        if(!$(id)) throw("Attempted to initalize accordion with id: "+ id + " which was not found.");
        this.fadeslideshow = $(id);
		//set the parameter
		this.delay = defaultDelay ? defaultDelay : 1000;
		this.startFrame = defaultStartFrame ? defaultStartFrame : 0;
		this.current = this.startFrame;
		
		this.slideList = this.fadeslideshow.getElementsByTagName('li');
		//set inital hide
		this.initialHide();
		
		//start slide show
		this.startSlideShow();
		
	},
	
	//initial Hide
	initialHide: function() {
	
		for (var i=0; i<this.slideList.length; i++) {
			if (i != this.startFrame) {
				this.slideList[i].style.display = 'none';
			}
		}
		//set the end frame
		this.endFrame = this.slideList.length-1;
	},
	
	//
	startSlideShow: function() {
		
			setInterval(this.fadeInOut.bind(this), this.delay);
			
	},
	
	//
	fadeInOut: function() {
					
			//alert (this.slideList);
			Effect.Fade(this.slideList[this.current], { duration:1, from:1.0, to:0.0 }); 
			//
			if (this.current == this.endFrame) {
				this.current = 0;
			}
			else {
				this.current++;
			}
			//
			Effect.Appear(this.slideList[this.current], { duration:1, from:0.0, to:1.0 });
	}
		

});

document.observe("dom:loaded", function(){
    slideshow = new FadeSlideShow ("slide-images", 0, 5000);
	
	slidefeatures = new FadeSlideShow("slide-features", 0, 4000);
	
});

