/* ********************************************
 * nav_code.js
 * created 03/01/01
 *
 * Rollover scripts for dynamic navigation
 * ******************************************** */

// initialize rollover naming convention, and common J&B images
imageExtension = ".gif";
imageDirectory = "../images/";
rolloverIdentifier = "_on";
normalIdentifier = "";
currentMenu = "";
currentMenuImage = "";
initImage( "nav1_solu" );
initImage( "nav1_sup" );
initImage( "nav1_news" );
initImage( "nav1_about" );
simpleInitImage( "nav1_1" );
simpleInitImage( "nav1_2" );
simpleInitImage( "nav1_3" );
simpleInitImage( "nav1_gre" );
simpleInitImage( "nav1_ora" );
simpleInitImage( "nav1_yel" );
simpleInitImage( "nav1_blu" );
initImage( "dot1" );
initImage( "dot2" );
initImage( "dot3" );
initImage( "dot4" );
initImage( "dot5" );
initImage( "dot6" );
initImage( "dot7" );
initImage( "dot8" );
initImage( "dot9" );
initImage( "dot11" );
initImage( "dot12" );
initImage( "dot13" );
initImage( "dot14" );
initImage( "dot15" );
initImage( "dot01" );
initImage( "dot02" );
initImage( "dot03" );
initImage( "dot04" );
initImage( "dot05" );
initImage( "dot06" );
initImage( "dot07" );
initImage( "dot08" );
initImage( "dot09" );
initImage( "dot11" );
initImage( "dot12" );
initImage( "dot13" );
initImage( "dot14" );
initImage( "dot15" );

// do capabilities checks
supportsAll = false;
supportsLayers = false;

// check for mac and ie.  needed for interactive textbook submenu
var agt=navigator.userAgent.toLowerCase();
var is_ie   = (agt.indexOf("msie") != -1);
var is_mac    = (agt.indexOf("mac")!=-1);

if ( document.all ) {
	supportsAll = true;
} else if ( document.layers ) {
	supportsLayers = true;
}

/* ********************************************
 * selectMenu
 * Aggregate the functions used to highlight a top level 
 * menu and display the submenu layer.
 * ******************************************** */
function Menu( menuName, imageName ) {
	
	deselectCurrentMenu();
	
	turnOn( imageName );
	showSubMenu( menuName, "subMenu" );
	
	currentMenu = menuName;
	if (imageName) { currentMenuImage = imageName }
}

/* ********************************************
 * simpleInitImage
 * create and preload a single image
 * ******************************************** */
function simpleInitImage( strImageName ) {

	eval( strImageName + " = new Image()" );
	eval( strImageName + ".src = '" + imageDirectory + strImageName + imageExtension + "'" );

}

/* ********************************************
 * initImage
 * create and preload the off and rollover
 * states for an image
 * on J&B from the same source
 * ******************************************** */
function initImage( strImageName ) {
	var re = /^(dot)\d\d?$/;
	if ( re.exec( strImageName )) {
		eval( strImageName + "_off = new Image()" );
		eval( strImageName + "_off.src = '" + imageDirectory + RegExp.$1 + normalIdentifier + imageExtension + "'" );
		eval( strImageName + "_roll = new Image()" );
		eval( strImageName + "_roll.src = '" + imageDirectory + RegExp.$1 + rolloverIdentifier + imageExtension + "'" );
	} else {
		eval( strImageName + "_off = new Image()" );
		eval( strImageName + "_off.src = '" + imageDirectory + strImageName + normalIdentifier + imageExtension + "'" );
		eval( strImageName + "_roll = new Image()" );
		eval( strImageName + "_roll.src = '" + imageDirectory + strImageName + rolloverIdentifier + imageExtension + "'" );
	}
}

/* ********************************************
 * swapImage
 * replace the src of one image object ( usually
 * from document.images ) with the source of 
 * another ( usually a preloaded object ). 
 * ******************************************** */
function swapImage( imageObj, newImageObject ) {
	if ( document.images ) {
		imageObj.src = newImageObject.src;
	}
}

/* ********************************************
 * turnOn
 * Set the image named image name to its
 * preloaded "on" or "rollover" state. Requires
 * the use of the naming convention described above.
 * anm 03.01.01
 * modified for J&B navigation
 * swap 'slivers' in nav1 only if neigboring images 
 * are not in 'on' state
 * ******************************************** */
function turnOn( strImageName, strLayername ){

	if ( ! strLayername ) {
		// do a simple swap using the document.images array
		swapImage( document.images[ strImageName ], eval( strImageName + "_roll" ) );
		// if this is solutions, nav1_1 = nav1_gre
		if ( strImageName.indexOf( "solu" ) > 0 ) {
			if ( document.images[ "nav1_1" ].src.indexOf( "_1" ) > 0 ) {
				swapImage( document.images[ "nav1_1" ], nav1_gre );
			}
		}
		// if this is support nav1_1 and nav1_2 = nav1_ora
		if ( strImageName.indexOf( "sup" ) > 0 ) {
			if ( document.images[ "nav1_1" ].src.indexOf( "_1" ) > 0 ) {
				swapImage( document.images[ "nav1_1" ], nav1_ora );
			}
			if ( document.images[ "nav1_2" ].src.indexOf( "_2" ) > 0 ) {
				swapImage( document.images[ "nav1_2" ], nav1_ora );
			}
		}
		// if this is news nav1_2 and nav1_3 = nav1_yel
		if ( strImageName.indexOf( "news" ) > 0 ) {
			if ( document.images[ "nav1_2" ].src.indexOf( "_2" ) > 0 ) {
				swapImage( document.images[ "nav1_2" ], nav1_yel );
			}
			if ( document.images[ "nav1_3" ].src.indexOf( "_3" ) > 0 ) {
				swapImage( document.images[ "nav1_3" ], nav1_yel );
			}
		}
		// if this is about nav1_3 = nav1_blu
		if ( strImageName.indexOf( "abo" ) > 0 ) {
			if ( document.images[ "nav1_3" ].src.indexOf( "_3" ) > 0 ) {
				swapImage( document.images[ "nav1_3" ], nav1_blu );
			}
		}
	} else {
		// swap an image in the strLayername
		if ( supportsAll ) {
			swapImage( document.all[ strLayername ].all[ strImageName ], eval( strImageName + "_roll" ) );
		} else if ( supportsLayers ) {
			swapImage( document.layers[ strLayername ].document.images[ strImageName ], eval( strImageName + "_roll" ) );
		}
	}
}

