function xFade (container,showTime)
{
	this.showTime = showTime * 1000; 
	this.elements = [];
	this.index = 0;
	container.style.position = 'relative';
	var c = container.childNodes;
	for (var i =0;i<c.length;i++)
	{
		if (c[i].nodeType == 1)
		{
			this.elements.push(c[i]);
			c[i].style.position  = 'absolute';
			c[i].style.display  =  'none';
		}

	}
	var self = this;
	xFade.fadeIn(this.elements[0]); // show the first one
	this.timeout = setTimeout(function(){ // schedule the next fade
		self.doTheFade();
	},this.showTime);
}

xFade.prototype.doTheFade = function ()
{
	var self = this;
	var next = (this.index +1 < this.elements.length ) ? this.index + 1 : 0;
	
	xFade.fadeOut(this.elements[this.index]);
	xFade.fadeIn(this.elements[next]);
	
	this.timeout = setTimeout(function(){
		self.doTheFade();
	},this.showTime);
	this.index = next;
}
xFade.setOpacity = function(el,value)
{
	if (typeof el.style.filter != 'undefined')
	{
		el.style.filter = (value < 100) ?  'alpha(opacity='+value+')' : '';
	}
	else
	{
		el.style.opacity = value/100;
	}
}

xFade.fadeIn = function(el,endOpacity,delay,step)
{
	delay = delay || 10;
	step = step || 2;
	endOpacity = endOpacity || 100;
	el.op = el.op || 0;
	var op = el.op;
	if (el.style.display == 'none')
	{
		xFade.setOpacity(el,0);
		el.style.display = 'block';
	}
	if (op < endOpacity)
	{
		el.op += step;
		xFade.setOpacity(el,op);
		el.timeout = setTimeout(function(){xFade.fadeIn(el,endOpacity,delay,step);},delay);
	}
	else
	{
		xFade.setOpacity(el,endOpacity);
		el.op = endOpacity;
		el.timeout = null;
	}
}

xFade.fadeOut = function(el,delay,step)
{
	delay = delay || 10;
	step = step || 2;
	if (typeof el.op == 'undefined') el.op = 100;
	var op = el.op;

	if (op >= 0)
	{
		el.op -= step;
		xFade.setOpacity(el,op);
		el.timeout = setTimeout(function(){xFade.fadeOut(el,delay,step);},delay);
	}
	else
	{
		xFade.setOpacity(el,0);
		el.style.display = 'none';
		el.op = 0;
		el.timout = null;
	}
}

function addEvent (el, evname, func)
{
	if (document.addEventListener)
	{
		el.addEventListener(evname, func, true);
	}
	else
	{
		el.attachEvent("on" + evname, func);
	}
}
function init()
{
	new xFade(document.getElementById('container'),7);
}

addEvent(window,'load',init);