$(document).ready(function() {
	$('.aspSolTip, .aspSolTipLeft, .aspSolTipRight').live('mouseover', function() {
		aspSolTip.show(this);
	}).live('mouseout', function() {
		$('#aspSolTipContainer').remove();
	});
});

var aspSolTip = {
	tipWidth: 250,
	show: function(element) {
		var title = $(element).attr('title'),
			description = $.trim($(element).attr('description') || ''),
			d = document.documentElement,
			w = $(document).width(),
			hasArea = w - aspSolTip.getAbsoluteLeft(element),
			clElY = aspSolTip.getAbsoluteTop(element),
			clElX = null,
			arrowOffset = 0,
			position = 'left';
		//Decode from UTF-8
		description = decodeURIComponent(description);
		var inject = '<div id="aspSolTipContainer" style="width: ' + aspSolTip.tipWidth + 'px">';
		if($(element).hasClass('aspSolTipRight')) {
			position = 'right';
		} else if($(element).hasClass('aspSolTipLeft')) {
			position = 'left';
		} else if(hasArea > (aspSolTip.tipWidth + 100)) {
			position = 'right';
		}
		if(position == 'right') {
			inject += '<div id="aspSolTipArrowLeft"></div><div id="aspSolTipCloseLeft">';
			arrowOffset = aspSolTip.getElementWidth(element) + 11;
			clElX = aspSolTip.getAbsoluteLeft(element) + arrowOffset;
		} else {
			inject += '<div id="aspSolTipArrowRight" style="left: ' + (aspSolTip.tipWidth + 1 ) + 'px"></div><div id="aspSolTipCloseRight">';
			clElX = aspSolTip.getAbsoluteLeft(element) - (aspSolTip.tipWidth + 15);
		}
		inject += title + '</div>';
		if(description.length > 0) {
			inject += '<div id="aspSolTipContent">' + description + '</div>';
		}
		inject += '</div>';
		$('body').append(inject);
		$('#aspSolTipContainer').css({left: clElX + 'px', top: clElY + 'px'});
		$('#aspSolTipContainer').show();
	},
	getElementWidth: function (element) {
		return element.offsetWidth;
	},
	getAbsoluteLeft: function(element) {
		var oLeft = element.offsetLeft,
			oParent = null;
		while(element.offsetParent != null) {
			oParent = element.offsetParent;
			oLeft += oParent.offsetLeft;
			element = oParent;
		}
		return oLeft;
	},
	getAbsoluteTop: function(element) {
		var oTop = element.offsetTop,
			oParent = null;
		while(element.offsetParent != null) {
			oParent = element.offsetParent;
			oTop += oParent.offsetTop;
			element = oParent;
		}
		return oTop;
	}
};
