/*
 * 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 = (0 + $("#popup_image_preview").height() );
		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.popup_image_preview").hover(function(e)
		{
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='popup_image_preview'><img src='" + this.rel + "' alt='' />"+ c +"</p>");								 		
		$("#popup_image_preview")
			
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			/*
			.css("left",(e.pageX - ($("#popup_image_preview").width()/2) - xOffset) + "px")
			.css("top",(e.pageY - $("#popup_image_preview").height() - yOffset) + "px")
			*/
			.fadeIn("fast");
			
    	},
		
	function()
		{
		this.title = this.t;	
		$("#popup_image_preview").remove();
    	});	
	$("a.popup_image_preview").mousemove(function(e)
		{
		var kompenzace = 0;		  
		if((e.pageX + yOffset + $("#popup_image_preview").width()) >= $("body").width()) {
		   kompenzace = $("#popup_image_preview").width() + (yOffset*2);
		}		
		
		$("#popup_image_preview")
		
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset - kompenzace) + "px");
			
			/*
			.css("left",(e.pageX - ($("#popup_image_preview").width()/2) - xOffset) + "px")
			.css("top",(e.pageY - $("#popup_image_preview").height() - yOffset) + "px");
			*/
		});			
	
	};
	

// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});