function activateSlideShows(){
	$(".slideShow").each( function(){
		
		if(!this.slideShowAcivated){
			
			var e = $( this );			
			this.slideShowAcivated = true;
			
			this.intervall = 1500;
			this.fadeSpeed = 3000;
			
			var cn = this.className.split(" ");
			for(var i=0; i<cn.length; i++){
				if( cn[i].indexOf("speed") == 0 ) this.intervall = Number( cn[i].substring(5) );
				if( cn[i].indexOf("fade") == 0 ) this.fadeSpeed = Number( cn[i].substring(4) );
			}
			
			e.css({'position': 'relative'});
			this.slides = e.children();
			
			for(var i=0; i<this.slides.length; i++){
				var sob = this.slides[i];
				sob.no = i;
				sob.slideShow = this;
				
				$(sob).css({
					'display':	(i==0)? 'block' : 'none',
					'position':	'absolute',
					'top':		'0px',
					'left':		'0px'
				});
			}
			
			
			this.resize = function(){
				$(this).css({
					height: $(this.currentSlide).height()+"px"		  
				});
			}
			
			this.showSlide = function( sno ){
				
				if(this.resizeInterval){
					window.clearInterval( this.resizeInterval );
					delete this.resizeInterval;	
				}
				
				if(sno==undefined){
					if(this.currentSlide) var sno = this.currentSlide.no;
					else{
						var sno = -1;
						this.currentSlide = this.slides[0];
					}
				}			
				var nno = sno+1;
				while( nno>=this.slides.length ) nno = 0; //-= this.slides.length;
				
				var nextSlide = this.slides[nno];
				
				if(nextSlide!=this.currentSlide){
					if( nno < sno ){			
						$( this.currentSlide ).fadeOut( this.fadeSpeed );
						$( nextSlide ).show();
					} else {
						nextSlide.lastSlide = this.currentSlide;
						$(nextSlide).fadeIn( this.fadeSpeed, function(){
							if( this.lastSlide!=this.slideShow.currentSlide ) $(this.lastSlide).hide();	
						});				
					}		
					this.currentSlide = nextSlide;
				}
				
				this.resize();				
				
				var e = this;
				window.setTimeout(function () {
					//alert(e);
					e.showSlide();
				}, this.intervall);//, this);
				//alert("this: "+this);
			}
			
			this.showSlide();		
			this.resizeInterval = window.setInterval( this.resize, 100 );
		}
	});
}

$(document).ready( function(){
	activateSlideShows();
});
