/****
*	@Name: Loader
*	@Description: This library intends to draw a loading image into some div (or a whole document if called through 'body' selector)
*	@Author: George Willian Condomitti
*	@Company: 3mw Comunicação e Tecnologia
*	@Date: 15/02/2011
*	@Version: 1.0
*
*	Use:
*		$([selector]).loader({ [options] });
*	Possible options:
*		size: 'small' | 'big'
*		show: true | false
*	Example:
*		$('#myDiv').loader(); //this would make up the loader into myDiv
*		$('#myDiv').loader({ show : false }); //this would hide the loading from myDiv
*
*	NOTE: Making a loading into a X div changes the X div's position to relative if the original position is not already defined so nor absolute,
*			so be aware that this could affect the looking of your layout or cause weird behavior if not carefully handled.
*
***/

jQuery.fn.loader = function(){
	var args = arguments[0];
	var o = $(this[0]);
	var loaderClass = null;
	var show = null;
	
	if(args != null && typeof(args) != 'undefined'){
		show = args.show;
	}

	if(show == null || typeof(show) == 'undefined'){
		show = true;
	}
	if(show && $(o).find('div[id=loader_container]').length == 0){
			if(args != null && typeof(args) != 'undefined'){
				loaderClass = args.size;
			}

	
			switch(loaderClass){
				case 'big':
					loaderClass = 'loader_big_loading';
				break;
				default:
					loaderClass = 'loader_small_loading';
			}
			//$(o).html('')
				var strLoaderDiv = "<div id=\"loader_container\" class=\"" + loaderClass + "\" style=\"position : absolute;width:100%;height:100%; top:0;left:0; z-index:15000\"><\/div>";
			if($(o).css('position') != 'absolute'){
				$(o).css({ 'position' : 'relative' });
			}
			$(o).append(strLoaderDiv);
			$('#loader_container').fadeTo('fast',0.5);
	} else if(!show){
		$(o).find('div[id=loader_container]').fadeOut(
						function(){
							$(o).find('div[id=loader_container]').remove();
						}
		);
	}

};

jQuery.fn.loaderSimple = function(){
	var args = arguments[0];
	var o = $(this[0]);
	
			var strLoaderDiv = "<div id=\"loader_container_simple\" >Carregando...<\/div>";
			$(o).html(strLoaderDiv)
			
};


jQuery.fn.loaderSimplePW = function(){
	var args = arguments[0];
	var o = $(this[0]);
	
			var strLoaderDiv = "<div id=\"loader_p_w\" >&nbsp;<\/div>";
			$(o).html(strLoaderDiv)
			
};

jQuery.fn.loaderSimplePB = function(){
	var args = arguments[0];
	var o = $(this[0]);
	
			var strLoaderDiv = "<div id=\"loader_p_b\" >&nbsp;<\/div>";
			$(o).html(strLoaderDiv)
			
};
