/**
 * Class for showing fading images.
 * 
 */
Header = {

	_interval: 10000,

	_images: new Array(),
			
	_activeImage: 0,
	
	_duration: 3,
	
	/**
	 * Init
	 */
	init: function()
	{
		/* check if the header-image div exists */
		if($('header'))
		{
			for(x = 0; x < headerImages.length; x++)
			{
				var item = createDOM('IMG', {src: headerImages[x], 'style': 'display:none;'});
				appendChildNodes('header', item);
				Header._images.push(item);
			}
		
			//var images = $('header').getElementsByTagName('img');
			//
			//for(x = 0; x < images.length; x++)
			//{
			//	Header._images.push(images[x]);
			//}
			
			/* stop if no images exist in the header div */
			if(Header._images.length == 0)
			{
				return;	
			}
			
			setInterval('Header._showNextImage()', Header._interval);
		}
	},
	
	/**
	 * Shows the next image and hides the previous image
	 */
	_showNextImage: function ()
	{
		/* create the fading effect of the current image */
		var fading = new MochiKit.Visual.fade(Header._getCurrentImage(), {sync: true});
		
		/* set next image as current image */
		Header._setNextImage();

		/* create the appearing effect of the new image */
		var appearing = new MochiKit.Visual.appear(Header._getCurrentImage(), {sync: true});
		
		/* make sure the effects run in parallel */
		Parallel([fading, appearing], {duration: Header._duration});
		
	},
	
	/**
	 * Sets the index of the image that will be shown next
	 */
	_setNextImage: function()
	{
		if(Header._activeImage + 1 == Header._images.length )
		{
			Header._activeImage = 0;
		}
		else
		{
			Header._activeImage += 1;
		}
	},
	
	/**
	 * Return the currently active image
	 */
	_getCurrentImage: function()
	{
		return Header._images[Header._activeImage];
	}
	
}; // class Header


addLoadEvent(Header.init);
