/// <reference path="~/scripts/jquery.js" />
(function($) {
this.imagePreview = function() {
    /* CONFIG */

    xPreviewOffset = 20;
    yPreviewOffset = -200;

    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result

    /* END CONFIG */
    $("a.preview").hover(function(e) {
        var p = this.rel;
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ?  this.t : "";
        //$("body").append("<p id='preview'><img src='"+ this.rel +"' />"+ c +"</p>");
        $("body").append("<p id='preview'><span id='previewholder' class='loading'>&nbsp;</span>" + c + "</p>");
        $("#preview")
			.css("top", (e.pageY - xPreviewOffset) + "px")
			.css("left", (e.pageX + yPreviewOffset) + "px")
			.fadeIn("fast");

        var img = new Image();

        $(img)
            .load(function() {
                $(this).hide();

                $('#preview #previewholder')
                    .empty()
                    .append(this).removeClass('loading');

                $(this).fadeIn();
            })
            .error(function() {
                $('#preview #previewholder')
                .empty().addClass('nopicture');
            })
            .attr('src', p);

    },
	function() {
	    this.title = this.t;
	    $("#preview").remove();
	});
    $("a.preview").mousemove(function(e) {
        $("#preview")
			.css("top", (e.pageY - xPreviewOffset) + "px")
			.css("left", (e.pageX + yPreviewOffset) + "px");
    });
};

})(jQuery);

(function($) {
// starting the script on page load
$(document).ready(function() {
    imagePreview();
});

})(jQuery);
