$(document).ready(initTips);
			
function initTips()
{
	$("a.tip")
		.hover(function(){ showTip(this.rel, this.href, this.id)},function(){$('#tipWindow').remove()})
		.click(function(){ return false; });
}
			
function showTip(message, url, id)
{
	var de = document.documentElement;
	var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(id);
	var posY = getAbsoluteTop(id) + 20;
	
	var queryString = url.replace(/^[^\?]+\??/,'');
	var params = parseQuery(queryString);
	
	if(params['width'] === undefined) params['width'] = 250;
	
	var content = 
		'<div id="tipWindow" style="width:' + (params['width'] * 1) + 'px">'
		+ message
		+ '</div>';
	
	if (hasArea > ((params['width'] * 1) + 75))
	{
		var arrowOffset = getElementWidth(id) + 11;
		var posX = getAbsoluteLeft(id) + arrowOffset; 	
	}
	else
	{
		var posX = getAbsoluteLeft(id) - ((params['width'] * 1) + 15);		
	}
	
	$("body").append(content);
	
	$("#tipWindow").css({left: posX + "px", top: posY + "px"});
	$("#tipWindow").fadeIn(200);	
}

function parseQuery(query) 
{
	var Params = new Object();
	
	if (!query) return Params;
	
	var Pairs = query.split(/[;&]/);
	
	for (var i = 0; i < Pairs.length; i++)
	{
		var KeyVal = Pairs[i].split('=');
		if (!KeyVal || KeyVal.length != 2 ) continue;
		var key = unescape(KeyVal[0]);
		var val = unescape(KeyVal[1]);
		val = val.replace(/\+/g, ' ');
		Params[key] = val;
	}
	
	return Params;
}


function getElementWidth(objectId) 
{
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) 
{	
	o = document.getElementById(objectId);
	oLeft = o.offsetLeft;           
	while(o.offsetParent != null) 
	{
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent
	}
	return oLeft;
}

function getAbsoluteTop(objectId) 
{
	o = document.getElementById(objectId);
	oTop = o.offsetTop; 
	while(o.offsetParent != null) 
	{ 
		oParent = o.offsetParent;  
		oTop += oParent.offsetTop;
		o = oParent;
	}
	return oTop;
}