/* 

HORIZONTAL DROP DOWN MENUS

Written by Don Charlton
Wall-to-Wall Studios
May 30 2006


BROWSER					VERSIONS			NOTES
-------					--------			-----
Mac IE					--					No longer supporting browser
Mac Firefox				1.04
Mac Netscape			7.2
Mac Safari				2.03
PC IE					7.0					One extra pixel above nav divs
PC Netscape				7.2
PC Firefox				1.04


*/



/* ------------------------------------------------------------------------------------
TEMPORARY ARRAY THAT REPRESENTS NAVIGATION
------------------------------------------------------------------------------------ */
// Array with section names
/*var vSectionArray = new Array ( "Home", "About PTEI", "Regenerative Medicine", "Industry", "Sponsored Research", "Education", "News & Events" );
var vNumberOfSections = vSectionArray.length - 1;*/


/* ------------------------------------------------------------------------------------
GENERATES HOME PAGE TABLE FOR PRIMARY NAVIGATION AND DROP DOWN MENUS
------------------------------------------------------------------------------------ */
// Set the size of the gap between each section in the main nav.
var vSpaceBetween = 1;
// Set the total width of the navigation
var vNavWidth = 768;

function fGenerateMainNavHome() {
		// Write the navigation table
		document.write( '<table id="navTable" width="' + vNavWidth + '" cellpadding="0" cellspacing="0" border="0"><tr>' );
		// If it's the home, plan to include the home link, else no by setting the starting point in the array.
		if ( !vHome ){
			vStartNum = 0;
		}else{
			vStartNum = 1;
		}
		

		// Loop through the sections and print to the page
		for ( i=vStartNum; i<vSectionArray.length; i++ ) {
		
			// Create the table data cell, and if this is the home page...
			if ( vHome ){
				// ... set the table math accounting for home link
				// document.write( '<td id="cell' + i + '" valign="top" align="left" width="' + Math.round( (vNavWidth - ((vSectionArray.length - 1) * vSpaceBetween )) / vSectionArray.length ) + '">' );
				document.write( '<td id="cell' + i + '" valign="top" align="left">' );
			} else {
				// ...else set the table math not accounting for home link.
				// document.write( '<td id="cell' + i + '" valign="top" align="left" width="' + Math.round( (vNavWidth - ((vSectionArray.length - 2) * vSpaceBetween )) / ( vSectionArray.length - 1) ) + '">' );
				document.write( '<td id="cell' + i + '" valign="top" align="left">' );
			}
			// Create the main nav <div> wrapped in a link (turn on if this is the current section)
			if ( i == 0 ){
				document.write( '<a class="menulink" href="index.php"><div onMouseOut="fPrimaryRollOver(\'out\',' + i + ');" onMouseOver="fPrimaryRollOver(\'over\',' + i + ');" class="menuDiv" id="nav' + i + '">'  + vSectionArray[i][0] + '</div></a>' );
			} else if ( i != vCurrSection ){
				document.write( '<a class="menulink" href="'+vSectionArray[i][3]+'?pageID='+vSectionArray[i][1]+'"><div onMouseOut="fPrimaryRollOver(\'out\',' + i + ');" onMouseOver="fPrimaryRollOver(\'over\',' + i + ');" class="menuDiv" id="nav' + i + '">'  + vSectionArray[i][0] + '</div></a>' );
			} else {
				document.write( '<a class="menulink" href="'+vSectionArray[i][3]+'?pageID='+vSectionArray[i][1]+'"><div onMouseOut="fPrimaryRollOver(\'out\',' + i + ');" onMouseOver="fPrimaryRollOver(\'over\',' + i + ');" class="menuDivCurrent" id="nav' + i + '">'  + vSectionArray[i][0] + '</div></a>' );
			}
			// Create the drop down menu if this is not the home page
			document.write( '<div onMouseOut="fPrimaryRollOver(\'out\',' + i + ');" onMouseOver="fPrimaryRollOver(\'over\',' + i + ');" id="menu' + i + '"' );
			if ( i != 0 && vSubSectionArray[i].length ){
					document.write(' class="dropmenu">')
					// Insert drop down contents
					document.write( '<ul>' );
					for(y=0;y<=vSubSectionArray[i].length-1;y++) {
						document.write( 	'<li><a href="'+vSubSectionArray[i][y][4]+'?pageID='+vSubSectionArray[i][y][1]+'"><b>'+vSubSectionArray[i][y][0]+'</b></a></li>' );
					}
					document.write( '</ul>' );
					
					var vMenuToEvaluate = document.getElementById( "menu" + i );
					vMenuToEvaluate.style.position = "absolute";
			} else {
				document.write('>');
			}
			
			document.write( '</div>' );
			// Close the table cell
			document.write( '</td>' );
			// Add divider IF it has been set and this is not the last loop through the array
			if ( vSpaceBetween > 0 && i != ( vSectionArray.length - 1 ) ){
				document.write( '<td id="spacerTDs" width="' + vSpaceBetween + '"><img src="img/spacer.gif" height="1" width="' + vSpaceBetween + '"></td>' );
			}
		}
		// Close table
		document.write( '</tr></table>' );
		
		// Fix style sheet discrepncies
		if (document.all){
			document.write('<style type="text/css">');
			document.write('div.pulled hr, hr {  margin: 0px;  }');
			document.write('</style>');
		}
		
}


