function waiting(options){
    this.waitingStyle = {
        zIndex:'999',
        position:'absolute',
        width:'160px',
        height:'40px',
        backgroundColor:'#000',
        opacity:'0.5',
	textAlign: 'center',
	paddingTop: '20px',
	borderRadius: '5px',
	boxShadow:'0 0 10px #fff',
	opacity:'1'
    };
    this.bgStyle = {
        display: 'none',
        zIndex:'1',
//        top:'0px',
//        left:'0px',
        position:'relative',
//        width:'100%',
//        height:'100%',
        backgroundColor:'#bccce2',
        opacity:'0.3',
	boxShadow: '0 0 5px #bccce2'
    };

    this.waitingImg = 'data:image/gif;base64,R0lGODlhQAAQAJkCAJ6ens3Nzf///AAAACH5BAUKAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAQAAQAKAAAAD///wCMYSPqcvtD6OctNqLs16h+w8G2wiEpkdu55lqq9lmbxhjM1hf95dbO9oLCofEovG4KQAAIfkEBQoAAgAsBAAEACQACACh/v//zc3NAAAAAAAAAiOMjxnCAg+jBKqe5qZ+1uK9ddUHTqJCltGZpCrHXs27xob7FgAh+QQFCgADACwEAAQAOAAIAKGenp7+///Nzc0AAAACOoSPCcMjD6MUbYSLsw6qnzqFULWVmOeBYkiaJdqpq9S6GqzI89jYG57Q7Sg9XwaIEO5qRg7SoJwxjQUAIfkEBQoAAgAsGAAEACQACAChnp6ezc3NAAAAAAAAAiOEjwnCEg+jDKqe5qZ+1uK9ddUHTqJCltGZpCrHXs27xob7FgAh+QQJHgAAACwAAAAAQAAQAKAAAACenp4CMISPqcvtD6OctNqLs948+A+GAdeJpkdu55lqq9lmrxhjc1hfN5hb+9cLCofEolFTAAA7';
    this.bgDiv = null;
    this.waitingDiv = null;
    this.init();
    this.setOptions(options);
    this.target = document.body;
    
}
waiting.prototype.load = function(target, options){
	if (typeof(target)!='undefined' && typeof(target)!='string'){
            this.target = target;
            this.setOptions(options);
            this.show();
        }
    };
waiting.prototype.init = function(){
        var that = this;
        var uid = Math.floor(Math.random()*0x100000).toString(16);
	var waitingId = 'waitingDiv_' + uid;
        var bgId = 'bgDiv_' + uid;

	this.waitingDiv = cE('div',{id:waitingId},this.waitingStyle);
	this.waitingDiv.innerHTML = '<img src="' + this.waitingImg +'"/>'
        this.bgDiv = cE('div',{id:bgId},this.bgStyle);;
	this.bgDiv.appendChild(this.waitingDiv); 
    };
waiting.prototype.show = function(){
	var that = this;
	if (typeof(this.target.innerHTML)=='undefined'){
	    var object = this.target;
	    for (var i=0; i<object.length; i++){
		this.target = object[i]
		this.show()
	    }
	    return true;
	}
	this.target.appendChild(this.bgDiv);
	$(this.bgDiv).fadeIn('fast');
	this.centralize(this.bgDiv);	
    };
waiting.prototype.hide = function(){
	var that = this;
        $(this.bgDiv).fadeOut('fast');
    },
waiting.prototype.setOptions = function(options){
	if (typeof(options) == 'object'){
		var that = this;
		if(options.bgOpacity)this.bgDiv.style.opacity = options.bgOpacity;
		    else this.bgDiv.style.opacity = "0.2";
		if(options.bgColor)this.bgDiv.style.backgroundColor = options.bgColor;
		    else this.bgDiv.style.backgroundColor = "#bccce2";
		if (options.waitingGif == true) this.waitingDiv.style.display = '';
		    else
			this.waitingDiv.style.display = 'none';
	}
    };
waiting.prototype.centralize = function(){
	var el = this.bgDiv;
	if (this.target != document.body){
	    var maxHeight = this.target.clientHeight;
	    var maxWidth = this.target.clientWidth;
	}else{
	    var maxHeight = (window.innerHeight)?(window.innerHeight):(document.documentElement.clientHeight);
	    var maxWidth = (window.innerWidth)?(window.innerWidth):(document.documentElement.clientWidth);
	}
        el.style.height = maxHeight  +'px';
	el.style.marginTop = '-' + maxHeight +'px';
	var top = ((maxHeight/2)-(this.waitingDiv.clientHeight/2)).toFixed(0);
	var left = ((maxWidth/2)-(this.waitingDiv.clientWidth/2)).toFixed(0);
	
	this.waitingDiv.style.top = top + 'px';
	this.waitingDiv.style.left = left + 'px';
	
	
        
	
}
