$(document).ready(function() {
    initaliseEvents();
});

function initaliseEvents()
{
    var i;
    $('.event-text').hide();
    $('.event-text:first').show();

    wkActiveStates($('#week li a img:first'));

    $('#week li a').click( function() {
        wkActiveStates($(this).find('img'));
        $('.event-text').hide();
        $day = $(this).attr('id');
        $('#' + $day + '-detail').show();
        return false;
    });
}

function wkActiveStates(activeDay)
{
    removeHoverStates();
    i = $(activeDay).attr('src');
    i = i.replace(/\.(\w+)$/, '_h.$1');
    $(activeDay).attr('src', i);
}

function removeHoverStates()
{
    $('#week li a img').each(function() {
        var i;
        i = $(this).attr('src');
        i = i.replace(/_h\.(\w+)$/, '.$1');
        $(this).attr('src', i);
    });
}