/*!
 * jQuery-превью
 * Позволяет:
 * 1) показывать превью для ссылки в виде изображения
 */
jQuery.fn.imagePreview = function(){

        xOffset = 10;
        yOffset = 30;

        $(this).each(function(){

             if($(this).attr('haveImagePreview') == "true")
                return;

             $(this).hover(function(e){
                    this.t = this.title;
                    this.title = "";

                    var c = (this.t != "") ? "<br/>" + this.t : "";

                    var dy = yOffset;
                    var dx = xOffset;
                    if($(this).attr("yOffset") != null && $(this).attr("yOffset") != "")
                       dy = parseInt($(this).attr("yOffset"));
                    if($(this).attr("xOffset") != null && $(this).attr("xOffset") != "")
                       dx = parseInt($(this).attr("xOffset"));

                    $("body").append("<p id='preview'><img src='"+ $(this).attr("img") +"' alt='Image preview' />"+ c +"</p>");
                    $("#preview")
                            .css("top",(e.pageY + dy) + "px")
                            .css("left",(e.pageX + dx) + "px");
                    if($.browser.msie)
                        $("#preview").show();
                    else
                        $("#preview").fadeIn("fast");
                    },
                    function(){
                            this.title = this.t;
                            $("#preview").remove();
                    });

            $(this).mousemove(function(e){
                    var dy = yOffset;
                    var dx = xOffset;

                    if($(this).attr("yOffset") != null && $(this).attr("yOffset") != "")
                       dy = parseInt($(this).attr("yOffset"));
                    if($(this).attr("xOffset") != null && $(this).attr("xOffset") != "")
                       dx = parseInt($(this).attr("xOffset"));

                    var top = parseInt(e.pageY) + dy;
                    var left = parseInt(e.pageX) + dx;

                    $("#preview")
                    .css("top",(top) + "px")
                    .css("left",(left) + "px");
            });

            $(this).attr('haveImagePreview','true');

        });

	
};
