/*
addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

var Sshow = {
	currentStat: 0,
	changeStat: 1,
	listheight: 0,
	init: function() {
		this.list = $('playground');
		if (this.list) {
			this.list.items = this.list.getElementsByTagName('IMG');
			Sshow.listsum = this.list.items.length;
			if (this.list.items.length > 1) { // wenn mehr als ein Bild
				for (var i = 0; i < this.list.items.length; i++) {
					litem = this.list.items[i];
					litemheight = $(litem).getHeight();
					if (Sshow.listheight <= litemheight) { 
						Sshow.listheight = litemheight;
					}
					litem.setAttribute('id','imglst'+(i+1));
					$(litem).setStyle({
					  left: '0',
					  position: 'absolute',
					  top: '0'
					});
					if (i > 0) {
						$(litem).setStyle({ display: 'none' })
					}
				}				
			Sshow.listheight = Sshow.listheight+"px";
			$('playground').setStyle({
			  height: Sshow.listheight
			});
			Sshow.start();
			}
		}
	},
	start: function() {
		Sshow.setcurrent();		
  	    new PeriodicalExecuter(Sshow.cycle, 4); // change image every 5 seconds 
	},	
	cycle: function() { 
		$(Sshow.currentimage).setStyle({
		  height: Sshow.listheight,
		  zIndex: '10',
		  display: 'block'
		});
		$(Sshow.changeimage).setStyle({
		  height: Sshow.listheight,
		  zIndex: '1',
		  display: 'block'
		});
	new Effect.Fade(Sshow.currentimage, { 
		  duration: 1, 
		  afterFinish: function() { 
				window.setTimeout("Sshow.setcurrent()", 500);
		  } 
		});
	},	
	setcurrent: function() { 
		if (Sshow.currentStat < Sshow.listsum) {
			Sshow.currentStat = Sshow.currentStat+1;
		} else {
			Sshow.currentStat = 1;
		}
		if (Sshow.changeStat < Sshow.listsum) {
			Sshow.changeStat = Sshow.changeStat+1;
		} else {
			Sshow.changeStat = 1;
		}
		Sshow.currentimage = 'imglst'+Sshow.currentStat;
		Sshow.changeimage = 'imglst'+Sshow.changeStat;
	}
};

addEvent(window,'load',Sshow.init);
