/**
 * Dots Array
 *   Single dot represents single category. That's it.
 *
 * Copyright (c) 2009 - Urh Srecnik <urh@srecnik.info>
 *
 * Built on top of jQuery library
 *   http://jquery.com/
 * */

jQuery.fn.dots = function(o)
{
    return this.each(function() {        
        var me = jQuery(this); 

        // go trough every dot
        me.find("a.fgdot")
            
            // handle click event (show lightbox for selected gallery)
            // @todo
            /// .click(function() { 
                /// console.log("ALT: " + this.alt);
            /// })

            // handle event of mouse entering the dot
            // changes background and shows the tooltip ballon with gallery details
            .bind("mouseenter", function() {
                if (!this.href)
                    return;

                $(this).css('backgroundImage', 'url("/img/layout/circle-dot.jpg")');

                var loc = $("#" + this.id.replace("dot_", 'desc_loc_')).html();
                var title = $("#" + this.id.replace("dot_", 'desc_title_')).html();
                var desc = "<b>" + title + "</b><br/>" + loc;
                $("#fgballon").html(desc);
                $("#fgballon").css('display', 'block');
            })

            // handle event of mouse leaving the dot
            // changes background to the original and hides the tooltip
            .bind("mouseleave", function() {
                if (!this.href)
                    return;
                
                $(this).css('backgroundImage', 'url("/img/layout/circle.jpg")');
                $("#fgballon").css('display', 'none');
            })

            // handle mouse move event
            // moves the tooltip ballon to the mouse coordinates
            .mousemove(function(e) {
                $("#fgballon").css('top', e.pageY + 'px');
                $("#fgballon").css('left', (e.pageX + 10) + 'px');
            })
	
	    // init lightbox for each gallery
	    .each(function(idx) {
                if (!this.href)
                    return;

            var selector = '.' + this.id.replace('dot_', 'gallery_');
            $(selector).lightBox({fixedNavigation:true});
	    });
    });
};
