/*
 * 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
 *
 */
 
 var screenshotPreviewEnabled = true;
 
this.screenshotPreview = function(){	
	/* CONFIG */

        xOffset = 30;
		yOffset = -10;
		
		
		// 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){
	    if (!screenshotPreviewEnabled)
	        return;
	    	    
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/><br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 

        var nodes = this.parentNode.parentNode.parentNode.childNodes;
        var col = 0;
        
        for (var i = 0; i < nodes.length; i++)
        {
            if (nodes[i].id != null && nodes[i].id.indexOf("hidColNumber") >= 0)
            {
                col = parseInt(nodes[i].value);
                break;
            }
        }

        setScreenshotPosition(e, col);
        $("#screenshot").fadeIn("fast");				
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
	    var nodes = this.parentNode.parentNode.parentNode.childNodes;
        var col = 0;
        
        for (var i = 0; i < nodes.length; i++)
        {
            if (nodes[i].id != null && nodes[i].id.indexOf("hidColNumber") >= 0)
            {
                col = parseInt(nodes[i].value);
                break;
            }
        }
	    setScreenshotPosition(e, col);
	});			
	
	function setScreenshotPosition(e, col)
	{
	    var x = e.pageX + xOffset;
	    var y = e.pageY + yOffset;
	
	    //if (e.pageX > 736)
	    if (col > 3)
	        x -= (parseInt($("#screenshot").css("width")) + (2 * xOffset));
		
	    if (e.pageY > 510)
	        //center vertically if on last row
	        y -= 220;
	        
	    $("#screenshot")
			.css("top",y.toString() + "px")
			.css("left",x.toString() + "px");
	}
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});