
//	Inserts the given HTML at the end of the current document's body.
//
//	appendToBody ( string html );
function appendToBody(html){
	document.getElementsByTagName("body")[0].innerHTML += html;
}

//	Retrieves the X and Y coordinates for the given object.
//
//	objectLocation ( DOMobject obj );
function objectLocation(obj){
	var parent = obj;
	var x = obj.offsetLeft;
	var y = obj.offsetTop;
	
	while ( parent = parent.offsetParent ){
		x += parent.offsetLeft;
		y += parent.offsetTop;
	}
	return [x,y];
}

//	Sets the opacity for an object
//	Only percentages within the range of 0 - 100 are considered valid.
//
//	opacity ( DOMobject obj, int percent);
function opacity(obj, percent){
	if (percent >= 0 && percent <= 100) {
		obj.style.opacity = "0." + percent;
		obj.style.filter = "alpha(opacity = "+ percent +")";
		return true;
	}
	return false;
}


//	Creates an artificial window inside the current document
//
//	embedWindow ( string url ) ;	
function embedWindow(url){
	var win;
	
	if ((win = document.getElementById("mfxl_embedWin")) == null){
		// Creating window code
		var content = "<div id=\"mfxl_embedWin\">";
		content    += "<div id=\"mfxl_embedWinBG\" onclick=\"embedWindowClose();\"></div>";
		content    += "<div id=\"mfxl_embedWinContent\">";
		content	   += "<div id=\"mfxl_embedWinCloseBtn\"><a href=\"javascript:void(0);\" onclick=\"embedWindowClose();\">Close [X]</a></div>";
		content	   += "<iframe id=\"mfxl_embedWinFrame\" src=\"\"></iframe>";
		content	   += "</div>";
		content	   += "</div>";
		appendToBody(content);
		
		win = document.getElementById("mfxl_embedWin");
	}

	opacity(document.getElementById("mfxl_embedWinBG"), 50);
	
	document.getElementById("mfxl_embedWinFrame").src = url;
	win.style.visibility = "visible";
	
}

//	Hides a created embedWindow
//
//	embedWindowClose ( void ) ;	
function embedWindowClose(){

	if ((win = document.getElementById("mfxl_embedWin")) != null){
		
		
		document.getElementById("mfxl_embedWinFrame").src = "about:blank";
		//opacity(document.getElementById("embedWin"), 0);
		win.style.visibility = "hidden";
		return true;
	}
	return false;
}

//	Creates a text balloon at the given object with the given message.
//	Hides itself again onmouseout.
//
//	textBalloon ( DOMobject obj, string msg);	
function textBalloon(obj, msg){
	var balloon;
	
	if ( (balloon = document.getElementById("mfxl_textBalloon")) == null){
		// Creating balloon code

		var content = "<div id=\"mfxl_textBalloon\"></div>";
		appendToBody(content);
		
		balloon = document.getElementById("mfxl_textBalloon");
	}
	
	var objpos = objectLocation(obj);
	
	balloon.style.top = objpos[1] - 30 + "px";
	balloon.style.left = objpos[0] + "px";
	balloon.innerHTML = msg; //+ "-" + balloon.style.top + "/" + balloon.style.left;
	balloon.style.visibility = "visible";
	
	obj.onmouseout = function() {
		balloon.innerHTML = "";
		balloon.style.visibility = "hidden";
	
	}
}
