/* This script is a common Mootools Essential script that should be linked
/ to by any other CMSLite or Web and Go sites that want to use the same functionality.
/ By default, this will be linked to when a new site is created in either CMSLite or Web and Go.
/ See mootools-release-1.11.js for more information
*/

//Slideshow Handler
function slideShowHandler(id,imagesList){

	//Preload the images!
	if(document.images){
		var iList2 = new Object;
		var i = 0;
		for(i=0; i<=imagesList.length; i++) {
			iList2["i"+i] = new Image;
			iList2["i"+i].src = imagesList[i];
		}
	}

	this.id					= id;
	this.imgid				= $(this.id).getElementsBySelector("img")[0];
	this.imagesList			= imagesList;
	this.sliderota_count	= 1;
	this.sliderota_timer	= null;

	$(this.id).setStyles({
		"background-image"	: "url("+this.imgid.getProperty("src")+")",
		"height"			: this.imgid.getProperty("height")+"px",
		"width"				: this.imgid.getProperty("width")+"px"
	});
	this.imgid.setOpacity(0);			

	this.launch = function(milsec) {
		this.tabrota_timer = this.doRotate.periodical(milsec,this);
	}

	this.doRotate = function(){
		this.sliderota_count += 1;		
		var ni		= this.imagesList[this.sliderota_count-1];	
		var fx		= new Fx.Styles(this.imgid, {duration:2000, wait:false});
		var id		= this.id;
		var imgid	= this.imgid;

		this.imgid.setProperty("src",ni);
		fx.start({
			"opacity" : 1
		}).addEvent("onComplete",function(){
				$(id).setStyle("background-image","url("+imgid.getProperty("src")+")");
				imgid.setOpacity(0);
		});
		if(this.sliderota_count == this.imagesList.length){
			this.sliderota_count=0;
		}			
	}
}