// JavaScript Document


//document.observe('dom:loaded',function(){
										 
	Event.observe(window, 'load', function() {										   
			init_minislideshow ();
	

		});



function init_minislideshow () {

		
		var minislideshows  = new Array();	
											   
			var num = 0;											   
											   
			$$('.minislideshow').each(function(element) {	
											   
				num++;						   
				var IDname = element.readAttribute('id');	
				
				var minislideshow = new mini_slideshow(element,0);	
				
				
				minislideshows[IDname] = minislideshow;
			
			});
			
}





	












mini_slideshow = Class.create({
    initialize: function(container, timeout){
		
		this.container = container;
		this.timeout = timeout;
		
		
		this.children = container.childElements();
		this.ii = 0;
		this.aktivecss = 'currentslideimage';
		//this.current = 0;
		
		this.anzahl = this.children.length;
		
		
		
		this.complete = false;
		
		this.children.each(function(childeelement) {
					childeelement.hide();
						   
		}.bind(this));
		
		this.children[0].show();
		
		//Event.observe(window, 'resize', this.resizer.bind(this)); 
		
		this.speed = 5000;
		this.intID = 0;
		
		var instantz = this;
		if (this.anzahl>1) 	this.mytimer = setInterval(function() { instantz.anitimer(); }, this.timeout);

		
		//alert (current);
		
	},
	loadcheck: function(event){
		//alert(1);
	},
	anitimer: function(){
		//clearInterval( this.interval );
		//resizebild () ;
		
		var instant = this;
		
		//alert ('s');
		clearInterval(this.mytimer);
		
		this.intID = setInterval(function() { instant.counter(this.ii ); }, this.speed);
		
	},
	
	counter: function(){
		this.animation(this.ii);
		//this._speed = 4000;
		//alert("It works"+this.ii+ " " + this.speed + " " + this.intID  );
		
		if (this.ii>=this.anzahl-1) {
			this.ii = 0;
		} else {
			this.ii++;
		}
		
		
		
		
	},
	animation: function(current){
		
				
				if (this.ii>=this.anzahl-1) { 
					next = 0; 
				} else {
					next = this.ii+1;
				}
				
				//alert (current + ' ' + next );
				
				
				
				
		
				new Effect.Parallel([
						new Effect.Appear(	this.children[next], 		{ sync: true })  ,
						new Effect.Fade(	this.children[this.ii], 	{ sync: true })  
					], { 
					  duration: 1.5,
					  delay: 0.2,
					  afterFinish: function() {
						  
						  
					  }
						  
				});
		//alert (this.children[this.next]);

	}
});







