/*
 * Miscellaneous scripts used throughout the Team Texas site
 */

/* 
 *
 */ 
function captializeFirstChars(str) 
{
    return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);

    function cnvrt() {
        return arguments[0].toUpperCase();
    }
}


/*
 * Toggle an overlay on the primary map image
 */
function toggleOverlay( container, image, file )
{
    var overlay = document.getElementById(container);
    var overlayImage = document.getElementById(image);
    var overlayImageSrc = "primary_map_files/" + file + ".png";
    /* var overlayImageSrc = "primary_map_files/" + file + "_overlay.png"; */

    if ( overlay.style.display == 'block' ) {
        overlay.style.display = 'none';
    } else { 
        overlay.style.display = 'block';
    }

    /* MSIE 5.x/6.x must be treated specially in order to make them use the PNG alpha channel */
    if (overlayImage.runtimeStyle) {
        overlayImage.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + overlayImageSrc + "', sizingMethod='scale')"; 
    } else {
        overlayImage.src = overlayImageSrc;
    }

    return true;
}

/*
 * Display a submap (hide the primary map)
 */
function displaySubmap( file )
{
    new Effect.Fade( 'image-map-container' );

    var primary_controls = document.getElementById('primary-controls');
    primary_controls.style.display = 'none';

    setTimeout( function() { new Effect.Appear('secondary-controls'); }, 1000 );

    /* Change the map info title & instructions accordingly */
    var map_info_title = file;
    map_info_title = map_info_title.replace( /_/g, " " );
    map_info_title = captializeFirstChars(map_info_title);
    document.getElementById('map-info-title').innerHTML = map_info_title;
    document.getElementById('map-instructions').innerHTML = 'Click on the member name on the left to view contact information.';

    /* Make the mouse over info line go away */
    document.getElementById('mouse-over-info').innerHTML = '';

    var imageSubmapContainer = document.getElementById('image-submap-container');
    var submapImage = document.getElementById('submap-image');
    var submapImageSrc = "secondary_map_files/" + file + ".png";

    document.getElementById('map-navigation').src = "secondary_map_files/navigation/" + file + ".png";
    
    /* MSIE 5.x/6.x must be treated specially in order to make them use the PNG alpha channel */
    if (submapImage.runtimeStyle) {
        submapImage.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + submapImageSrc + "', sizingMethod='scale')"; 
    } else {
        submapImage.src = submapImageSrc;
    }

    setTimeout ( function() { new Effect.Appear('image-submap-container') }, 1500 );

    document.getElementById('submap-image').useMap = '#' + file;
}

/*
 * Hide the submap (show the primary map)
 */
function hideSubmap()
{
    /* Fade out the submap */
    new Effect.Fade( 'image-submap-container' );
    document.getElementById('image-submap-container').src = 'images/blank.gif';
    
    /* Make the primary mape appear */        
    setTimeout ( function() { new Effect.Appear('image-map-container') }, 2000 );

    /* Hide these submap controls */
    document.getElementById('secondary-controls').style.display = 'none';

    /* Show the primary controls */ 
    setTimeout ( function() { document.getElementById('primary-controls').style.display = 'block'; }, 1000 );

    /* Revert the map info title, instructions & mouse over line, navigation map to the default */
    document.getElementById('map-info-title').innerHTML = 'Overlays';
    document.getElementById('map-instructions').innerHTML = 'To find a Team Texas Member in your area of interest simply click on the region.';
    document.getElementById('mouse-over-info').innerHTML = 'Mouse over the regions for more information';
    document.getElementById('map-navigation').src = "images/nationalmap.gif";
}
