/* jQuery plugin for easy CSS tooltips
*
* Based on Tooltip scripts by Alen Grakalic (http://cssglobe.com)
* For more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
* Extended by Senko Rasic to call arbitrary function which builds tooltip HTML
*/

(function($) {
    function tooltip(el, fn, options) {
        el.hover(function(e) {
            this.anchor_title = this.title;
            this.title = '';

            $('body').append('<p id="' + options.tooltipID + '">' + fn(this) + '</p>');
            $('#' + options.tooltipID)
                .css("top", (e.pageY - options.xOffset) + "px")
                .css("left", (e.pageX + options.yOffset) + "px")
                .fadeIn("fast");
        }, function() {
            this.title = this.anchor_title;
            $('#' + options.tooltipID).remove();
        });

        el.mousemove(function(e) {
            $('#' + options.tooltipID)
                    .css("top", (e.pageY - options.xOffset) + "px")
                    .css("left", (e.pageX + options.yOffset) + "px");
        });
    }

    $.fn.tooltip = function(fn, options) {
        options = options || {};
        var defaults = {
            xOffset: 250,
            yOffset: 20,
            tooltipID: 'tooltip'
        };

        return this.each(function() {
            tooltip($(this), fn, $.extend(defaults, options));
        });
    }

})(jQuery);

var GB_ANIMATION = false;
$(document).ready(function() {
    $('a.preview').tooltip(function(el) {
        var c = (el.anchor_title != "") ? "<br/>" + el.anchor_title : "";
        return "<img src='" + $(el).children("img").attr("src").replace(/thumb/,'med') + "' alt='image preview' />" + c;
    }, { 'tooltipID': 'preview' });
    $("a.greybox").click(function() {
        var t = this.title || $(this).text() || this.href;
        GB_show(t, this.href, 470, 700);
        return false;
    });

});
