var t;

function attachTooltips(xOffset, yOffset) {
	// I swear these are around the wrong way
	if (typeof xOffset == 'undefined') {
		xOffset = 10;
	}
	if (typeof yOffset == 'undefined') {
		yOffset = 20;		
	}
	$(".tooltip").hover(function(e){
		if ($(this).hasClass('integriaBrandsTooltip')) {	// hacky, but I'm sick of this
			xOffset = 280;
			yOffset = -20;
		}
		
		this.t = this.title;
		this.title = "";
		if ($(this).attr('rel') && $('#'+$(this).attr('rel')).length) {
			this.t = $('#'+$(this).attr('rel')).html();
		}
		$("body").append("<div id='tooltip'>"+ this.t +"</div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("z-index","999")
			.css("width","200px")
			.fadeIn("fast");		
    },
	function(){
		//setTimeout(function() {
			if ($(this).attr('rel') && $('#'+$(this).attr('rel')).length) {
				this.title = '';
			}
			else {
				this.title = this.t;
			}
			xOffset = 10;
			yOffset = 20;		

			$("#tooltip").remove();
		//}, 1000);
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
}
$(function() {
	attachTooltips();
});
