// JavaScript Document
//v1.0.1
/*

*/

var slideshow = Class.create();
slideshow.prototype = {
	initialize: function(id,images,display,fade,extend_last) {
		this.name=id;
		this.id  = $(id);
		this.images  = images;
		this.display  = display;
		this.fade  = fade;
		this.current = 1;
		this.next = 1;
		this.end = this.images.length-1;
		this.timer= null;
		this.extend_last=extend_last;
		this.preload();
		this.play();
	},
	
	preload: function() { 
	
	  var images = this.images;
	
	  document.imageArray = new Array(images.length);
	
	  for(var i=0; i<images.end; i++)
	
	  {
	
		document.imageArray[i] = new Image;
	
		document.imageArray[i].src = images[i];
	
	  }
	
	},

	play: function() {
		thisObject=this;
		if(this.end){
			
			display=this.display;

			setTimeout('thisObject.swap()',(display*1000));
		}
	},

	swap: function() {

		var next_img = document.createElement('img');
		Element.extend(next_img);
		next_img.hide();
		next_img.src=this.images[this.next];
		//'images/intro/rotate_'+(this.next+1)+'.jpg';
		this.id.appendChild(next_img);

		fade=this.fade;
		
		this.current=this.next;
		this.next++;
		if(this.next>this.end)
			this.next=0;
			
		if(next_img.up().immediateDescendants().length>2)
		next_img.up().down().remove();
		
		return new Effect.Appear(next_img, { duration: fade, afterFinish: this.play() });
		
	}

};
