/**
*
*	simpleTooltip jQuery plugin, by Marius ILIE
*	adjusted by A. Lowijs , handles images by putting image|width|height|filename in the title tag of the element
*	visit http://dev.mariusilie.net for details
*
**/
(function($){ $.fn.simpletooltip = function(){

	return this.each(function() {
		var text = $(this).attr("title");
		$(this).attr("title", "");
		if(text!=undefined) {

			if((match=text.match(/^image\|(\d+)\|(\d+)\|(.+)$/))!==null) {
				var innerHtml = "<img src=\"" + match[3] + "\" width=\""
								+ match[1]+"\" height=\""+ match[2]
								+ "\" border=\"1\" class=\"simpleTooltip\" alt=\"\">";
				var width = match[1];
				var height = match[2];
			} else 
				var innerHtml = text;

			$(this).hover(function(e){

				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				$(this).attr("title", ""); 

				//Adjustment making sure the simleToolTip layer doesnt exists, otherwise remove it
				if($("#simpleTooltip").length>0)
					$("#simpleTooltip").remove();

				$("body").append("<div id='simpleTooltip'>"+innerHtml+"</div>");
				$("#simpleTooltip").css("position", "absolute");
				$("#simpleTooltip").css("z-index", "100");
				$("#simpleTooltip").css("display", "none");

				//Adjustment setting the height and width for the simpleToolTip div
				if(typeof(width)!=undefined && typeof(height)!=undefined) {
					$("#simpleTooltip").width(width);
					$("#simpleTooltip").height(height);
				}
				if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
				else var tipWidth = $("#simpleTooltip").width()
				$("#simpleTooltip").width(tipWidth);
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			}, function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});

			//Adjustment setting the mouseout handle so the simpleToolTip div disappears again
			//When hover didnt work (can happen when you move reallly fast)
			/*
			$(this).mouseout(function(e){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});*/

			$(this).mousemove(function(e){
				if($("#simpleTooltip").length>0) {
					var tipX = e.pageX + 12;
					var tipY = e.pageY + 12;
					var tipWidth = $("#simpleTooltip").outerWidth(true);
					var tipHeight = $("#simpleTooltip").outerHeight(true);
					if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
					if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
					$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
				}
			});
		}
	});
}})(jQuery);


jQuery(document).ready(function(){
	jQuery(".simpleTooltip").simpletooltip();
});
