// 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);	
				
				//minislideshow = new einelideshow(element,1,0,4);

				//new einelideshow(element,1,0,4);
				//Scrollframes.push(scrollbar);
				//Scrollframes["cool"]="Mustang";
				minislideshows[IDname] = minislideshow;
				//alert(Scrollframes[IDname]);
				//minislideshows[IDname].animation();
			});
			
}





	












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;
		
		//alert(this.anzahl );
	/*	//alert(Anzahl);
		
		children[current].addClassName(aktivecss);
		
		*/
		
		this.complete = false;
		
		this.children.each(function(childeelement) {
			//if (childeelement.hasClassName(aktivecss) ) current = ii;				   
					childeelement.hide();
					//childeelement.observe('load', this.loadcheck.bind(this));
			//ii++;	//alert(childeelement);		   
		}.bind(this));
		
		this.children[0].show();
		
		//Event.observe(window, 'resize', this.resizer.bind(this)); 
		
		this.speed = 7500;
		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);
		
		//setTimeout ( this.animation(3), 3000 );
		//alert (num);
		
		//clearInterval(this.timer);
		//if ( num >5 )	this.clearInterval(this.aktiv);
		//setTimeout(this.anitimer(num+1), 80000);
	},
	
	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){
		//alert (this.aktivecss);
		//alert (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: 2.5,
					  delay: 0.2,
					  afterFinish: function() {
						  
						  
					  }
						  
				});
		//alert (this.children[this.next]);

	}/*,	
	resizer: function(event){
		
		this.children.each(function(childeelement) {
			   
		}.bind(this));
	}*/
});




/*
	
	einelideshow = function(imageconti, num, aus, changeTime) {
		
		//imageconti 	= document.getElementById(bildgruppe);
		
		var children = imageconti.childElements();
		
		var anzahl 		= children.length;
		
		
		
		
			
		if (num == anzahl) {
			num = 1;	
		} else {
			num++;
		}
		
		if (num == 1) {
			aus = anzahl;
		} else {
			aus = num - 1;
		}
	
		imagea	= children[num-1];
		//imagea	= imageconti.childNodes[num-1];
		
		imageb	= children[aus-1];
		
		
		
			
		//geladenebilder = checkbilder(imageconti);
		
		timerma = setTimeout('einelideshow('+imageconti+','+num+' ,'+aus+','+changeTime+')',changeTime*1000);
		//alert(imagea);
		
				new Effect.Parallel([
					new Effect.Appear(imagea, 	{ sync: true })  ,
					new Effect.Fade(imageb, 	{ sync: true })  
				], { 
				  duration: 1.5,
				  delay: 0
				  
						  
				});
		
		
	
		//imagea.appear({duration: 1 });
		//imageb.fade();
		
	
	
	//new einelideshow(bildgruppe, num, aus);
}
*/


