/**
 * Preloader scripts
 *
 * @copyright (c) 2004-2007, SWsoft
 */
function SbPreloader() {
	this._enabled = true;

	var preloader = this;
	addEvent(self, 'load', function (event) {preloader.hide();});
	addEvent(self, 'beforeunload', function (event) {preloader.show();});
}

SbPreloader.prototype.isEnabled = function() {
	return this._enabled;
}

SbPreloader.prototype.disable = function() {
	this._enabled = false;
}

SbPreloader.prototype.enable = function() {
	this._enabled = true;
}

SbPreloader.prototype.show = function() {
	if (this._enabled) {
		this.showBackground();
		this._toggleMessage(1);
	}
}

SbPreloader.prototype.showBackground = function() {
	this._toggleBackground(1);
}

SbPreloader.prototype.hide = function() {
	if (this._enabled) {
		this.hideBackground();
		this._toggleMessage(0);
	}
}

SbPreloader.prototype.hideBackground = function() {
	this._toggleBackground(0);
}

SbPreloader.prototype._toggleBackground = function(fl) {
	var x,y;
	x = getScreenWidth();
	y = getScreenHeight();
	var table=document.getElementById('SB_loader_table');
	var td=document.getElementById('SB_loader_td');
	var el=document.getElementById('DIV_DESKTOP');
	if(null!=el) {
		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.width = x + "px";
		el.style.height = y + "px";
		el.style.zIndex = 1;
	}
	var top = (y/2) - 50;
	var left = (x/2) - 200;
	if( left<=0 ) left = 10;
	if (!document.all) {
		td.style.width = window.innerWidth +"px";
		td.style.height = window.innerHeight +"px";//-122
	}
	table.style.display=(fl==1)?'block':'none';
}

SbPreloader.prototype._toggleMessage = function(fl) {
	var iframe=document.getElementById('SB_loader_iframe');
	var el=document.getElementById('loader');
	var x,y;
	x = getScreenWidth();
	y = getScreenHeight();
	var top = (y/2) - 50;
	var left = (x/2) - 200;
	if( left<=0 ) left = 10;

	iframe.style.left = left + "px";
	iframe.style.top = top + "px";
	iframe.style.display=(fl==1)?'block':'none';
	el.style.visibility = (fl==1)?'visible':'hidden';
	el.style.display = (fl==1)?'block':'none';
	el.style.left = left + "px"
	el.style.top = top + "px";
}