/*
 * Replace the H1 element with a different font.
 */
function replaceH1Font()
{
    Cufon.replace('h1', { fontFamily: 'fut_maxi' });    
}

/*
 * Replace certain elements with a different font.
 */
function replaceFonts() {
    Cufon.replace('h2', { fontFamily: 'fut_maxi' });
    Cufon.replace('h3', { fontFamily: 'fut_maxi' });
    Cufon.replace('h4', { fontFamily: 'fut_maxi' });
    Cufon.replace('.vcard a.url', { fontFamily: 'fut_maxi' });
    Cufon.replace('a.refer', { fontFamily: 'fut_maxi' });
    Cufon.replace('#navigation li', { 
        fontFamily: 'fut_maxi',
        hover: true
    });
}

/*
 * Replace the font in strong.classified.
 */
function replaceClassifiedFont()
{
    Cufon.replace('strong.classified', { 
        fontFamily: 'classified',
        hover: true,
        hoverables: {strong: true}
    });
}

/*
 * Setup "accordian" style in-place toggles.
 */
function setupToggles() {
    $('.item li a.hide').click(function() {
        $(this).next().slideToggle();
        return false;
    }).next().hide();
}

/*
 * Continuously animate an element with a rotating color scheme.
 * 
 * Parameters: target: element to animate. Defaults to '.logo h1'
 */
function animateBackground(target) {
    var hue = 'rgb(' + (Math.floor(Math.random() * 255)) + ','
            + (Math.floor(Math.random() * 255)) + ','
            + (Math.floor(Math.random() * 255)) + ')';
    $(target).animate( { backgroundColor: hue }, 4000);
    $(target).animate( { backgroundColor: "#ff6418" }, 4000);
    
    // animate() returns immediately so wait 8 seconds for previous 2
    // animations, + 10 seconds before animating again
    setTimeout(function(){animateBackground(target)}, 18000);
}

/*
 * Setup continuous animation of an element with a rotating color scheme,
 * starting 10 seconds after being invoked.
 * 
 * Parameters: target: element to animate. Defaults to '.logo h1'
 */
function spectrum(target) {
    if (typeof(target) == "undefined") {
        target = '.logo h1';
    }
    setTimeout(function(){animateBackground(target)}, 10000);
}

/*
 * All pages that include this file get automatic startup behavior. This
 * includes font replacement and a rotating color scheme on the
 * "logo_to_animate" element, which defaults to '.logo h1'. This automatic
 * startup behavior can be disabled by setting the skip_cyberpoint_setup
 * variable to True. If the setupToggles variable is True, toggles will be
 * setup as well.
 */
if ((typeof(skip_cyberpoint_setup) == "undefined") || !skip_cyberpoint_setup) {
    replaceH1Font();
    replaceFonts();
    $(document).ready(function() {
        if ((typeof(toggles) != "undefined") && toggles) {
            setupToggles();
        }
        if (typeof(logo_to_animate) == "undefined") {
            spectrum();
        }
        else {
            spectrum(logo_to_animate);
        }
    });
}

