//Initialization logic for jquery tipsy tooltips.

(function($) {
    
    //Initialize on the body ready event (so it can be safely executed from head).
    $("body").ready(function() {
        
        //Get the window width (safer than document width).
        docWidth = $(window).width();
        $.each($("img.tooltip"), function() {
        
            /* Position the tooltip either left or right of the tooltip element, depending
               on how much space there is on the right side of the element.
               Note: Use offset rather than position, as the position function throws
               js-errors in firefox and webkit based browser.
            */
            if (docWidth - $(this).offset().left > 210) {
                $(this).tipsy({ gravity: 'w', offsetLeft: 3 });
            } else {
                $(this).tipsy({ gravity: 'e', offsetLeft: -3 });
            };
        });
    });
})(jQuery);