/* ********************************************
 * turnOn
 * Set the image named image name to its
 * "off" or "normal" state. Watch naming convention.
 * ******************************************** */
function turnOff( strImageName, strLayername ){

	if ( ! strLayername ) {
		// do a simple swap using the document.images array
		swapImage( document.images[ strImageName ], eval( strImageName + "_off" ) );
		// if this is solutions, nav1_1 = nav1_gre
		if ( strImageName.indexOf( "solu" ) > 0 ) {
			if ( document.images[ "nav1_1" ].src.indexOf( "gre" ) > 0 ) {
				swapImage( document.images[ "nav1_1" ], nav1_1 );
			}
		}
		// if this is support nav1_1 and nav1_2 = nav1_ora
		if ( strImageName.indexOf( "sup" ) > 0 ) {
			if ( document.images[ "nav1_1" ].src.indexOf( "ora" ) > 0 ) {
				swapImage( document.images[ "nav1_1" ], nav1_1 );
			}
			if ( document.images[ "nav1_2" ].src.indexOf( "ora" ) > 0 ) {
				swapImage( document.images[ "nav1_2" ], nav1_2 );
			}
		}
		// if this is news nav1_2 and nav1_3 = nav1_yel
		if ( strImageName.indexOf( "news" ) > 0 ) {
			if ( document.images[ "nav1_2" ].src.indexOf( "yel" ) > 0 ) {
				swapImage( document.images[ "nav1_2" ], nav1_2 );
			}
			if ( document.images[ "nav1_3" ].src.indexOf( "yel" ) > 0 ) {
				swapImage( document.images[ "nav1_3" ], nav1_3 );
			}
		}
		// if this is about nav1_3 = nav1_blu
		if ( strImageName.indexOf( "abo" ) > 0 ) {
			if ( document.images[ "nav1_3" ].src.indexOf( "blu" ) > 0 ) {
				swapImage( document.images[ "nav1_3" ], nav1_3 );
			}
		}
	} else {
		if ( supportsAll ) {
			swapImage( document.all[ strLayername ].all[ strImageName ], eval( strImageName + "_off" ) );
		} else if ( supportsLayers ) {
			swapImage( document.layers[ strLayername ].document.images[ strImageName ], eval( strImageName + "_off" ) );
		}
	}
}

/* ********************************************
 * selectMenu
 * Aggregate the functions used to highlight a top level 
 * menu and display the submenu layer.
 * anm 03.01.01 modified to make imageName optional, to retain 'on' states
 * for main J&B nav
 * ******************************************** */
function selectMenu( menuName, imageName ) {
	deselectCurrentMenu();
	
	if (imageName) { turnOn( imageName ) }
	showSubMenu( menuName, "subMenu" );
	
	currentMenu = menuName;
	if (imageName) { currentMenuImage = imageName }
}

/* ********************************************
 * deselectMenu
 * anm 03.01.01 modified to make imageName optional, to retain 'on' states
 * for main J&B nav
 * ******************************************** */
function deselectMenu( menuName, imageName ) {
	if (imageName) { turnOff( imageName ) }
	hideSubMenu( menuName, "subMenu" );
	
	currentMenu = "";
	if (imageName) { currentMenuImage = "" }
}

/* ********************************************
 * deselectCurrentMenu
 * call the deselectMenu with the current values
 * ******************************************** */
function deselectCurrentMenu() {
	
	if ( currentMenu ) {
		if ( supportsAll && document.all.subResMenu ) {
			hideSubMenu( 'subResMenu' );
		} else if ( supportsLayers && document.layers.subResMenu ) {
			hideSubMenu( 'subResMenu' );
		}
		if ( currentMenuImage ) { 
			deselectMenu( currentMenu, currentMenuImage )
		} else {
			deselectMenu( currentMenu )
		}
	}

}

/* ********************************************
 * deselectCurrentMenu
 * call the deselectMenu with the current values
 * ******************************************** */
function selectCurrentMenu() {
	
	if ( currentMenu ) {
		if (currentMenuImage) {
			selectMenu( currentMenu, currentMenuImage );
			} else {
			selectMenu( currentMenu );
		}
	}

}

/* ********************************************
 * showSubMenu
 * Show the submenu layer. 
 * ******************************************** */
function showSubMenu( strLayerName ) {
	if ( supportsAll ) {
		document.all[ strLayerName ].style.visibility = "visible";
	} else if ( supportsLayers ) {
		document.layers[ strLayerName ].visibility =  "visible";
	}
	
}

/* ********************************************
 * hideSubMenu
 * Hide the submenu layer.
 * ******************************************** */
function hideSubMenu( strLayerName ) {
	
	if ( supportsAll ) {		
		document.all[ strLayerName ].style.visibility = "hidden";
	} else if ( supportsLayers ) {
		document.layers[ strLayerName ].visibility = "hidden";
	}
	
}


