﻿/*
* Image 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
*
*/

$.fn.imagePreview = function(settings) {

    settings = jQuery.extend({
        xOffset: 10,
        yOffset: 30
    }, settings);

    return this.each(function() {
    
        $(this).hover(function(e) {
            this.t = this.title;
            this.title = "";
            var c = (this.t != "") ? "<br/>" + this.t : "";
            $("body").append("<p id='imagepreview'><img src='" + $(this).attr("popup") + "' alt='Loading image...' />" + c + "</p>");
            $("#imagepreview")
	            .css("top", (e.pageY - settings.xOffset) + "px")
	            .css("left", (e.pageX + settings.yOffset) + "px")
	            .fadeIn("fast");
        },
        function() {
            this.title = this.t;
            $("#imagepreview").remove();
        });
        
        $(this).mousemove(function(e) {
            $("#imagepreview")
	            .css("top", (e.pageY - settings.xOffset) + "px")
	            .css("left", (e.pageX + settings.yOffset) + "px");
        });        
    });
};