/* ------------------------------------------------------------------------------------
ROLLOVER FUNCTIONS FOR MAIN NAVIGATION
------------------------------------------------------------------------------------ */
function fPrimaryRollOver(pStatus, pDivToAffect) {
		// If this is the home, only change colors on rollovers.
		if ( pDivToAffect == 0 ){
			if ( pStatus == "over" ){
				fRollOverStyles(pDivToAffect);
			} else {
				fRollOutStyles(pDivToAffect);
			}
		} else {
			// Store the current div in a variable
			var vMenuToEvaluate = document.getElementById( "menu" + pDivToAffect );
			// If this is hidden and this is not home, show menu and change styles.
			if ( vMenuToEvaluate.style.visibility == "visible" ) {
				fRollOutStyles(pDivToAffect);
				vMenuToEvaluate.style.visibility = "hidden";
			} else {
			// If this is visible and this is not home, hide menu and change styles.
				fRollOverStyles(pDivToAffect);
				vMenuToEvaluate.style.visibility = "visible";
			}
		}
		
}


/* ------------------------------------------------------------------------------------
CHANGES STYLES ON ROLLOVER OF MAIN NAV
------------------------------------------------------------------------------------ */
function fRollOverStyles( pDivToChangeStyles ) {
		// Get the nav section
		var vCellToEvaluate = document.getElementById( "nav" + pDivToChangeStyles );
		// Manipulate styles as needed
		vCellToEvaluate.style.backgroundColor = "#000000";
		vCellToEvaluate.style.color = "#FFCC00";
		fShowHideSelectObjects('hidden');
}


/* ------------------------------------------------------------------------------------
CHANGES STYLES ON ROLLOUT OF MAIN NAV
------------------------------------------------------------------------------------ */
function fRollOutStyles( pDivToChangeStyles ) {
		// Get the nav section
		var vCellToEvaluate = document.getElementById( "nav" + pDivToChangeStyles );
		// Manipulate styles as needed
		if( pDivToChangeStyles == vCurrSection ){
			vCellToEvaluate.style.backgroundColor = "000000";
			vCellToEvaluate.style.color = "#FFFFFF";
		} else {
			vCellToEvaluate.style.background = "none";
			vCellToEvaluate.style.color = "#FFFFFF";
		}
		fShowHideSelectObjects('visible');
}


/* ------------------------------------------------------------------------------------
HIDES AND SHOWS DROP DOWNS ON CALENDAR PAGE
------------------------------------------------------------------------------------ */
function fShowHideSelectObjects( pShowHide ){
		if (document.all) {
			if ( window.document.getElementById('category_selector') ){
				vSelect = window.document.getElementById('category_selector');
				vSelect.style.visibility = pShowHide;
			}
			if ( window.document.getElementById('months') ){
				vSelect = window.document.getElementById('months');
				vSelect.style.visibility = pShowHide;
			}
			if ( window.document.getElementById('cats') ){
				vSelect = window.document.getElementById('cats');
				vSelect.style.visibility = pShowHide;
			}
		}
}