﻿(function() {
    
    function hoverOverTab(event) {
        if(!$(event.target).hasClass('current')) {
            $(event.target).stop();
            $(event.target).animate({opacity: 1}, 300);
        }
    }
    function hoverOffTab(event) {
        if(!$(event.target).hasClass('current')) {
            $(event.target).stop();
            $(event.target).animate({opacity: 0}, 100);
        }
    }
    
    /* toggle the value of the search input */
    function toggleValue(event) {
        if($(this).attr('value') == $(this).data('theValue').value) {
            $(this).attr('value', '');
        } else if($(this).attr('value') == '') {
            $(this).attr('value', $(this).data('theValue').value);
        }
    }
    $(function() {
         /* Get a random background image between 0 and 14 */
        $('#nav').css({backgroundImage: 'url(http://saintpaulmncoc.weblinkconnect.com/cwt/external/wcpages/images/header-'+Math.floor(Math.random()*(15))+'.jpg)'});

         // Perform other setup items.
         if(!$.browser.msie || ($.browser.msie && parseInt($.browser.version, 10) >= 7)) {
            /* if not IE6, add "fading" tabs */
            $('#nav ul a').each(function() {
                if(!$(this).hasClass('current')) {
                    $(this).css({opacity: '0'});
                }
            });
            $('#nav ul a').bind('mouseover', hoverOverTab);
            $('#nav ul a').bind('mouseout', hoverOffTab);
        } else {
            /* if IE6, use the ifixpng jquery plugin on elements that need it */
            $('div#nav .cta, div#nav ul, div#nav ul a').ifixpng();
        }

        $('#ssSearch').data('theValue', { value: $('#ssSearch').attr('value') });
        $('#ssSearch').bind('focus', toggleValue);
        $('#ssSearch').bind('blur', toggleValue);
        
    });
    
    /* Configure sIFR */
    sIFR.useStyleCheck = true;
    sIFR.forceTextTransfor = true;
    var WhitneyBook = { src: 'http://saintpaulmncoc.weblinkconnect.com/cwt/external/wcpages/flash/Whitney_Book.swf' };
    sIFR.activate(WhitneyBook);
    sIFR.replace(WhitneyBook, { selector: 'div#main h1' });
    sIFR.replace(WhitneyBook, { selector: 'div#subnav li', css: [
        '.sIFR-root { text-transform: uppercase; }',
        'a { color: #88746A; text-decoration: none; font-size: 11px; }',
        'a:hover { color: #214159; }',
        '.current { color: #000000; }'
    ] })
    
})();