// splasher (c) Mikolaj Gasior <mikolaj.gasior@webcoders.pl>

function mSplash(divName, options) {
	this.divName	= divName;
	this.className	= '';
	for (o in options) {
		if (o == 'class') {
			if (options[o] != '')
				this.className	= options[o];
		}
		if (o == 'loader') {
			if (options[o] != '')
				this.loader		= options[o];
		}
	}
}

mSplash.prototype = {
	checkIfExists: function() {
		if (document.getElementById(this.divName) == null)
			return false;
		else
			return true;
	},
	show: function(tekst) {
		if (this.checkIfExists()) {
			document.getElementById(this.divName+"___text").innerHTML=(this.loader!=''?'<img src="'+this.loader+'" alt=""/><br/>':'')+tekst;
			//$('#'+this.divName).DropInUp(500);
			//if (document.getElementById('all')!==null) {
				$('#'+this.divName).css('width', '100%');
				$('#'+this.divName).css('height', '100%');
			//}
			document.getElementById(this.divName).style.display='block';
			document.getElementById(this.divName+"___window").style.display='block';
		} else {
			this.append();
			if (this.checkIfExists()) {
				document.getElementById(this.divName+"___text").innerHTML=(this.loader!=''?'<img src="'+this.loader+'" alt=""/><br/>':'')+tekst;
				//$('#'+this.divName).DropInUp(500);
				//if (document.getElementById('all')!==null) {
					$('#'+this.divName).css('width', '100%');
					$('#'+this.divName).css('height', '100%');
				//}
				document.getElementById(this.divName).style.display='block';
				document.getElementById(this.divName+"___window").style.display='block';
			}
		}
		return true;
	},
	append: function() {
		var d = document.createElement('DIV');
		d.id = this.divName;
		d.innerHTML = "&nbsp;";
		var d_window = document.createElement('DIV');
		d_window.id = this.divName+"___window";
		d_window.innerHTML = "&nbsp;";
			var d_window_center = document.createElement('CENTER');
			d_window.appendChild(d_window_center);
				var d_window_loading = document.createElement('DIV');
				d_window_loading.id = this.divName+"___loading";
				d_window_loading.innerHTML = "&nbsp;";
				var d_window_text = document.createElement('DIV');
				d_window_text.id = this.divName+"___text";
				d_window_text.innerHTML = "&nbsp;";
				d_window_center.appendChild(d_window_loading);
				d_window_center.appendChild(d_window_text);
		document.body.appendChild(d);
		document.body.appendChild(d_window);
		return true;
	},
	hide: function(czas) {
		if (this.checkIfExists()) {
			document.getElementById(this.divName).style.display='none';
			document.getElementById(this.divName+"___window").style.display='none';
			//$('#'+this.divName).DropOutUp(500);
		}
		return true;
	}
}

mSplash = new mSplash('splash', {loader: BASE_URL+'templates/default/images/ajax-loader.gif' });
