/*
 * 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
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = -100;
		yOffset = -15;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		//change offset;
		var ths = $(this);
		
		this.t = this.title.replace("::","<br/>");;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		
		//now readjust the offsets based on width
		a = getWidth($("#tooltip"));
		xOffset = 0 - a - 100;
		
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});			
};


this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		locked = false;
		locked_x = 600
		locked_y = 100;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.sg_screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	

		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='sg_screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");		
		
		/*Tweaks by Ben */
		var top = e.pageY - xOffset;
		var left = e.pageX + yOffset;
		if (locked == true) {
			top = locked_y;
			left = locked_x;
		}
		$("#sg_screenshot")
			.css("top",(top) + "px")
			.css("left",(left) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#sg_screenshot").remove();
    });	
    
  if (!locked) {
	$("a.sg_screenshot").mousemove(function(e){
		$("#sg_screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	
	}
};


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

function getWidth(obj) {
	return (obj.innerWidth());
}