/**
 * Tooltip
 * 
 * @require     MooTools
 * 
 * @author      Steffen Maechtel <s.maechtel@netzbewegung.com>
 * @version     1.00 alpha
 */

Nb_Tooltip = new Class({
    
    initialize: function(message)
    {
        this.message = message;
        this.element = null;
    },
    setStyle: function(style, value)
    {
        this.element.setStyle(style, value);
    },
    setStyles: function(styles)
    {
        this.element.setStyles(styles);
    },
    generateAndShow: function(target, direction)
    {
        this.generate(target, direction);
        this.show();  
    },
    hideAndDestroy: function()
    {
        this.hide();
        this.destroy();  
    },
    create: function(target, direction)
    {
        direction = direction || 'bottom';
        target    = target   || $$('body')[0];
        
        var tooltip = new Element('div', {
            'class': 'tooltip',
            html: this.getHtml(this.message)
        });
 
        this.element = tooltip;
        
        target.grab(this.element, direction);
    },
    show: function()
    {
        this.element.setStyle('display', 'block');
    },
    hide: function()
    {
        this.element.setStyle('display', 'none');
    },
    destroy: function()
    {
        this.element.destroy();
    },
    getHtml: function(content)
    {
        return ['<div class="tooltip-body-wrapper">',
                    '<div class="tooltip-body-content">',
                        content,
                    '</div>',
                '</div>',
                '<div class="tooltip-north-west"></div>',
                '<div class="tooltip-north"></div>',
                '<div class="tooltip-north-east"></div>',
                '<div class="tooltip-east"></div>',
                '<div class="tooltip-south-east"></div>',
                '<div class="tooltip-south"></div>',
                '<div class="tooltip-south-west"></div>',
                '<div class="tooltip-west"></div>'].join("");

    }
    
});

