$(document).ready(function(){
	// thumbnail tooltip.
	$("a[rel*=tooltip]").hover(function(e){
		$('#tooltip').remove();//jh added this so old tooltip disappears
		var aPos = findPos(this);
		var xPos = aPos[1] - 8;
		var yPos = aPos[0] + $(this).width() + 5;
		var scrollVis = getScroll()[1] + getWindowSize()[1];

		$("body").append("<div id='tooltip'><div class='tt_arrow'></div><div class='tt_content'>" + $("#" + $(this).attr('alt')).html() + "</div></div>");
		$("#tooltip").css("top", xPos + "px").css("left", yPos + "px");

		var tipHeight = xPos + $("#tooltip").height();
		var tipOver = scrollVis - tipHeight;
		if(tipOver < 0){
			$("#tooltip").children(".tt_content:first").css("margin-top", tipOver + "px");
		}
		$("#tooltip").show();
	}, function(){
		//$('#tooltip').remove();
	});
	$(document).click(function(e){
		$('#tooltip').remove();  //jh added this to keep the tooltip ontop until the user clicks somewhere else
	});
});

function findPos(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function getScroll() {
	var scrX = scrY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrY = window.pageYOffset;
		scrX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrY = document.body.scrollTop;
		scrX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6
		scrY = document.documentElement.scrollTop;
		scrX = document.documentElement.scrollLeft;
	}
	return [scrX,scrY];
}
function getWindowSize() {
	var nWidth = nHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		nWidth = window.innerWidth;
		nHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE6
		nWidth = document.documentElement.clientWidth;
		nHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE4
		nWidth = document.body.clientWidth;
		nHeight = document.body.clientHeight;
	}
	return [nWidth,nHeight];
}