// JavaScript Document
var loadingText      = 'Een ogenblikje aub';
var loadingImage     = '/images/loader/loader.gif';
var loadingOverlayBG = '/images/loader/overlay.png';
var loadingDivBG     = '/images/loader/loaderBackground.png';
var IsIE6            = ( $.browser.msie && $.browser.version == '6.0' );

function loader()
{
	this.isInitialized = false;
	this.loadingDivId  = "loadingDiv";
	this.waitTextId    = "loadingText";
	this.overlayId     = "overlayDiv";
	this.contentDivId	   = "loadingDivContent";
	this.loadingDiv    = $E ( this.loadingDivId  );
	this.overlayDiv    = $E ( this.overlayId );
	
	this.init = function () {
		var bodie = document.getElementsByTagName("body")[0];
		
		/*creating the overlay*/
		this.overlayDiv = document.createElement("div");
		this.overlayDiv.setAttribute("id",this.overlayId);
		this.overlayDiv.style.position = "fixed";
		this.overlayDiv.style.width="99.8%";
		this.overlayDiv.style.height="99.8%";
		this.overlayDiv.style.top="0px";
		this.overlayDiv.style.left="0px";
		this.overlayDiv.style.display = "none";	
		this.overlayDiv.onclick= null;
		this.overlayDiv.style.backgroundImage = "url("+window['loadingOverlayBG']+")";
		this.overlayDiv.style.zIndex = "1000001";
		bodie.appendChild ( this.overlayDiv );
		
		/*creating the loading*/
		
		this.loadingDiv = document.createElement("div");
		this.loadingDiv.setAttribute("id",this.loadingDivId);
		var waitpic = new Image();
		waitpic.src=window['loadingImage'];
		
		this.loadingDiv.style.position = "absolute";
		this.loadingDiv.style.width = "161px";
		this.loadingDiv.style.height = "62px";
		this.loadingDiv.style.left = "50%";
		this.loadingDiv.style.top = "50%";
		this.loadingDiv.style.marginTop = "-31px";
		this.loadingDiv.style.marginLeft = "-81px";

		this.loadingDiv.style.visibility = "hidden"
		this.loadingDiv.style.display = "none";
		this.loadingDiv.style.backgroundImage = "url("+window['loadingDivBG']+")";
		this.loadingDiv.style.backgroundRepeat = "no-repeat";
		this.loadingDiv.style.zIndex = "1000001";
		
		var waittext = document.createElement("div");
		waittext.setAttribute("id",this.waitTextId);
		waittext.appendChild(document.createTextNode(window['loadingText']));
		waittext.style.position = "relative";
		waittext.style.top = "5px";
		waittext.style.left = "0px";
		waittext.style.width = "161px";
		waittext.style.textAlign = "center";
		waittext.style.fontWeight = "bold";
		waittext.style.color = "white";
	
		this.loadingDiv.appendChild(waittext);
		
		var loadingImgDiv = document.createElement("div");
		loadingImgDiv.setAttribute("id",this.contentDivId);
		loadingImgDiv.style.position = "relative";
		loadingImgDiv.style.top = "22px";
		loadingImgDiv.style.left = "15px";
		loadingImgDiv.appendChild(waitpic);
		
		this.loadingDiv.appendChild(loadingImgDiv);
		
		bodie.appendChild(this.loadingDiv);
		this.isInitialized = true;
	}
	
	this.reset = function ( )
	{
		this.loadingDiv.innerHTML = '';
		var waitpic = new Image();
		waitpic.src=window['loadingImage'];
		
		this.loadingDiv.style.position = "absolute";
		this.loadingDiv.style.width = "161px";
		this.loadingDiv.style.height = "62px";
		this.loadingDiv.style.left = "50%";
		this.loadingDiv.style.top = "50%";
		this.loadingDiv.style.marginTop = "-31px";
		this.loadingDiv.style.marginLeft = "-81px";

		this.loadingDiv.style.visibility = "hidden"
		this.loadingDiv.style.display = "none";
		this.loadingDiv.style.backgroundImage = "url("+window['loadingDivBG']+")";
		this.loadingDiv.style.backgroundRepeat = "no-repeat";
		this.loadingDiv.style.zIndex = "1000001";
		
		var waittext = document.createElement("div");
		waittext.setAttribute("id",this.waitTextId);
		waittext.appendChild(document.createTextNode(window['loadingText']));
		waittext.style.position = "relative";
		waittext.style.top = "5px";
		waittext.style.left = "5px";
		waittext.style.width = "161px";
		waittext.style.textAlign = "left";
		waittext.style.fontWeight = "bold";
		waittext.style.color = "white";
	
		this.loadingDiv.appendChild(waittext);
		
		var loadingImgDiv = document.createElement("div");
		loadingImgDiv.setAttribute("id",this.contentDivId);
		loadingImgDiv.style.position = "relative";
		loadingImgDiv.style.top = "22px";
		loadingImgDiv.style.left = "15px";
		loadingImgDiv.appendChild(waitpic);
		
		this.loadingDiv.appendChild(loadingImgDiv);	
	}
	
	this.toggleWait = function ( forcehide )
	{
 		if( this.isObject ( ) )
		{
			if (this.loadingDiv.style.visibility == "hidden" && !forcehide)
			{
				this.overlayDiv.style.display ="block";
				this.loadingDiv.style.visibility = "visible"
				this.loadingDiv.style.display ="block";
				if( IsIE6 )
					document.getElementsByTagName("body")[0].style.overflow="hidden";
			}
			else
			{
				this.overlayDiv.style.display = "none";
				this.loadingDiv.style.visibility = "hidden"
				this.loadingDiv.style.display ="none";
				if( IsIE6 )
					document.getElementsByTagName("body")[0].style.overflow="auto";
			}
 		 }
		else
		{
			if( !this.isInitialized )
				this.init( );
				
		 	this.toggleWait( forcehide );
		}
	}

	this.isActive = function( )
	{
		if( this.isObject( ) )
			return ( this.loadingDiv.style.visibility != 'hidden' );
	}

	this.isObject = function ( )
	{
		if( this.loadingDiv != null && this.overlayDiv != null )
			return true;
		else
			return false;
	}
	
	this.show = function ( )
	{
		if( !this.isInitialized )
			this.init( );

		if( !this.isActive( ) && this.isObject ( ) )
		{
			this.overlayDiv.style.display ="block";
			this.loadingDiv.style.visibility = "visible"
			this.loadingDiv.style.display ="block";
			if( IsIE6 )
				document.getElementsByTagName("body")[0].style.overflow = "hidden";	
		}
	}

	this.hide = function ( )
	{
		if( this.isActive( ) && this.isObject ( ) )
		{	
			this.overlayDiv.style.display    = 'none';
			this.loadingDiv.style.visibility = 'hidden';
			this.loadingDiv.style.display    = 'none';
			if( IsIE6 )
				document.getElementsByTagName( 'body' )[ 0 ].style.overflow = 'auto';
		}
	}
}

