

this.screenshotPreview = function() {
    /* CONFIG */

    xOffset = 30;
    yOffset = 10;

    /* END CONFIG */
    $("a.screenshot").hover(function(e) {
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";

        var x = (e.pageX + xOffset);
        var y = (e.pageY - yOffset);
        var height = $(window).height();
        var width = $(window).width();
        var previewHeight = 375;
        var previewWidth = 500;

        //Fix y
        //Original
        //        if (previewHeight + y > height) {
        //            y = height - previewHeight - 40;
        //        }

        if (previewHeight + y > height) {        
            y = height - previewHeight - 40;
        }

	
        //Fix x
        if (previewWidth + x > width) {
            x = width - previewWidth -(2 * xOffset);
        }
	
	if (y < 1)
	{
    	    y = 1;
	}

	if (x < 1)
	{
	    x = 1;
	}
	    
        $("body").append("<p id='screenshot'><img src='" + this.rel + "' />" + c + "</p>");
        $("#screenshot")
			.css("top", y + "px")
			.css("left", x + "px")
			.fadeIn("fast");
    },
	function() {
	    this.title = this.t;
	    $("#screenshot").remove();
	});
    $("a.screenshot").mousemove(function(e) {
        var x = (e.pageX + xOffset);
        var y = (e.pageY - yOffset);
        var height = $(window).height();
        var width = $(window).width();
        var previewHeight = 375;
        var previewWidth = 500;

        //Fix y
        //if (previewHeight + y > height) {
        //    y = height - previewHeight - 40;
        // }


        if (previewHeight + y > height) {
            y = height - previewHeight - 40;
        }
        
        //Fix x
        if (previewWidth + x > width) {
            x = width - previewWidth -(2 * xOffset);
        }

	if (y < 1)
	{
    	    y = 1;
	}

	if (x < 1)
	{
	    x = 1;
	}
	
        $("#screenshot")
			.css("top", y + "px")
			.css("left", y + "px");

    });
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});