
function welcome_init()
{
	dissolver = new Dissolver();
	dissolver.initialize();
	setTimeout( "dissolver.start()", 1000 );
	// setTimeout( "dissolver.stop()", 30000 );
}


// -------------------------------------------------------------------------- //
/*	Dissolver Class
	Version: 1.0.0
	Date: 2008.06.30
	
	Copyright 2008 Cognizant Consulting Inc.
	http://cogni.ca/
*/
// -------------------------------------------------------------------------- //

function Dissolver()
{
	if( !Dissolver.Instances )				// Record instances as part of the
		Dissolver.Instances = [];			// object so setTimeout can access
	this.id = Dissolver.Instances.length;	// the correct instance directly,
	Dissolver.Instances[this.id] = this;	// without needing to know external
											// variable names.
	this.disolving = false;
	this.current_id = 1;
	this.next_id = 2;
	this.max_id = 4;
	this.step = 100;
	this.step_size = 2;
	this.delay = 5 * 1000;	// delay is in milliseconds
	this.targets = [""];
	this.interval = 0;
	
	this.initialize = function()
	{
		for( var i = 1; i <= this.max_id; i++ )
		{
			this.targets[i] = document.getElementById( 'dissolve' + i );
		}
	}
	
	this.stop = function()
	{
		this.disolving = false;
	}

	this.pause = function()
	{
		if( this.disolving )
			setTimeout( 'Dissolver.Instances['+this.id+'].resume()', this.delay );
	}

	this.start = function()
	{
		if( !this.disolving )
		{
			this.disolving = true;
			this.resume();
		}
	}
	
	this.resume = function()
	{
		this.interval = setInterval( 'Dissolver.Instances['+this.id+'].dissolve()', 20 );
	}

	this.dissolve = function()
	{
		try
		{
			if( this.step >= 100 )
			{
				this.step = 100;	// Safety
				this.targets[this.current_id].className = 'front';
				this.targets[this.next_id].className = 'back';
				this.targets[this.current_id].style.opacity = (this.step / 100);
				this.targets[this.current_id].style.filter = 'alpha(opacity=' + this.step + ')';
				this.targets[this.next_id].style.opacity = (this.step / 100);
				this.targets[this.next_id].style.filter = 'alpha(opacity=' + this.step + ')';
			}
			
			this.step -= this.step_size;
			this.targets[this.current_id].style.opacity = (this.step / 100);
			this.targets[this.current_id].style.filter = 'alpha(opacity=' + this.step + ')';
			
			if( this.step <= 0 )
			{
				clearInterval( this.interval );
				this.interval = 0;
				this.current_id = this.next_id;
				this.next_id = (this.current_id == this.max_id) ? 1 : this.current_id + 1;
				this.step = 100;
				this.pause();
			}
		}
		catch( e )
		{
			clearInterval( this.interval );
			this.interval = 0;
			alert( "Error:\n" + e.toString() );
		}
	}
}

