/**
 * @fileoverview  What follows are JavaScript functions unique to this Website.
 * @version 2008-12-13
 * @author  James Swanson
*/

/**
 *
 */
function buttonHoverToggle( e ) // --------------------------- buttonHoverToggle
{
    var buttonObj = Event.element( e );
    var buttonSrc = buttonObj.src;
    if (/~/.test( buttonSrc )) {
        buttonObj.src = buttonSrc.replace( /~/, '' );
    } else {
        buttonObj.src = buttonSrc.replace( /\.(gif|jpg|png)/, "~.$1" );
    }
}

/**
 * Initializes the user buttons across the top of the screen.  This function
 * requires the prototype.js library for calls to Event.observe().
 * @version 2008-12-13
 */
function initButtons() // ------------------------------------------ initButtons
{
    if ($('calendar-button')) {
        Event.observe( 'calendar-button'
                     , 'click'
                     , function() { document.location = 'calendar.html'; }
                     , false
                     );
    }
    if ($('history-button')) {
        Event.observe( 'history-button'
                     , 'click'
                     , function() { document.location = 'history.html'; }
                     , false
                     );
    }
    if ($('services-button')) {
        Event.observe( 'services-button'
                     , 'click'
                     , function() { document.location = 'services.html'; }
                     , false
                     );
    }
    if ($('offices-button')) {
        Event.observe( 'offices-button'
                     , 'click'
                     , function() { document.location = 'offices.html'; }
                     , false
                     );
    }
    if ($('officials-button')) {
        Event.observe( 'officials-button'
                     , 'click'
                     , function() { document.location = 'officials.html'; }
                     , false
                     );
    }
    if ($('meetings-button')) {
        Event.observe( 'meetings-button'
                     , 'click'
                     , function() { document.location = 'meetings.html'; }
                     , false
                     );
    }
    if ($('feedback-button')) {
        Event.observe( 'feedback-button'
                     , 'click'
                     , function() { document.location = 'feedback.html'; }
                     , false
                     );
    }
    if ($('links-button')) {
        Event.observe( 'links-button'
                     , 'click'
                     , function() { document.location = 'links.html'; }
                     , false
                     );
    }
    if ($('maps-button')) {
        Event.observe( 'maps-button'
                     , 'click'
                     , function() { document.location = 'maps.html'; }
                     , false
                     );
    }

}

/**
 * Brings a tab into focus.
 * @param     {Object} tabObj the tab object
 * @param     {Number} tabIndex the tab index to bring into focus
 * @version   2007-04-19
 */
function showTab( tabObj, tabIndex ) // -------------------------------- showTab
{
    if (tabObj && tabObj.tabPane) {
        tabObj.tabPane.setSelectedIndex( tabIndex );
    }
}

function setExternalLinks() // -------------------------------- setExternalLinks
{
    $$('a').findAll( function( n ) {
        return( n.readAttribute( 'rel' ) == '_blank' );
    } ).each( function( n ) {
        n.target = "_blank";
    } );
}
