/*
 * Url preview 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.screenshotPreview = function(){	
		/* CONFIG */
		
		xOffset = document.documentElement.clientHeight/2;	
		yOffset = document.documentElement.clientWidth/2;			
		//yOffset = $("#screenshot").height();	
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		//alert(this.rel);
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		//var vp = xOffset + document.documentElement.scrollTop
		var browserName = navigator.userAgent.toLowerCase();
		if (browserName.indexOf("safari") != -1) 
		{
			var vp = xOffset + (document.body.scrollTop) 		
		}
		else
		{
			var vp = xOffset + (document.documentElement.scrollTop) 
		}
		// If rel is not balnk then only show hover image
		if(this.rel != ""){
			$("body").append("<p id='screenshot'>"+this.rel+"</p>");								 
		}
		$("#screenshot")
			.css("top", (vp - $("#screenshot").height()/2) + "px")
			//.css("left",(yOffset - $("#screenshot").width()/2) + "px")
			.css("left", (e.pageX + 50) + "px")
			//.css("top",(e.pageY - xOffset) + "px")
			//.css("left",(e.pageX + yOffset) + "px")
			/*.css("top",(e.pageY - $("#screenshot").height()) + "px")
			.css("left",(e.pageX + xOffset) + "px")*/
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		//var vp = xOffset + document.documentElement.scrollTop
		var browserName = navigator.userAgent.toLowerCase();
		if (browserName.indexOf("safari") != -1) 
		{
			var vp = xOffset + (document.body.scrollTop) 		
		}
		else
		{
			var vp = xOffset + (document.documentElement.scrollTop) 
		}
		$("#screenshot")
			.css("top", (vp - $("#screenshot").height()/2) + "px")
			.css("left", (e.pageX + 50) + "px")
			//.css("left",(yOffset - $("#screenshot").width()/2) + "px")
			
			//.css("top",(e.pageY - xOffset) + "px")
			//.css("left",(e.pageX + yOffset) + "px");
	});			
};

this.tooltip = function(){	
	/* CONFIG */	
		valueX = 2;
		valueY = 20;
		/*xOffset = 10;
		yOffset = 20;*/		
		// 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){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - valueX) + "px")
			.css("left",(e.pageX + valueY) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - valueX) + "px")
			.css("left",(e.pageX + valueY) + "px");
	});			
};

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