/*
 * 	Object can be executed by 2 ways:
 * 
 * 	1. automatically by passing arguments to contructor (element, show event, hide event, hint text)
 * 		ex.: new loadingBarClass('.button', 'mouseover', 'mouseout', 'Here will be hint text');
 * 
 * 	2. maunally by using show, hide on custom events
 * 		ex.: new loadingBarClass().show(); ... new loadingBarClass().hide();
 * 
 */

function loadingBarClass(obj, s, h, t){
	
	this.loader = {};
	this.loaderSelector = '.notification-popup';
	this.defaultText = 'Loading ...';
	this.obj = obj ? (typeof(obj)=='object' ? obj : jQuery(obj)) : {};
	this.s = s ? s : {};
	this.h = h ? h : {};
	
	var self = this;
	
	this.init = function()
	{
		this._constructLoader();
		
		if(this.obj && this.s && this.h && this.obj.length && this.s.length && this.h.length)
		{
			jQuery(document).ready( function(){
				this.obj
					.live(this.s, function(){ self.show(t); })
					.live(this.h, function(){ self.hide(); });
			});
		}
	}
	
	this.show = function(text)
	{
		if(text) 
		{
			jQuery('.message',this.loader).html(text);
		}
	
		this.loader.removeClass('hidden');
	}
	
	this.hide = function()
	{
		jQuery('.message',this.loader).html( this.defaultText );
		this.loader.addClass('hidden');
	}
	
	this._constructLoader = function()
	{
		if(jQuery(this.loaderSelector).length)
		{
			this.loader = jQuery(this.loaderSelector);
		}
		else
		{
			var div = jQuery('<div class="notification-popup hidden"><div class="message">' + this.defaultText + '</div></div>');
			div.insertBefore('#admin-bar');
			this.loader = div;
		}
	}
	
	
	this.init();
	
	return this;
}


