/* NOTE: a variables script (separate configurable file) must be included before including this script,
or the variables must be set on the page in some fashion in order for these utilities to work correctly.

Variables are as follows (examples):
------
var global_imagePath = "includes/images/webgraphics/";
var global_imageIdPrefix = "menuImg_";
var global_rolloverOnSuffix = global_rolloverOnSuffix;
var global_rolloverOffSuffix = global_rolloverOffSuffix;
var global_rolloverOverSuffix = global_rolloverOverSuffix;
var global_activeItem = "";
var global_idArray = new Array( 'bio', 'mailingList', 'images', 'multimedia', 'news', 'myspace' );
var bln_useSeparateOnImage = false;	// set this to true|false depending if you want a separate 'content on' image from the rollover
var bln_debugMode = false;	// set for debugging
------

Values of each of these variables can be set accordingly.
*/


function newImage(arg) 
{
	if (document.images) 
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function setActive( activeItem )
{
    if( document.images && document.getElementById )
    {
        var ctr = 0;
        
        if( global_activeItem != "" )
        {  
            // clear out selected image
            for( ctr = 0; ctr < global_idArray.length; ctr++ )
            {
                menuRollOff( global_idArray[ctr] );
            }

        }
        
        for( ctr = 0; ctr < global_idArray.length; ctr++ )
        {
            var currImg = document.getElementById( global_imageIdPrefix + global_idArray[ctr] );
      
            if( activeItem.match( global_idArray[ctr] ))
            {
                currImg.src = global_imagePath + activeItem + ((bln_useSeparateOnImage) ? global_rolloverOnSuffix : global_rolloverOverSuffix );
                
                if( bln_debugMode )
                {
					alert( "Active Image Source: " + currImg.src );
                } 
            }
            else
            {
                currImg.src = global_imagePath + global_idArray[ctr] + global_rolloverOffSuffix; 
            }
        }
    }
    
    global_activeItem = activeItem;
}

function menuSetActive( menuID )
{
    if( global_activeItem.match( menuID ) == null )
    {
        changeImages( menuID, global_imagePath + menuID + (bln_useSeparateOnImage) ? global_rolloverOnSuffix : global_rolloverOverSuffix );
    }
    
}

function menuRollOver( menuID )
{
    if( global_activeItem.match( menuID ) == null )
    {
        changeImages( menuID, global_imagePath + menuID + global_rolloverOverSuffix );
    }
    
    document.body.style.cursor = "pointer";
}

function menuRollOff( menuID )
{
    if( global_activeItem.match( menuID ) == null )
    {
        changeImages( menuID, global_imagePath + menuID + global_rolloverOffSuffix );
    }
    
    document.body.style.cursor = "auto";
}

function changeImages() 
{
	if (document.images) 
	{
	    if( document.getElementById )
	    {
	        var imageID = global_imageIdPrefix + changeImages.arguments[0];
	        var objImage = document.getElementById( imageID );
	        objImage.src = changeImages.arguments[1];
	        
	        if( bln_debugMode )
	        {
				var strBuffer = "ImageID: " + imageID + "\n";
				strBuffer += "src: " + objImage.src;
				
				alert( strBuffer );
	        }
	    }
	}
	
	return true;
}

function preloadImages() 
{
	if (document.images) 
	{
	    var imgArray = new Array();
	    
	    for( ctr = 0; ctr < global_idArray.length; ctr++ )
	    {
	        var currMult = ((bln_useSeparateOnImage) ? 3 : 2 ) * ctr;
	        imgArray[currMult] = newImage( global_imagePath + global_idArray[ctr] + global_rolloverOffSuffix );
	        
	        if( bln_useSeparateOnImage )
	        {
				imgArray[currMult + 1] = newImage( global_imagePath + global_idArray[ctr] + global_rolloverOnSuffix );
				imgArray[currMult + 2] = newImage( global_imagePath + global_idArray[ctr] + global_rolloverOverSuffix );
	        }
	        else
	        {
				imgArray[currMult + 1] = newImage( global_imagePath + global_idArray[ctr] + global_rolloverOverSuffix );
	        }
	    }
	    
		// testing code
	    if( bln_debugMode )
	    {
			var strBuffer = "Preloaded Image Roster--\n\n";
		    
			for( ctrTest = 0; ctrTest < imgArray.length; ctrTest++ )
			{
				strBuffer += imgArray[ctrTest].src;
				
				if( ctrTest < (imgArray.length - 1 ))
				{
					strBuffer += "\n";
				}
			}
			
			alert( strBuffer );
	    }
	}
}
