$(document).ready(function(){
    //preloads
    var preloads = [
    '/img/subNavBgBot.png',
    '/img/subNavBgMid.png'
    ];
    for(i=0;i<preloads.length;i++)
    {
        var img = new Image();
        img.src = preloads[i];
    }

    //nav controls
    var subNavHeaderHtml = '<div class="subNavHeader"><table cellpadding="0" cellspacing="0" width="100%"><tr><td width="2"><img src="/img/subNavHeaderLeft.jpg" /></td><td class="headerTextCell"></td><td width="2"><img src="/img/subNavHeaderRight.jpg" /></td></tr></table></div>';
    $('#navUl').children('li:last').addClass('noSeparator');
    $('#navUl').children('li').hover(
        function(){
            var title = $(this).children('a').attr('title');
            if($(this).children('.subNav').length)
            {
                if(!$(this).children('.subNavHeader').length)
                {
                    $(this).children('a').after(subNavHeaderHtml)
                    $(this).children('.subNavHeader').find('.headerTextCell').html($(this).children('a').clone());
                    $(this).children('.subNav').show()
                }
            }
            else
            {
                if($(this).attr('id') == 'navRate')
                    $(this).addClass('hoverRate');
                else if($(this).attr('id') == 'navAbout')
                    $(this).addClass('hoverAbout');
                else
                    $(this).addClass('hover');
                $(this).children('.subNavHeader').remove();
                $(this).children('.subNav').hide();
            }
        },
        function(){
            $(this).removeClass('hover');
            $(this).removeClass('hoverRate');
            $(this).removeClass('hoverAbout');
            $(this).children('.subNavHeader').remove();
            $(this).children('.subNav').hide();
        }
        );

    //widget control
    $('.widgetTitle').click(function(){
        if($(this).hasClass('widgetOpen'))
        {
            $(this).removeClass('widgetOpen').addClass('widgetClosed');
            $(this).next('.widgetContent').slideUp();
        }
        else
        {
            $(this).removeClass('widgetClosed').addClass('widgetOpen');
            $(this).next('.widgetContent').slideDown();
        }
    });

    //footer fixes
    $('#footerNav ul li:first').css({
        'padding-left':0
    });
    $('#footerNav ul li:last').css({
        border:'none'
    });
});