jQuery(document).ready(function($) {

    if ($.browser.msie) {
        if ($.browser.version <= 6) {
            try {
                document.execCommand("BackgroundImageCache", false, true);
            }
            catch(err){};
            
            if (window['DD_belatedPNG'] !== undefined){
                DD_belatedPNG.fix('img, #nav li.active a, #tape, #nav li ul, #nav li li, #sidebar h3');
            }
            
            $('#nav li').hover(
                function () {
                    if ($('> ul', this).length > 0) {
                        $(this).addClass("hover");
                        //$('select').hide();
                        $('select').css('visibility', 'hidden');
                    }
                },
                function () {
                    if ($('> ul', this).length > 0) {
                        $(this).removeClass("hover");
                        //$('select').show();
                        $('select').css('visibility', 'visible');
                    }
                }
            );
        }
    } 

    //run the slideshow
    if($('#slideshow, #int_slideshow').length){
        $('#slideshow, #int_slideshow').cycle({timeout: 5000});
    }

    //search box help text
    $('#header_site_search #search_text').toggleVal({populateFrom:'label'}); 

});

(function($){
    //set up the accordian like functionality
    $(function() {
        $('#program')
            .find('h3')
                .click(function() {
                    $this = $(this);
                    $div = $('+ div.day', this);
                    $div.slideToggle();
                    if ($this.hasClass('closed')) {
                        $this.removeClass('closed').addClass('open');
                    }
                    else {
                        $this.removeClass('open').addClass('closed');
                    }
                })
                .end()
            .find('div.day')
                .hide()
                .end()
            .find('h3')
                .addClass('closed')
        ;
        if ($.browser.msie && $.browser.version <= 6) {
            $('#program tr').hover(function() {
                $('td', this).addClass('hover');
            }, function() {
                $('td', this).removeClass('hover');
            });
        }
    });
    //preselect based on # val in URL, or current date, or first
    $(function() {
        var loc = String(document.location);
        if (Boolean(loc.match(/keywords=/))) {
            $('#program')
                .find('h3')
                    .removeClass('closed')
                    .addClass('open')
                    .end()
                .find('div.day')
                    .show()
                .end()
            ;
        }
        else {
            var anchor = loc.replace(/^[^#]+#/g, '');
            var now = new Date();
            now = String(now.getFullYear())+now.getMonth()+now.getDate();
            if (!anchor || $('#'+anchor).length==0) {
                if ($('#'+now).length>0) {
                    anchor = now;
                }
                else {
                    anchor = $('#program h3:first').attr('id');
                }
            }
            $('#'+anchor)
                .addClass('open')
                .removeClass('closed')
                .find('+ div.day').show()
            ;
        }
    });
})(jQuery);
