/**
 * @author christian
 */
if (!window.console)  {
	window.console =  {
		 log: function( o )  {
			// alert( o );
		 }
	 };
}

ImagesSlideshow = new Class({
	options: {
		animation: {
			type: "scroll",// fadeNscroll, scroll, fade
			transition: Fx.Transitions.Cubic.easeInOut,
			duration: 500
		},
		interval: 5000,
		width: -1,
		height: -1
	},
	
	initialize: function(container, options){
		this.setOptions(options);
		this.container = container;

		this.images = container.getElements("img");
		var firstItem = this.images[0];
		if(this.options.width == -1)
			this.options.width = parseInt(firstItem.getStyle("width"));
		if(this.options.height == -1)
			this.options.height = parseInt(firstItem.getStyle("height"));
		
		container.setStyle("position", "relative");
		container.setStyle("width", this.options.width);
		container.setStyle("height", this.options.height);
		
		this.length = this.images.length;
		
		this.images.each(function(item, index){
			item.setStyle("position", "absolute");
			if(index>0)
				item.setStyle("opacity", 0);
		}, this);
		this.currentIndex = 0;
		this.periodical = this.showNext.periodical(this.options.interval, this);
	},
	
	showNext: function ()
	{
		this.gotoIndex((this.currentIndex + 1) % this.length);
	},
	
	gotoIndex: function(newIndex){
		if(newIndex == this.currentIndex)
			return;
		
		this.currentIndex = newIndex;
		var nextImg = this.images[this.currentIndex];
		nextImg.setStyle("opacity", 0);
		this.container.removeChild(nextImg);
		this.container.appendChild(nextImg);
		nextImg.tween("opacity", 1);
	},
	
	log: function (msg) {
		if (window.console)
			window.console.log(msg);
	}
})
ImagesSlideshow.implement(new Events); // Implements addEvent(type, fn), fireEvent(type, [args], delay) and removeEvent(type, fn)
ImagesSlideshow.implement(new Options);// Implements setOptions(defaults, options)