//!-----------------------------------------
// @file		loader.js
// @desc		loade
// @author	EB
// @note		
//
// @history 	
//	12-2-2009 15:34, EB : Initially created
//  
//
//!-----------------------------------------

var Loader = new Class({
	Implements: [Options],
	
	options: {
		sLoaderID : 'loader',
		sLoaderText : $empty,
		bCursor: false,
		bPositionAfterElement: true //Positioneer loader Div direct achter meegegeven element (absoluut)
	},
	
	initialize: function(element, options)
	{
		
		this.setOptions(options);
		this.oElement = element;
	},	
	
	show : function()
	{
		this.bLoading = true;
		if (this.options.bCursor)
		{
			$(document.body).setStyle('cursor', 'wait');
		}
		else 
		{
			this.oLoaderDiv = $(this.options.sLoaderID);
			//Als loader nog niet bestaat loader aanmaken
			if (!$chk(this.oLoaderDiv))
			{
				this.oLoaderDiv = new Element('div', 
				{
					'id' : this.options.sLoaderID,
					'styles' : {
						'z-index' : '100000'
					}
				}).inject(document.body);
			}
			
			if (this.options.sLoaderText.length > 0)
			{
				this.oLoaderDiv.set('text', this.options.sLoaderText);
			}
			
			//Positie loader div instellen
			if (this.options.bPositionAfterElement)
			{
				var oCoords = this.oElement.getCoordinates();
				this.oLoaderDiv.setStyles({'left': (oCoords.left+oCoords.width),'top':oCoords.top});	
			}
			this.oLoaderDiv.setStyle('display', 'block');
		}
	},

	hide : function()
	{
		if (this.options.bCursor)
		{
			$(document.body).setStyle('cursor', 'default');
		}
		else
		{
			this.oLoaderDiv.setStyle('display','none');
		}
		this.bLoading = false;
	},
	
	isLoading : function()
	{
		return this.bLoading;
	}
});