/**
 * Class to help with the fading on the index layout
 *
 * @author      Blue Moon IT <info@bluemoonit.net>
 * @copyright   2008, Blue Moon IT
 * @package     BlueMoonIt--TopfysioTemplate
 * @subpackage  HTML
 * @version     SVN: $Id: index.fading.js 310 2009-05-12 11:05:28Z johan $
 */
IndexFading_Class = function()
{
	this.started = false;

	this.altSplashImage = null;

	this.status = null;

	this.delay = 3000;

	this.start = function()
	{
		if( !this.started ) {
			this.splashDiv = $('#splash');
			this.introDiv  = this.splashDiv.find('div.intro');
			this._imgList   = this.splashDiv.find('img');

			if( 1 < this._imgList.size() ) {
				this.currentImage = 0;

				this._imgList.css('opacity', '0');
				this._imgList.eq(this.currentImage).css('opacity', '1');

				this._imgList.css({
					position: 'absolute',
					top: 0,
					left: 0,
					zIndex: -1
				});
			} else {
				this.currentImage = -1;
			}

			this.started = true;
			this.status = 0;
		} else {
			if( 0 == this.status ) {
				this.introDiv.animate({
					opacity: 0
				}, 1000);

				this.status = 1;
			} else {
				this.introDiv.animate({
					opacity: 1
				}, 1000);

				this.status = 0;
			}

			if( -1 < this.currentImage ) {
				this._imgList.eq(this.currentImage).animate({
					opacity: 0
				}, 1000);

				this.currentImage++;

				if( this._imgList.size() <= this.currentImage ) {
					this.currentImage = 0;
				}

				this._imgList.eq(this.currentImage).animate({
					opacity: 1
				}, 1000);
			}
		}

		var context = this;
		this.timer = setTimeout(function() {
			context.start.call(context);
		}, this.delay);
	}

	this._imgList = null;
}
