/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 
 
 ** MODIFIED (somewhat heavily) BY 76design **
 
 */
 


this.tooltip = function(){	

	$("a.tooltip").hover(function(e){		

		$(this).parent().find('.popupdesc').html();
		var coords = relMouseCoords(e);
		$("body").prepend("<div id='tooltip'>"+ $(this).parent().find('.popupdesc').html() +"</div>");

		var tooltipHeight = $('#tooltip').height();
		
		
		// the css left thinger may seem redundant ... or you'd epxect it to i dunno ... put the tooltip in an awkward position ... but uh, if you get rid of it ... it breaks in IE6. so .. 
		$("#tooltip")
			.css("top",(coords[0] - $('#tooltip').height()) + "px")
			.css("left",((coords[1]) - $('#tooltip').width()) + "px")
			.fadeIn('fast');
    },
	
	function(){
		$("#tooltip").remove();
    });
	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - $('#tooltip').height()) + "px")
			.css("left",(e.pageX + 10) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});



// --> http://www.quirksmode.org/js/events_properties.html
function relMouseCoords(e) {
	var posx = 0;
	var posy = 0;
	
	if (!e) var e = window.event;
	
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	return new Array(posx, posy); 
}
