/**
 *
 * Infodiv.js
 * Displays an infolayer
 * 
 * dependencies		prototype Javascript framework
 * @author			Alex Buchgeher <a.buchgeher(at.)cyberhouse(dot.)at>
 *
 */

var DEBUG = false;	// debug mode on? use additionally the &debug=1 getvar to get debugging output
var offsetX = 150;	// offset of infolayer to trigger-element in pixels (x-axis)
var offsetY = 0;	// offset of infolayer to trigger-element in pixels (y-axis)

/**
 * Displays and positions the infodiv layer.
 * Inserts the given infotext. 
 * @author			Alex Buchgeher <a.buchgeher(at.)cyberhouse(dot.)at>
 * @param object	Anchor Element Pointer
 * @param string	Infotext to be displayed
 * @return void
 */
function infodivIn(el, title, infoText) {
//	if(!isDebugModeOn()) { return; }
	var infoBox = $("infoBox");
	
		// first of all set element visible because 
		// of some IE javascript-engine rendering bugs
	infoBox.style.display = "block";

		// headline
	var headerEl = $("infoBox-header");
	headerEl.appendChild(document.createTextNode(title));
	
		// infotext
	var infoTextEl = $("infoBox-infotext");
	infoTextEl.appendChild(document.createTextNode(infoText));
	 
		// positioning
	var elPos = Position.cumulativeOffset(el);
	var x = elPos[0];
	var y = elPos[1];
	
	x+= offsetX;
	y+= offsetY;
	
	infoBox.style.top = y + "px";
	infoBox.style.left = x + "px";
}

/**
 * Hides the infodiv layer.
 * Deletes the infotext. 
 * @author	Alex Buchgeher <a.buchgeher(at.)cyberhouse(dot.)at>
 * @param object	Anchor Element Pointer
 * @return void
 */
function infodivOut(el) {
	var infoBox = $("infoBox");
	var infoTextEl = $("infoBox-infotext");
	var headerEl = $("infoBox-header");
	try {
		var textNodeElem = infoTextEl.firstChild;
		Element.remove(textNodeElem);
	} catch(e) {}
	try {
		var textNodeElem = headerEl.firstChild;
		Element.remove(textNodeElem);
	} catch(e) {}
	infoBox.style.display = "none";
}









/**
 * Returns the get-parameter depending
 * on the given key
 * @author	Alex Buchgeher <a.buchgeher(at.)cyberhouse(dot.)at>
 * @param string
 * @return string
 */
function _GET(key) {
	var url = window.location.search;
	url = url.replace(/^\?/, '');
	if(url != '') {
		var getParams = url.split('&');
		var getKeyVal = new Array();
		for(var i=0; i<getParams.length; i++) {
			var ar = getParams[i].split('=');
			getKeyVal[ar[0]] = unescape(ar[1]);
		}
		return getKeyVal[key] == undefined ? '' : getKeyVal[key];
	}
	return '';
}

function isDebugModeOn() {
	return 	DEBUG && _GET("debug") == '1';
}

/**
 * Debugging function
 * Leaks memory when using IE
 * @author	Alex Buchgeher <a.buchgeher(at.)cyberhouse(dot.)at>
 * @param string The string to debug
 * @param string an optional key (by default set to debug)
 * @return void
 * @see DEBUG : boolean, global
 */
function debug(string, key) {
	if(!isDebugModeOn()) { return; }
	if(document.debugCnt == undefined) {
		document.debugCnt = 0;
	}
	if(key == '') {
		key = "debug";
	}
	var debug = $(key);
	if(debug == null) {
		document.debugCnt++;
		var top = 20 * document.debugCnt;
		var body = document.getElementsByTagName("body")[0];
		debug = document.createElement("div");
		debug.id = key;
		debug.style.position = "absolute";
		debug.style.right = "0px";
		debug.style.top = top + "px";
		debug.style.border = "2px solid #000";
		debug.style.background = "#fff";
		body.appendChild(debug);
	}
	debug.innerHTML = "<code style=\"color: red;\">" + key + "</code> | <code>" + string + "</code>";
	return;
}
