/**
 * sck tooltip
 * @author slawek
 * @email ms1570p@o2.pl
 */

(function($){
    $.fn.sckTip = function(options) {  
    
        var defaults = {
            attribute   : 'alt',
            top         : 25,
            left        : 10
        };  
        var options = $.extend(defaults, options);
        
        var prev_value;
        
        return this.each(function() {
        
            $(this).bind({
                mouseenter: function() {
                    
                    prev_value = $(this).attr(options.attribute);
                    
                    if ( ($('#sck-tip').length) == 0 )
                        $('body').append('<div id="sck-tip" style="font-size: 12px; -moz-box-shadow: 0px 0px 9px black; -moz-border-radius: 6px; padding: 5px 10px; border: 1px solid #808080; background-color: #f0f0f0; color: black; position: absolute; display: none"></div>');
                        
                    $('#sck-tip').html($(this).attr(options.attribute));
                    
                    if (options.attribute == 'alt')
                        $(this).attr(options.attribute, '');
                }, 
                
                mousemove: function(e) {
                    
                    if ($('#sck-tip').is(':hidden'))
                        $('#sck-tip').fadeIn('fast');
                        
                    var posX = e.pageX + options.left;
                    var posY = e.pageY + options.top;  
                    
                    $('#sck-tip').css({'top' : posY, 'left' : posX});                                              
                },
                
                mouseleave: function() {
                    
                    if ($('#sck-tip'))
                        $('#sck-tip').hide();
                        
                    $(this).attr(options.attribute, prev_value);
                }
                
            });
        });  

    };  
})(jQuery); 
