/*
Msg 1.1.0 (c) 2008 by J. Reijers

### EXAMPLE ###

<body>
<script type="text/javascript">
with (Msg) {
	colour = "#FFFFFF";
	textSize = "9px";
	init();
}
</script>
<img src="picture.gif" onClick="Msg.show('Hello!')" onMouseOut="Msg.hide()">

*/

function _Msg() {
	this.x = -1;
	this.y = -1;
	this.center = true;
	this.centerX = true;
	this.centerY = true;
	this.colour = "";
	this.border = "1px solid black";
	this.text = "";
	this.textSize = "10px";
	this.textColour = "black";
	this.textWeight = "";
	this.padding = 2;
	this.opacity = 100;
	this.zIndex = 1000;
	this.initialised = false;

	_Msg.prototype.init = function() {
		if (this.textSize == 0) this.textSize = this.height;
		this.centerX = (this.x == -1);
		this.centerY = (this.y == -1);
		this.center = (this.centerX && this.centerY);
		document.write("<div id='divMsg' style=\"position: absolute; left: " + this.x + "; top: " + this.y + "; z-index: " + this.zIndex + "; border: " + this.border + "; background-color: " + this.colour + "; font-size: " + this.textSize + "; font-weight: " + this.textWeight + "; color: " + this.textColour + "; display: none\">" + this.text + "</div>");
		this.div = document.getElementById("divMsg");
		this.initialised = true;
		this.setOpacity();
	}

	_Msg.prototype.setOpacity = function(value) {
		if (!this.initialised || this.disabled) return false;
		if (typeof value == "undefined") var value = this.opacity;
		if (value < 0) value = 0;
		this.div.style.filter = "alpha(opacity=" + value + ")";
		this.div.style.opacity = value / 100;
		this.div.style.mozOpacity = value / 100;
		this.opacity = value;
	}

	_Msg.prototype.show = function(text) {
		if (!this.initialised) return false;
		if (typeof text == "undefined") var text = this.text; else {
			this.text = text;
			if (this.centerX) this.x = -1;
			if (this.centerY) this.y = -1;
		}
		this.div.innerHTML = text;
		this.div.style.display = "";
		if (this.x == -1) {
			this.x = parseInt(this.div.parentNode.offsetWidth / 2, 10) - parseInt(this.div.offsetWidth / 2, 10);
			this.div.style.left = this.x;
		}
		if (this.y == -1) {
			this.y = parseInt(this.div.parentNode.offsetHeight / 2, 10) - parseInt(this.div.offsetHeight / 2, 10);
			this.div.style.top = this.y;
		}
	}

	_Msg.prototype.hide = function() {
		if (!this.initialised) return false;
		this.div.style.display = "none";
	}
}

function addEvent(o, e, f) {
	o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent ? o.attachEvent("on" + e, f) : o["on" + e] = f;
}

Msg = new _Msg();
