// This functions provide the functionality for an extremely simple tooltip
// which uses the elements title attribute for infobox contents.
// - by TeeK

// The first parameter is the element triggering the tooltip.
// The second one is the type of tooltip (for special cases):
// type == 0 standard
// type == 1 document link
// type == 2 use manual input from the third parameter

function ibStart(element, type, input) {

	// check if #infobox already exists and remove it (just to be sure ... ;)
	$("#infobox").remove();

	// get title, store it in data object and remove it from the element
	if (element.attr("title") !== undefined) {
		element.data("title", element.attr("title"));
		element.removeAttr("title");
	}

	// get title
	var tmpTitle = element.data("title");

	// prepare htmlcode variable
	var htmlcode = "";

	// types ...
	if (type == 0) {
		// standard
		htmlcode = tmpTitle;
	} else if (type == 1) {
		// prepare html content for document infobox
		var seperatorPos = tmpTitle.indexOf("|");
		var fileSize = tmpTitle.substr(0, seperatorPos - 1);
		var fileEnding = tmpTitle.substr(seperatorPos + 2, tmpTitle.length);
		htmlcode = "<strong>"+element.html()+"</strong><br />";
		htmlcode += '<img src="./imgs/' + fileEnding + '.gif" border="0px" alt="" id="type_img" align="left" /><br />';
		htmlcode += fileEnding.toUpperCase() + '-Datei<br />';
		htmlcode += 'Größe: <code>' + fileSize + '</code><br clear="all" />';
		htmlcode += '<p class="small greyed">Klicken Sie, um die Datei zu öffnen.</p>';
	} else if (type == 2) {
		htmlcode = input;
	}

	// create infobox with htmlcode content
	$("body").append('<div id="infobox"><div>' + htmlcode + '</div></div>');

	// calculate position of toolbox and place it correctly
	var elementPos = element.position();
	var boxLeft = elementPos.left;
	var boxTop = elementPos.top;
	$("#infobox").css({"left" : (boxLeft - 170) + "px", "top" : (boxTop - 3) + "px"});
}

function ibEnd() {
	$("#infobox").remove();
}
