//<!--

/*
 * showEvent()
 * 
 * shows a calendar event on mouseover
 * 
 * @params aObj:    href element
 * 
 */

var currentTitle;

function showEvent(event)
{
    var aObj = $(Event.element(event));
    
    if (empty(aObj.title))
        return;

    if (!$('calendarPopup'))
    {
        var b               = document.getElementsByTagName('body')[0];
        var e               = document.createElement('DIV');
        e.id                = 'calendarPopup';
        e.style.display     = 'none';
        b.appendChild(e);
    }
    
    var e           = $('calendarPopup');
    var c           = $A(aObj.classNames());
    currentTitle    = aObj.title.replace('\n', '<br />');
    aObj.title      = ''; //keep the title from showing
    e.className     = ''; //clear all old classnames
    
    e.addClassName('calendarPopup');
    e.update(currentTitle);
    e.addClassName(c[1]);
    e.setStyle({
        top:        Event.pointerY(event) + 15 +'px',
        left:       Event.pointerX(event) + 15 +'px'
    });
    
    e.show();
    
    Event.observe(aObj, 'mousemove', positionPopup.bindAsEventListener(aObj));
    
    if ($('calendarHelp'))
        $('calendarHelp').update('Click for more information');
}


/*
 * hideEvent()
 * 
 * hides a calendar event on mouseover
 * 
 * 
 */
function hideEvent(event)
{
    var aObj = $(Event.element(event));
    
    if (!$('calendarPopup') || empty(aObj))
        return;
     
    aObj.title      = currentTitle.replace('<br />', '\n');
    currentTitle    = '';
    
    $('calendarPopup').update();
    $('calendarPopup').hide();
    
    if ($('calendarHelp'))
        $('calendarHelp').update('&nbsp;');
}

/*
 * positionPopup()
 * 
 * moves the calendar popup with the mouse
 * 
 * 
 */
function positionPopup(event)
{
    var aObj = $(Event.element(event));
    
    if ($('calendarPopup').visible())
    {
        $('calendarPopup').setStyle({
            top:    Event.pointerY(event) + 15 + 'px',
            left:   Event.pointerX(event) + 15 + 'px'
        });
    }
}

/*
 * initCalendar()
 * 
 * adds mouseover/out events to all hrefs in a calendar table
 * 
 * 
 */
function initCalendar(calId)
{
    if (!$(calId))
        return;
    
    var a   = $(calId).getElementsBySelector('a.calendarEvent');
    
    a.each(
        function(item)
        {
            Event.observe(item, 'mouseover', showEvent.bindAsEventListener(item));
            Event.observe(item, 'mouseout', hideEvent.bindAsEventListener(item));
        }
    );
    
}


function empty () 
{ 
    if (arguments[0] == null || typeof arguments[0] == "undefined" || arguments[0] == "undefined" || arguments[0] == "") 
        return true; 
    else 
    return false;
};

//-->