/*
	    Universal Slideshows Script
		============================
		(c) copyright
		Trefnet Nederland BV
		Havinghastraat 32
		1817 DA Alkmaar 
		
		T. 072 - 527 00 40
		F. 072 - 527 00 41
		============================
		Hint : This code sets all neccasary styles, and not all slides must have the same size.
		       You might want to set the height and display hard on the elements.
*/

	var oSlideShowSettings       = {} ;
	oSlideShowSettings.timeover  = 1000 ;
	oSlideShowSettings.timeout   = 4000 ;
	oSlideShowSettings.instances = new Array() ;

	function SlideShow( oRoot, nTimeOut, nTimeOver )
	{
		this.root      = oRoot ;
		this.children  = new Array() ;
		this.pointer   = 0 ;
		this._magic    = Math.random() * 100000 ;
		this.timeout   = nTimeOut  ? nTimeOut : oSlideShowSettings.timeout ;
		this.timeover  = nTimeOver ? nTimeOver : oSlideShowSettings.timeover ;
		this.init() ;
	} ;
	
	SlideShow.prototype.init = function()
	{
		var nHeight = 100 ;
		this.children = this.root.getElementsByTagName( 'div' ) ;
		
		$( this.root ).css( { listStyleType : 'none', position : 'relative' } ) ;
		$( this.root ).find( 'div.listcontent_slideshow_item' ).css( { position: 'absolute'  } ) ; 
		$( this.root ).find( 'div.listcontent_slideshow_item' ).each( function( nIndex, oElement ){ nHeight = Math.max( nHeight, oElement.offsetHeight ) ; } ) ;
		$( this.root ).css( 'height', nHeight + 10 ) ;
		$( this.root ).find( 'div.listcontent_slideshow_item' ).css( { display : 'none' } ) ; 
		$( this.root ).find( 'div.listcontent_slideshow_item:first' ).css( { display : 'block' } ) ;
		
		oSlideShowSettings.instances[ this._magic ] = this ;
		if( this.children.length )
			setTimeout( 'SlideShow.prototype.advance(' + this._magic + ')', this.timeout  ) ;
	} ;
	
	SlideShow.prototype.nextSlide = function()
	{
		var nLast = this.pointer ;
		this.pointer++ ;
		if( this.pointer == this.children.length )
			this.pointer = 0 ;
		$( this.children[nLast] ).fadeOut( this.timeover ) ;
		$( this.children[this.pointer] ).fadeIn( this.timeover ) ;
		setTimeout( 'SlideShow.prototype.advance(' + this._magic + ')', this.timeout  ) ;
	} ;
	
	SlideShow.prototype.advance = function( nNumber )
	{
		oSlideShowSettings.instances[nNumber].nextSlide() ;
	} ;
	
	
	
	$( document ).ready( function()
		{
			$( 'div.listcontent_slideshow' ).each( function(){ new SlideShow( this ) ; } ) ;
		} );
	
	
