$(document).ready(function(){
	$(".tooltip img").mouseover(function(){
		var id = $(this).attr("id");
		var type = $(this).attr("class");
		var content = null;
		
		$(this).after("<div><p class=\"loading\"><img src=\"/global/images/forms/tooltip_loading.gif\" alt=\"Loading...\" /><em>Loading...</em></p></div>");
		var tooltip = $(this).parent("p").children("div");
	
		if(type == "required"){ 
			$(tooltip).children().remove();
			$(tooltip).append("<p>Required</p>");
		}else{
			$.ajax({
				type: "GET",
				url: "/global/scripts/ajax/tooltip.php",
				cache: true,
				data: { id: id },
				success: function(data){
					content = data;					
				},
				complete: function(){
					if(content == null){ content = "<p>Tooltip could not be found.</p>"; }
					$(tooltip).children().remove();
					$(tooltip).append(content);
				}
			});
		}
	}).mouseout(function(){
	 	$(this).parents("p").children("div").remove();
	});
});

function StopEvent(e){
	StopPropagation(e);
	CancelEvent(e);
}

function StopPropagation(e){
	if(e.stopPropagation){
		e.stopPropagation();
	}else if(e.cancelBubble){
		e.cancelBubble = true;
	}
}

function CancelEvent(e){
	if(e.preventDefault){
		e.preventDefault();
	}else if($(window).event){ //cannot check for e.returnValue
		e.returnValue = false;
	}
}