function progressBar( sName )
{
	this._inherit = dynamicElement;
	this._inherit( sName );

	this._bar = new dynamicElement( sName + "bar" );

	this._self = "ProgressObject";
	eval( this._self + "=this" );
	return this;
}
progressBar.prototype.init = function()
{
	this._direction = 1;
	this._init      = true;
	this._minX      = -this._bar._width;
	this._maxX      = this._bar._width;
	this._bar.move( this._minX, 0 );
}
progressBar.prototype.animate = function()
{
	if ( !this._init )
		this.init();
	var nPos = this._bar._x + ( ( this._bar._width / 10 ) * this._direction );

	if ( nPos > this._maxX || nPos < this._minX )
		this._direction *= -1;
//	if ( nPos > this._maxX )
//		nPos = this._minX;
	

	this._bar.move( nPos, this._bar._y );
	this._timer = setTimeout( this._self + ".animate();", 75 );
}

function PatsFactor()
{
	this._overlay    = new growthSpurt( "overlay" );
	this._column     = new growthSpurt( "column" );
	this._background = new growthSpurt( "flowers" );
//	this._progress   = new progressBar( "progress" );
	this._soon       = new dynamicElement( "binnenkort" );
	this._console    = false;

	if ( document.getElementById && document.createElement ) // DOM Browsers
	{
		this._console       = document.getElementById( "console" );
		this._consoleBuffer = new Array();
		this._consoleTimer  = null;
	}

	this._background._style.bottom = -100 + this._background.docTypePosAppend;

	this._soon._parent = this;
	this._soon.setMethod( "clickety", objectClick );
	this._soon.setHandler( "click", "clickety" );

	this._contractY = 150;
	this._contractX = 50;
//	this._progress.animate();

	this._self = "PatsFactorObject";
	eval( this._self + "=this" );
	return this;
}
PatsFactor.prototype.write = function( sMessage )
{
	if ( this._console )
	{
		clearTimeout( this._consoleTimer );
		var oBR       = document.createElement( "br" );
		oBR.className = "clear";
		this._consoleBuffer[ this._consoleBuffer.length ] = oBR;

		for ( var i = sMessage.length - 1; i >= 0; --i )
		{
			var oChar = document.createElement( "div" );
			var sChar = sMessage.substr( i, 1 );
	
			switch( sChar )
			{
				case " ":
					oChar.innerHTML = "&nbsp;";
					break;
				case "\n":
				case "\r":
					oChar = oBR.cloneNode( true );
					oChar.className = "clear";
					break;
				default:
					oChar.appendChild( document.createTextNode( sChar ) );
					break;
			}
			this._consoleBuffer[ this._consoleBuffer.length ] = oChar;
		}
		this.updateConsole();
	}
}
PatsFactor.prototype.updateConsole = function()
{
	clearTimeout( this._consoleTimer );
	if ( this._console )
	{
		if ( this._consoleBuffer.length > 0 )
		{
			this._console.insertBefore( this._consoleBuffer.shift(), this._console.firstChild );
			this._consoleTimer = setTimeout( this._self + ".updateConsole()", 40 );
		}
		else if ( this._console.childNodes.length > 255 || this._console.lastChild.nodeName.toLowerCase() != "br" )
		{
			this._console.removeChild( this._console.childNodes[ this._console.childNodes.length - 1 ] );
			this._consoleTimer = setTimeout( this._self + ".updateConsole()", 40 );
		}
	}
}
PatsFactor.prototype.handleClick = function()
{
	if ( !this._contracted || typeof this._contracted == "undefined" )
	{
		this._contracted = true;
		this.contractArtwork( -this._contractX, this._contractY );
	}
	else
	{
		this._contracted = false;
		this.contractArtwork( this._contractX, -this._contractY );
	}
}
PatsFactor.prototype.contractArtwork = function( nX, nY )
{
	this._overlay.slide( this._overlay._x + nX, this._overlay._y + nY );
	this._background.slide( this._background._x + nX, this._background._y + nY );
}


function objectClick()
{
	this._parent.handleClick();
}

var oPF = null;
var oTextTimer = null;
var nTestText  = 0;
var aTestText  = new Array(
	"Klaar terwijl je wacht.",
	"Nu met gratis wachttijd.",
	"Mail ons je suggesties op info@patsfactor.nl!",
	"Binnenkort meer (echt waar).",
	"Blijf niet te lang je tijd verdoen hier, maar kom regelmatig terug om te zien of we al klaar zijn.",
	"Spreek je later!"
);

function setTestText()
{
	var nText = Math.round( Math.random() * ( aTestText.length - 1 ) );
	while ( nText == nTestText )
		nText = Math.round( Math.random() * ( aTestText.length - 1 ) );
	oPF.write( aTestText[ nText ] );
	nTestText = nText;
	oTextTimer = setTimeout( "setTestText();", 10000 );
}

window.onload = function()
{
	oPF = new PatsFactor();
	oPF._column.move( -400, 0 );
	oPF._column.resize( 1, oPF._column._height );
	oPF._column._slideSpeed = 50;
	oPF._column._sizeSpeed  = 80;
	oPF._column.slide( 150, 0 );
	oPF._column.smoothResize( 330, oPF._column._height );
	oTextTimer = setTimeout( "setTestText();", 5000 );
}

window.onresize = function()
{
	oPF._column.resize( oPF._column._width, ( document.body.clientHeight || window.innerHeight ) );
}
