/*
 * JTip
 * By Cody Lindley (http://www.codylindley.com)
 * Under an Attribution, Share Alike License
 * JTip is built on top of the very light weight jquery library.
 */


aigAjaxLoadedFunctions.push(function(container) {
	$("a.jTip", container).each(function() {
		var title = $(this).attr("title");
		$(this).removeAttr("title").hover(
			function(){ JT_show(this,title); },
			function(){ $('#JT').remove() }
		);
	});
});

function JT_show(linkOb,title){
	var width = 220;
	
	var useAjax = false;
	if ($(linkOb).hasClass("ajaxTip")) {
		useAjax = true;
		href = $(linkOb).attr("href").replace("http://www.answersingenesis.org","");
		stage = (href.indexOf("/stage") != -1 ? true : false);
		cat = href.replace("/stage","").split("/")[1];
		id = $(linkOb).attr("id");
		if (id.indexOf("-") != -1) {
			idParts = id.split("-");
			id = idParts[1];
			cat = idParts[0];
		}
		if (cat == "bios") width = 120;
		url = (stage ? "/stage" : "") + "/web/ajax/tooltip/" + cat + "/" + id;
	}	
	var moreOffset = 45;
	var offset = $(linkOb).offset();
	var x = offset.left + $(linkOb).width() + moreOffset;
	var y = offset.top;
	
	var direction = "JT_arrow_left";
	if (x + width + moreOffset > $(document).width()) {
		direction = "JT_arrow_right";
		x = offset.left - width - 20;
	}
	$("body").append("<div id='JT'><div id='"+direction+"'></div><div id='JT_copy'><div class='JT_loader'><div></div></div>");
	
	$('#JT').css({left: x+"px", top: y+"px", width: width});
	$('#JT').show();
	if (useAjax) $('#JT_copy').load(url);
	else $('#JT_copy').html( title );
}