function img(baseName)
{
    this.states = new Array();
    this.states["on"] = new Image(); this.states["on"].src = basePath + baseName + "_on.gif";
    this.states["off"] = new Image(); this.states["off"].src = basePath + baseName + "_off.gif";
}

// variable declaration
var basePath;    

/********************/
/*  Main Nav */
/*******************/
function changeNavImage()
{  
	if (document.images)
	{
		for (var i=0; i < changeNavImage.arguments.length; i+=2)
		{                
      		document[changeNavImage.arguments[i]].src = mainNavImgList[changeNavImage.arguments[i]].states[changeNavImage.arguments[i+1]].src;
		}  
	}
}

var mainNavImgList = new Array(); 

// base path for image rollover states
// set by external file
basePath = mainNavBasePath;

// mainNavImgNameList:  array of image names coming from external data file

// preloading images
for (var i = 0; i < mainNavImgNameList.length; i++)
{
    mainNavImgList[mainNavImgNameList[i]] = new img(mainNavImgNameList[i]);
}


// for javascript popup windows
function popupWindow(url, name, settings)
{
	return window.open(url, name, settings);
}

// for image transparency

var blendImageDivID;
var blendImageID;
var blendSpeed;
var blendNumSteps;

// change the opacity of the specified element
function changeOpacity(opacity, id)
{
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

// fade in the image from transparent to fully visible
function fadeImage()
{
	// set the timeouts for the number of steps it would take to do the full blend transition
	startOpacity = 0;
	endOpacity = 99;
	opacityStep = (endOpacity - startOpacity) / blendNumSteps;
	for(i = 0; i < blendNumSteps; i++) {  
        setTimeout("changeOpacity(" + (startOpacity + ((i+1) * opacityStep)) + ",'" + blendImageID + "')",(i * blendSpeed)); 
    }	

	// at the end, reset the image for the next blend transition
	setTimeout("resetImage()", (blendNumSteps+1) * blendSpeed);
}

// reset the image for the next blend transition
function resetImage()
{
	// set the current image as the background image in the div
    document.getElementById(blendImageDivID).style.backgroundImage = "url(" + document.getElementById(blendImageID).src + ")"; 
 
 	// make the top image transparent
    setTimeout("changeOpacity(0,'" + blendImageID + "')",50); 
}

// blend in the image
function blendImage(divID, imageID, newImage, transitionTime, numSteps) 
{ 	
	// if dynamic element creation is supported
	if (typeof document.createElementNS != 'undefined' || typeof document.createElement != 'undefined')
	{
	    // get the speed per frame in milliseconds, for a transition of the specified number of steps
		var speed = Math.round(transitionTime / numSteps); 
	
	 	// specify the div ID, image ID and blending speed values to the global variables
		blendImageDivID = divID;
		blendImageID = imageID;
		blendSpeed = speed;
	    blendNumSteps = numSteps;
		
		// set the fadeImage function to run once the image is loaded
		document.getElementById(imageID).onload = fadeImage;
	}
	
	// load the new image
	document.getElementById(imageID).src = newImage; 
} 

