var help = function()
{
    var options = {
        idPrefix : 'service_help_',
        offsets  : {top:0, left: -23},
        delay    : 700
    };
    
    var currentEl = null;
    var currentHelp = null;
    var currentId = null;
    
    var hideTimer;
    
    var helpsE = [];
    
    function obtainHelpPosition(element)
    {
        var position = currentEl.position();

        var height = currentHelp.height();

        return {top  : Math.round(position.top + options.offsets.top - height),
                left : Math.round(position.left + options.offsets.left)};
    }
    
    function showCurrentHelp()
    {
        var position = obtainHelpPosition();
        
        showHelp(position);
    }
    
    function showHelp(position)
    {
        if ($.inArray(currentId, helpsE) == -1) {
            currentHelp.mouseout(onMouseOutHelp).mouseover(onMouseOverHelp);
            helpsE.push(currentId);
        }
        
        currentHelp.css({top: position.top + 'px', left: position.left + 'px'}).show();
    }
    
    function onMouseOverHelp()
    {
        stopTimer();        
    }
    
    function onMouseOutHelp()
    {
        startTimer();
    }
    
    function setupCurrents(id, element)
    {
        currentId = id;
        currentEl = $(element);
        currentHelp = $('#' + options.idPrefix + id);
        
        if (currentHelp.length == 0) {
            currentId = null;
            currentEl = null;
            currentHelp = null;
            
            return false;
        } else {
            return true;
        }
    }
    
    function startTimer()
    {
        hideTimer = setTimeout(function() {hideCurrent();}, options.delay);
    }
    
    function stopTimer()
    {        
        if (hideTimer) {
            clearTimeout(hideTimer);
        }
    }
    
    function hideCurrent()
    {
        if (null !== currentHelp) {
            currentHelp.hide();
        }
        
        currentId = null;
        currentEl = null;
        currentHelp = null;
    }
    
    return {
        show : function(id, element)
        {            
            stopTimer();
            if (null !== currentId && currentId != id) {
                hideCurrent();
            } else if (null !== currentId && currentId == id) {                
                return;
            }
            
            if (!setupCurrents(id, element)) {
                return false;
            }
            
            showCurrentHelp();
        },
        
        hide : function()
        {
            startTimer();
        },
        
        hideNow : function()
        {
            hideCurrent();
        }
    };
} ();
