var browserApp;
var browserOS;
var browserVersion;

var NSInitialized = false;


/* DEVMODE : make sure this is changed back when we migrate to production */
var DEVMODE = false;
var dev_dir = DEVMODE ? "../" : "";




function initializePage()
{
	// check browser and platform
	browserString = navigator.userAgent.toLowerCase();
	
	browserString.match(/\(.+\s+(\w+)\s+(\d+\.\d+);\s*(.+)\)/);
	browserOS = RegExp.$3;
	browserVersion = RegExp.$2;
	browserApp = RegExp.$1;
	
	// This site won't work in IE 5.0 Mac due to some bugs that are fixed in 5.1.
	// Show Mac IE 5.0 users an alert begging them to upgrade.
	if ( /mac/i.test(browserOS) && browserApp == "msie" && browserVersion == "5.0" )
	{
		showAlert ("macie");	
	}
	
	initializePrefs();
	populateSidebar();
//	initializeExpanding();
	initializePulldowns();
}


function unloadTasks()
{
	// save Portfolio Explorer state if user has the preference option turned on
	if (menuSelectObj.prefSaveExpOn)
	{
		var myExpandingString = "";
		for (i in expandingObject) {
			if (expandingObject[i]) {
				if (myExpandingString != "") { myExpandingString += "|"; }
				myExpandingString += i; }
			}
		setCookie("D3_portfolio_explorer_state", myExpandingString, 30);
	}
}


// ----------------------- PULL-DOWN MENU SUBROUTINES ------------------------------------------------------------------

var menuSelectObj = new Object(); // contains all the menu items that can be selected or "checked off" (eg: preferences menu items)

//var flashObject = new Object();


function initializePulldowns()
{
	var menuDiv = document.getElementById("menuDiv");
	var menuHTML = '<DIV ID="menu_0"><TABLE ID="t_menu_header" border=0 cellpadding=' + menuPadding + ' cellspacing=1 height="' + menuHeight + '" width="100%"><TR>';
	
	for (i in menuAry)
	{
		var menuTitle = menuAry[i][0];
		menuHTML += '<TD ID="c_menu_0_' + i + '" class="menu_cell" align="left" width="' + menuWidth + '" bgcolor=#' + menuColour + ' onMouseOver="javascript:showMenu(\'menu_0_' + i + '\');" onMouseOut="javascript:hideMenu(\'menu_0_' + i + '\');"><TABLE border=0 cellspacing=0 cellpadding=0 width="100%"><TR><TD class="menu_cell">&nbsp;' + menuTitle + '</TD></TR></TABLE></TD>';
	}
	
	menuHTML += '<td bgcolor=#' + menuColour + '><img src="images/spacer.gif" width="1px" height="1px"></td>';
	menuHTML += '</TR></TABLE></DIV>';
	menuDiv.innerHTML = menuHTML;
	
	for (i in menuAry)
	{
		var thisTable = document.getElementById("t_menu_header");

		createMenu(menuAry[i], "menu_0", i, i * cellWidth, menuHeight);
	}
}

function createMenu(whichMenu, menuParent, menuIndex, offsetX, offsetY)
{
	var menuDiv = document.getElementById("menuDiv");
	var menuName = menuParent + "_" + menuIndex;
	
	var menuHTML = '<DIV ID="' + menuName + '" ><TABLE ID="t_' + menuName + '" border=0 cellpadding=' + menuPadding + ' cellspacing=1 height="' + menuHeight + 'px">';
	
	var subMenu = whichMenu[1];
	for (i in subMenu)
	{
		var menuItem = subMenu[i][0];
		var itemName = menuName + "_" + i;
		menuHTML += '<TR><TD ID="c_' + itemName + '" class="submenu_cell" align="left" bgcolor=#' + submenuColour + ' width="' + menuWidth + 'px" height="' + menuHeight + 'px"';
		if (typeof subMenu[i][1] == "object")
		{
			menuHTML += ' onMouseOver="showMenu(\'' + itemName + '\');" onMouseOut="hideMenu(\'' + itemName + '\');"';
		}
		else
		{
			menuHTML += ' onMouseOver="showMenu(\'' + itemName + '\');" onMouseOut="hideMenu(\'' + itemName + '\');" onMouseUp="clearMenu(\'' + itemName + '\'); ' + subMenu[i][1] + ';"';
		}
		
		var cellHeight = menuHeight - menuPadding;
		menuHTML += ' valign="center"><TABLE border=0 cellspacing=0 cellpadding=0 width="100%"><TR><TD align="left" class="submenu_cell" valign="center" height="' + cellHeight + 'px">&nbsp;';
		
		if (subMenu[i][2]) // this item is selectable / activatable
		{
			if (menuSelectObj[subMenu[i][2]]) // the item is selected / activated
			{
				menuHTML += '<img src="images/menu_item_active.gif">';
			}
			else
			{
				menuHTML += '<img src="images/spacer.gif" width="15px">';
			}
		}
		
		menuHTML += menuItem + '</TD><TD align="right" class="submenu_cell">';
		
		if (typeof subMenu[i][1] == "object") // it has a submenu
		{
			menuHTML += '<IMG src="images/submenu_arrow.gif" border="0">';
			createMenu(subMenu[i], menuName, i, offsetX + cellWidth, offsetY + i * (menuHeight + 3));
		}
		else // it's an actionable menu item
		{
			menuHTML += '<img src="images/spacer.gif" width="12" border="0" alt="spacer" />'; // firefox needs this - don't know why...
			//flashObject[itemName] = 0;
		}
		menuHTML += '</TD></TR></TABLE></TD></TR>';
	}
	menuHTML += '<TR><TD><IMG src="images/spacer.gif" width="' + menuWidth + '" height="1"></TD></TR>';
	menuHTML += '</TABLE></DIV>';
	menuDiv.innerHTML += menuHTML;
	
	var subMenuDiv = document.getElementById(menuName);
	subMenuDiv.style.visibility = "hidden";
	subMenuDiv.style.position = "absolute";
	subMenuDiv.style.left = offsetX;
	subMenuDiv.style.top = offsetY;
}

var prevMenu;
var prevCell;
var menuTimer;

function menuOn(menuName)
{
	if (prevMenu && prevMenu != null)
	{
		clearTimeout(menuTimer);
	}
	
	thisCell = document.getElementById("c_" + menuName);
	thisCell.style.backgroundColor = "#404040";
	
	thisCell.getElementsByTagName("TABLE")[0].getElementsByTagName("TR")[0].getElementsByTagName("TD")[0].style.color = "#F0F0F0";
	
	if (prevCell && prevCell != null && prevCell != thisCell)
	{
		resetCellHighlight(prevCell);
	}

	prevCell = thisCell;
}

function menuOff(menuName)
{
	//hideMenu(menuName);
}

function resetCellHighlight(prevCell)
{
	if (prevCell.id.split("_").length > 4)
	{
		prevCell.style.backgroundColor = submenuColour;
	}
	else
	{
		prevCell.style.backgroundColor = menuColour;
	}
	prevCell.getElementsByTagName("TABLE")[0].getElementsByTagName("TR")[0].getElementsByTagName("TD")[0].style.color = "#000000";
}

function showMenu(menuName)
{
	if (prevMenu && prevMenu != null)
	{
		var prevNameAry = prevMenu.split("_");
		var nameAry = menuName.split("_");
		
		for (i = nameAry.length; i <= prevNameAry.length; i++)
		{
			var prevName = prevNameAry.slice(0,i).join("_");
			document.getElementById(prevName).style.visibility = "hidden";
		}
	}
	var subMenuDiv = document.getElementById(menuName);
	if (subMenuDiv && subMenuDiv != null)
	{
		subMenuDiv.style.visibility = "visible";
		prevMenu = menuName;
	}
	
	menuOn(menuName);
}

function hideMenu(menuName)
{
	menuTimer = setTimeout('clearMenu("' + menuName + '")', resetSensitivity);
}

/*function flashMenu(menuName)
{
	if (flashObject[menuName] > 5) { flashObject[menuName] = 0; clearMenu(menuName) }
	else 
	{
		var hilightColour = flashObject[menuName]/2 == Math.round(flashObject[menuName]/2) ? "#202020" : submenuColour;
		
		thisCell = document.getElementById("c_" + menuName);
		thisCell.style.backgroundColor = hilightColour;
		
		flashObject[menuName]++;
		setTimeout ("flashMenu('" + menuName + "');", 100);
	}
}*/

function clearMenu(menuName)
{
	if (prevCell.id == "c_" + menuName)
	{
		var prevNameAry = prevMenu.split("_");
		for (i = 3; i <= prevNameAry.length; i++)
		{
			var prevName = prevNameAry.slice(0,i).join("_");
			document.getElementById(prevName).style.visibility = "hidden";
		}
	}
	resetCellHighlight(prevCell);
}

// -------------------------- PREFERENCES ---------------------------------------------------------

function initializePrefs()
{
	var i = 0;
	var j = 0;
	while  (j > -1 && i > -1)
	{
		i = document.cookie.indexOf("pref_", j);
		if (i > -1)
		{
			j = document.cookie.indexOf(";", i);
			
			var thisCookie
			if (j == -1) { thisCookie = document.cookie.slice(i); }
			else { thisCookie = document.cookie.slice(i,j); }
			
			myCookieAry = thisCookie.split("=");
			myCookieAry[0] = myCookieAry[0].slice(myCookieAry[0].indexOf("_") + 1);
			
			doPref (myCookieAry[0], myCookieAry[1]);
		}
	}
}

function setPref(whichPref, whatValue)
{
	doPref (whichPref, whatValue);
	
	checkCookies();	
	var cookieName = "pref_" + whichPref;
	setCookie (cookieName, whatValue, 365);
	
	if (whichPref == "saveExplorer" && whatValue == "false") { document.cookie = "D3_portfolio_explorer_state="; }// clear the explorer_state cookie 
	
		
	document.getElementById("menuDiv").innerHTML = ""; prevCell = null; prevMenu = null;
	initializePulldowns();
}

function doPref(whichPref, whatValue)
{
	if (whichPref == "saveExplorer")
	{
		menuSelectObj.prefSaveExpOff = whatValue == 'true' ? null : true;
		menuSelectObj.prefSaveExpOn = whatValue == 'true' ? true : null;
	}
}



// ------------------------- EXPANDING TEXT HIERARCHICAL MENUS SUBROUTINES ----------------------------------------------------

var expandingObject = new Object();

function initializeExpanding()
{
	// First, check to see whether the user has a saved image of the portfolio explorer's state in a cookie
	if (getCookie("D3_portfolio_explorer_state"))
	{
		var expandingObjAry = getCookie("D3_portfolio_explorer_state").split("|");
		for (i in expandingObjAry) // would like to just clobber expandingObject using expandingObject = split..., but I don't think it will work that way
		{
			expandingObject[expandingObjAry[i]] = true;
		}
	}

	
	var contentArea = document.getElementById("expandingContentArea");
	var myContent = createExpanding(0, expandingAry);		
	contentArea.innerHTML = myContent;
}

function createExpanding(whichLevel, whichAry, whichItem)
{
	var theContent = "";
	if (whichLevel == 0)
	{
		theContent = '<TABLE border="0" cellspacing="0" cellpadding="0"><tr><td colspan="3" class="treeCell" align="left"><a href="javascript:showHelp(\'help_explorer\');"><img src="images/spacer.gif" height="35px" width="200px" border="0"></a></td></tr>';
	}
	else
	{
		theContent = '<tr><td></td><td></td><td><table border="0" cellspacing="0" cellpadding="0">';
	}
	
	for (i in whichAry)
	{
		var levelMenu = whichAry[i];
		if (whichItem && levelMenu[2] && inMenu(whichItem, levelMenu) ) { expandingObject[levelMenu[0]] = true; }
		var arrowDirection = expandingObject[levelMenu[0]] ? "down" : "up";
		
		if (whichLevel == 0)
		{
			theContent += '<TR>';
			theContent += '<TD width="32px" align="left" class="treeCell" onMouseUp="expandText(\'' + levelMenu[0] + '\');"><IMG src="images/icon_' + levelMenu[0] + '_small.gif"></TD>';
			theContent += '<TD width="15px" align="left" class="treeCell" onMouseUp="expandText(\'' + levelMenu[0] + '\');"><IMG src="images/text_expand_arrow_' + arrowDirection + '.gif"></TD>';
			theContent += '<TD id="item_' + levelMenu[0] + '" class="treeHeader" onMouseUp="expandText(\'' + levelMenu[0] + '\');" width="135px">' + levelMenu[1] + '</TD>';
			theContent += '</TR>';
		}
		else
		{
			if (levelMenu[2]) // this Item has a submenu
			{
				theContent += '<TR><TD height="18"><IMG src="images/spacer.gif" width="5px"></TD><TD width="15px" align="left" class="treeCell" onMouseUp="expandText(\'' + levelMenu[0] + '\');"><IMG src="images/text_expand_arrow_' + arrowDirection + '.gif"></TD><TD id="item_' + levelMenu[0] +'" class="treeSubhead" onMouseUp="expandText(\'' + levelMenu[0] + '\');">' + levelMenu[1] + '</TD></TR>';
			}
			else // no submenu for this Item
			{
				theContent += '<TR><TD colspan="2" height="18"><IMG src="images/spacer.gif" width="5px"></TD><TD nowrap="nowrap" class="treeContent" onMouseUp="showContent(\'' + levelMenu[0] + '\');">' + levelMenu[1] + '</TD></TR>';
			}
		
		}

		// now, recurse through the menu tree if this menu has a submenu and the item is expanded
		if (expandingObject[levelMenu[0]])
		{
			theContent += createExpanding(whichLevel+1, levelMenu[2], whichItem);
		}
		
		
		if (whichLevel == 0)
		{
			theContent += '<TR><TD colspan="3"><IMG src="images/spacer.gif" height="10px"></TD></TR>';
		}
	}
	
	if (whichLevel == 0)
	{
		theContent += '</table>';
	}
	else
	{
		theContent += '</table></td></tr>';
	}
	
	return theContent;
}

function inMenu(whichItem, whichMenu)
{
	var re = new RegExp( "(^|,)" + whichItem + "(,|$)" );
	if ( re.test(whichMenu.toString()) ) { return true; }
	else { return false; }
}

function isExpanding(whichItem, whichMenu)
{
	for (i in whichMenu)
	{
		if (whichMenu[i][0] == whichItem) // we found it!
		{
			if (whichMenu[i][2]) { return true; } // yep, we have a submenu - short-circuit and return true!
			else { return false; } // nope, no submenu - short-circuit and return false
		}
		else if (whichMenu[i][2] && inMenu(whichItem, whichMenu[i][2])) // this menu has a submenu, so recurse it
		{
			return (isExpanding (whichItem, whichMenu[i][2]));
		}
	}
	// nothing found, so 
	return false;
}

function expandText(whichItem)
{
	// first add the dynamic content to the appropriate area
	var contentDivName = whichItem + "_01";
	var contentDiv = document.getElementById(contentDivName);
	if (contentDiv && contentDiv != null) { showContent(contentDivName); }	
	
	// then check against the expandingObject whether we're expanding or collapsing this item
	if (expandingObject[whichItem])
	{
		expandingObject[whichItem] = null; // collapse the menu
		whichItem = null;
	}
	else
	{
		expandingObject[whichItem] = true;
	}

	var contentArea = document.getElementById("expandingContentArea");
	var myContent = createExpanding(0, expandingAry, whichItem);	
	contentArea.innerHTML = ''; // Mac IE 5.1 bug
	contentArea.innerHTML = myContent;
}

// add dynamic content to the content area.
// substitute occurrences of <PRIMLINK> and <SECLINK> containers with properly expanded hyperlinks
function showContent(whichDIV)
{
	contentCell = document.getElementById("dynContentCell");
	contentDIV = document.getElementById(whichDIV);
	
	// expand the pseudo-xml code within the content DIV
	var thisContent = contentDIV.innerHTML;
	var re;
	
	if ( whichDIV.match(/([^_]+)_\d\d/) )
	{
		shortName = RegExp.$1;
	}
	else
	{
		shortName = whichDIV;
	}
	
	var dynContentHeader = '<TABLE border="0" cellspacing="0" cellpadding="0" width="100%"><TR><TD class="bodyHeader" ID="header" align="right"><img src="images/header_' + shortName + '.gif"></TD></TR>';
	if (!/<DYNCONTENT\s+noportfolio>/gi.test(thisContent))
	{
		// "noportfolio" tag not used
		dynContentHeader += '<TR><TD class="bodyContent" align="right"><table border=0 cellspacing=0 cellpadding=0><tr><td width="25px" class="treeContent" onClick="javascript:showPortfolio(\'' + shortName + '\', true);" onMouseOver="status=\'Click to view this portfolio in a popup window (slideshow mode ON)\';" onMouseOut="status=\'\';"><IMG src="images/slideshow_icon_cropped.gif"></td><td valign="center" class="primaryLink" onClick="javascript:showPortfolio(\'' + shortName + '\', true);" onMouseOver="status=\'Click to view this portfolio in a popup window (slideshow mode ON)\';" onMouseOut="status=\'\';">' + shortName + ' portfolio slideshow</td></tr></table></TD></TR>';
	}
	dynContentHeader += '<TR><TD align="center"><img src="images/image_' + shortName + '.jpg"></td></tr>';
		
	// multiline RegExps don't really work consistently, so we do it the dumb way.
	thisContent = thisContent.replace(/<DYNCONTENT[^>]*>/gi , dynContentHeader); // would have liked to use /<DYNCONTENT[ a-z]*>/gi here, but Netscape didn't like it. Bastard.
	thisContent = thisContent.replace(/<\/DYNCONTENT>/gi , '</TABLE>');
	//alert (thisContent);
	
	thisContent = thisContent.replace(/<TEXT>/gi , '<tr><td class="bodyContent">');
	thisContent = thisContent.replace(/<\/TEXT>/gi , '<br /><br /></td></tr>');
	
	thisContent = thisContent.replace(/<PORTFOLIO>([^<]+)<\/PORTFOLIO>/gi , '<tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td width="20px" align="left" class="primaryLink" onMouseUp="showPortfolio(\'' + shortName + '\');" onMouseOver="status=\'Click to view this portfolio in a popup window (slideshow mode OFF)\';" onMouseOut="status=\'\';"><img src="images/slideshow_icon_small.gif" border="0"></td><td class="primaryLink" valign="center" onMouseUp="showPortfolio(\'' + shortName + '\');" onMouseOver="status=\'Click to view this portfolio in a popup window (slideshow mode OFF)\';" onMouseOut="status=\'\';">$1</td></tr></table></td></tr>');
	thisContent = thisContent.replace(/<SEPARATOR><\/SEPARATOR>/gi , '<tr><td background="images/separator_bkg_lt_horiz.gif" colspan="2"><IMG src="images/spacer.gif" height="27px"></td></tr>');
	
	thisContent = thisContent.replace(/<LINKS>/gi , '<tr><td class="bodyContent">');
	thisContent = thisContent.replace(/<\/LINKS>/gi , '</td></tr>');
	
	thisContent = thisContent.replace(/<LOADIMAGE/gi , "<img"); // this substitution is here so that we don't load all the section images when the page loads

	// expand primary and secondary links
	re = /<(PRIMLINK|SECLINK|SLIDELINK|SUBLINK)>([^<]+)<\/(PRIMLINK|SECLINK|SLIDELINK|SUBLINK)>/i;
	while ( thisContent.match( re ) )
	{
		var matchAry = thisContent.match( re );
		var decodeMode = matchAry[1].toUpperCase();
		//var linkIcon = matchAry[1].toUpperCase() == "PRIMLINK" ? "link_arrow_small.gif" : "link_arrow_light_small.gif";
		var linksAry = matchAry[2].split("|");
		for (i in linksAry)
		{
			var thisLink = linksAry[i];
			if (thisLink == "BREAK")
			{
				linksAry[i] = "<br />";
			}
			else if (decodeMode == "PRIMLINK")
			{
				linksAry[i] = '<IMG src="images/link_arrow_small.gif"> <a href="javascript:jumpTo(\'' + thisLink + '\')">' + thisLink + '</a>';
			}
			else if (decodeMode == "SECLINK")
			{
				linksAry[i] = '<IMG src="images/link_arrow_light_small.gif"> <a href="javascript:linkTo(\'' + thisLink + '\')">' + thisLink + '</a>';
			}
			else if (decodeMode == "SUBLINK")
			{
				linksAry[i] = '<IMG src="images/link_arrow_small.gif"> <a href="javascript:jumpTo(\'' + thisLink + '\')">' + thisLink + '</a>';
			}
			else // decodeMode == "SLIDELINK"
			{
				linksAry[i] = '<IMG src="images/slideshow_icon_cropped.gif"><img src="images/spacer.gif" width="8px" height="19px" onClick="javascript:jumpPortfolio(\'' + thisLink + '\', true);"><a href="javascript:jumpPortfolio(\'' + thisLink + '\', true);">' + thisLink + '</a>';
			}

		}
		
		thisContent = thisContent.replace( re, linksAry.join("<br />") );
	}
	
	// expand <INFO> tags
	re = /<INFO\s+link\s*=\s*"([^"]+)"\s*>([^<]+)<\/INFO>/gi;
	while ( thisContent.match( re ) )
	{
		var infoLink = RegExp.$1;
		var infoText = RegExp.$2;
		thisContent = thisContent.replace( re, '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="primaryLink" width="20px" onMouseOver="status=\'Click for an information popup\';" onMouseOut="status=\'\';" onMouseUp="showInfo(\'' + infoLink + '\');"><img src="images/info_icon.gif"></td><td valign="center" class="primaryLink" onMouseOver="status=\'Click for an information popup\';" onMouseOut="status=\'\';" onMouseUp="showInfo(\'' + infoLink + '\');"> ' + infoText + '</td></tr></table>' );
	}
	
	// expand <MORE [dyncontent] prev="" next=""></MORE> tags
	var matchTest = thisContent.match(/<MORE([^>]+)><\/MORE>/gi);
	if (matchTest)
	{
		var moreContent = RegExp.$1;

		dynContent = /dyncontent/gi.test(moreContent);
		prevLink = moreContent.match(/prev="([^"]+)"/gi) ? RegExp.$1 : "";
		nextLink = moreContent.match(/next="([^"]+)"/gi) ? RegExp.$1 : "";

		var newContent = dynContent ? '<tr><td>' : '';
		newContent += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="left" valign="center" class="primaryLink" onMouseOver="status=\'click to see more on this topic\';" onMouseOut="status=\'\';" onMouseUp="showContent(\'' + prevLink + '\');"><img src="images/arrow_prev.gif" border="0"></td><td align="center" class="primaryLink" onMouseOver="status=\'click to see more on this topic\';" onMouseOut="status=\'\';" onMouseUp="showContent(\'' + nextLink + '\');"><img src="images/more_icon.gif" border="0"></td><td align="right" valign="center" class="primaryLink" onMouseOver="status=\'click to see more on this topic\';" onMouseOut="status=\'\';" onMouseUp="showContent(\'' + nextLink + '\');"><img src="images/arrow_next.gif" border="0"></td></tr></table>';
		newContent += dynContent ? '</td></tr>' : '';
		
		thisContent = thisContent.replace( /<MORE[^>]*><\/MORE>/gi, newContent );
	}
	
	contentCell.innerHTML = ''; // for Mac IE5.1 bug
	contentCell.innerHTML = thisContent;
	//alert (thisContent);
}

function jumpTo(whichItem)
{
	// first add the dynamic content to the appropriate area
	contentDiv = document.getElementById(whichItem + "_01") ? document.getElementById(whichItem + "_01") : document.getElementById(whichItem);
	if (contentDiv && contentDiv != null) { showContent(contentDiv.id); }	
	
	if (inMenu(whichItem, expandingAry))
	{
		// only register this item if it's expandable
		if (isExpanding(whichItem, expandingAry)) { expandingObject[whichItem] = true; }
	
		var contentArea = document.getElementById("expandingContentArea");
		var myContent = createExpanding(0, expandingAry, whichItem);	
		contentArea.innerHTML = ''; // Mac IE 5.1 bug
		contentArea.innerHTML = myContent;
	}
}

function jumpPortfolio(whichDIV, slideshowOn)
{
	jumpTo(whichDIV);
	showPortfolio(whichDIV, slideshowOn);
}

// --------------------------- Expanding Columns Subroutines -----------------------------------------------------

var sidebarColWidth = 175;
var totalCols = 1;
function populateSidebar()
{
	var sidebarArea = document.getElementById("sidebar_content");
	var sidebarWidth = sidebarArea.offsetWidth;
	
	totalCols = sidebarWidth >= sidebarColWidth * 2 + 40 ? 2 : 1;
	
	var sidebarContent;
	if (totalCols == 1)
	{
		sidebarContent = document.getElementById("sidebar_1").innerHTML;
		sidebarContent += document.getElementById("sidebar_2").innerHTML;
	}
	else // totalCols == 2
	{
		sidebarContent = '<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"><tr><td width="50%" valign="top">';
		sidebarContent += document.getElementById("sidebar_1").innerHTML;
		sidebarContent += '</td>';
		sidebarContent += '<td><img src="images/spacer.gif" width="10px"></td><TD width="20" background="images/dashed_line_lt_bkg_vert.gif" height="100%"><IMG src="images/spacer.gif" width="20px"></TD><td><img src="images/spacer.gif" width="10px"></td>';
		sidebarContent += '<td width="50%" valign="top">';
		sidebarContent += document.getElementById("sidebar_2").innerHTML;
		sidebarContent += '</td></tr></table>';
	}

	//var arrowDirection = whatsNewExpanded ? "down" : "up"; 
	
	//var whatsNewContent = document.getElementById("whats_new_recent").innerHTML;	
	//whatsNewContent = whatsNewContent.replace(/<ARCHIVES><\/ARCHIVES>/gi , '<a href="javascript:expandWhatsNew()"><img id="whats_new_arrow" src="images/text_expand_arrow_' + arrowDirection + '.gif"; border="0"></a><img src="images/spacer.gif" width="4px"><a href="javascript:showHelp(\'help_whats_new\');"><img src="images/help_icon_small.gif" border="0"></a>&nbsp;&nbsp;');
	
	//if (whatsNewExpanded) { whatsNewContent += document.getElementById("whats_new_archive").innerHTML; }
	
	//sidebarContent = sidebarContent.replace(/<WHATSNEW><\/WHATSNEW>/gi, whatsNewContent);
	sidebarArea.innerHTML = sidebarContent;
}

function repopulateSidebar()
{
	var sidebarArea = document.getElementById("sidebar_content");
	var sidebarWidth = sidebarArea.offsetWidth; // use offsetWidth instead of clientWidth for NS7 compatibility
	
	var newTotalCols = sidebarWidth >= sidebarColWidth * 2 + 20 ? 2 : 1;
	if (newTotalCols != totalCols) { populateSidebar(); }
}


// --------------------------- WHAT'S NEW SUBROUTINES ------------------------------------------------------------------

var whatsNewExpanded = false;
function expandWhatsNew()
{
	whatsNewExpanded = !whatsNewExpanded;
	populateSidebar();
}

// --------------------------- POPUP WINDOW SUBROUTINES ----------------------------------------------------------------------


function linkTo(whichLink)
{
	for (i in linkToAry)
	{
		if (linkToAry[i][0] == whichLink)
		{
			var config = linkToAry[i][2] ? linkToAry[i][2] : "";
			window.open(dev_dir + linkToAry[i][1], "linkwindow", config);
			return;
		}
	}
	alert ("We are really sorry - that link does not appear to be active at this time.");
}


function showPortfolio(whichSection, slideshowOn)
{
	time = new Date;
	secs = Date.UTC(time); // force reload in IE
	
	config='toolbar=no,location=no,directories=no,status=no,menubar=no,width=400,height=600,scrollbars=no,resizable=no';
	var slideshowToggle = slideshowOn ? "&slideshowOn=true" : "";
	
	window.open (dev_dir + "cgi-bin/new_portfolio.pl?s=" + whichSection + slideshowToggle + "&" + secs, "portfolio", config); // use Perl script to generate content list from MySQL database
}

function WOTDPopup()
{
	time = new Date;
	secs = Date.UTC(time); // force reload in IE
	
	command='wordOfTheDay';
	config='toolbar=no,location=no,directories=no,status=no,menubar=no,width=600,height=275,scrollbars=yes,resizable=yes,scrolling=yes';
	window.open (dev_dir + "cgi-bin/speller.pl?cmd=" + command + "&" + secs,"Spell",config);
}

function wallPopup()
{
	config='toolbar=no,location=no,directories=no,status=no,menubar=no,width=385,height=290,scrollbars=no,resizable=yes';
	window.open (dev_dir + "WALL/post.html","wall",config);
}

function launchFlash(whichURL, windowName, config){
	window.open(whichURL, windowName, config);
}

// -------------------- HELP, INFO and ALERT SUBSYSTEM -------------------------------------------------------------------

function showHelp(whichContentDiv)
{
	var helpContentSpan = document.getElementById("help_content");
	if (document.getElementById(whichContentDiv)) {
		helpContentSpan.innerHTML = document.getElementById(whichContentDiv).innerHTML;
		
		var helpDiv = document.getElementById("help_dialog");
		helpDiv.style.visibility = "visible";
	}
	else {
		alert ("We're terribly sorry. That HELP feature is deactivated.");
	}
}

function hideHelp()
{
	// this of course assumes that only one alert is open at a time!
	var helpDiv = document.getElementById("help_dialog");
	helpDiv.style.visibility = "hidden";
}

// shows the info dialog box. If modalFlag == true, the OK button is NOT displayed (info dialog must be hidden using some other method)
function showInfo(whichContentDiv, modalFlag)
{
	document.getElementById("info_header").src = "images/info_header_" + whichContentDiv + ".gif"; // we have to do this BEFORE we add the "info_"
	whichContentDiv = "info_" + whichContentDiv;
	
	var infoContentSpan = document.getElementById("info_content");
	if (document.getElementById(whichContentDiv))
	{
		var theContent = document.getElementById(whichContentDiv).innerHTML;
		
		if (!modalFlag)
		{
			theContent += '<br /><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="center"><a href="javascript:hideInfo();"><img src="images/info_ok.gif" border="0"></a></td></tr></table>';
		}

		infoContentSpan.innerHTML = theContent;
			
		var infoDiv = document.getElementById("info_dialog");
		infoDiv.style.visibility = "visible";
	}
	else
	{
		alert ("We're sorry, that information is not available at this time. Please check back soon.");
	}
}

function hideInfo()
{
	// this of course assumes that only one info dialog is open at a time!
	var infoDiv = document.getElementById("info_dialog");
	infoDiv.style.visibility = "hidden";
}

function showAlert(whichContent)
{
	var whichContentDiv = whichContent + "_alert";
	
	var alertAction = getCookie(whichContentDiv + "_action");
	if (alertAction)
	{
		doAlertTask(whichContentDiv, alertAction);
	}
	else
	{
		var alertHeaderImg = document.getElementById("alert_header_img");
		alertHeaderImg.src = "images/alert_" + whichContent + "_header.gif";
		
		var alertContent = document.getElementById(whichContentDiv).innerHTML;
		alertContent = alertContent.replace(/<dontremind><\/dontremind>/gi, '<input type="checkbox" id="' + whichContentDiv + '_dont_remind"> Don\'t show me this alert again.');	
		
		var alertContentSpan = document.getElementById("alert_content");
		alertContentSpan.innerHTML = alertContent;

		var alertDiv = document.getElementById("alert_dialog");
		alertDiv.style.visibility = "visible";
	}
}

function hideAlert()
{
	// this assumes that only one alert is open at a time!
	var alertDiv = document.getElementById("alert_dialog");
	alertDiv.style.visibility = "hidden";
}

// Handles the buttons on the dialog. WhichEvent is the button that the user clicked ie: the action taken
// This script also checks for the presence of a "don't remind me again" checkbox (identified by the name of the alert + "_dont_remind")
// if the checkbox is "checked" then a cookie is stored. The script also checks to make sure the user has allowed cookies.
// Finally, the script then executes the chosen task by calling doAlertTask();

function processAlert(whichAlert, whichEvent)
{
	var dontRemind = document.getElementById(whichAlert + "_dont_remind");

	if (dontRemind && dontRemind.checked)
	{
		checkCookies();
		var cookieName = whichAlert + "_action";
		document.cookie = cookieName + "=" + whichEvent;
	}
	
	hideAlert();
	doAlertTask(whichAlert, whichEvent);
}


// Processes the alert task. Defaults to simply closing the alert if the input is "cancel"
function doAlertTask(whichAlert, whichEvent)
{
	if (whichEvent == "cancel") { return; }
	
	if (whichAlert == "macie_alert")
	{
		config='location=yes,scrollbars=yes,resizable=yes,scrolling=yes';
		window.open ("http://www.microsoft.com/mac/downloads.aspx#IE", "DownloadIE", config);
	}
}

// this function checks to see whether the user is accepting cookies. If not, it lets them know
// that some functionality will not work the way it is supposed to.
function checkCookies()
{
	Today = new Date();
	var secs = Today.toUTCString(); 
	
	document.cookie = "D3_cookie_test=" + secs;

	// retrieve the test cookie
	var i = document.cookie.indexOf("D3_cookie_test");

	var j = document.cookie.indexOf(";", i);
	var thisCookie = j > i ? document.cookie.slice(i, j) : document.cookie.slice(i);
	var cookieAry = thisCookie.split("=");

	if (cookieAry[1] != secs)
	{
		alert ("You do not have cookies enabled.\n\nSome features of this site will not work until you enable them.");
	}
}

// Utility function. Returns the value of the cookie if present or "null" if not.
function getCookie(whichCookie)
{
	var i = document.cookie.indexOf(whichCookie);
	if (i > -1)
	{
		var j = document.cookie.indexOf(";", i);
		var thisCookie = j > i ? document.cookie.slice(i, j) : document.cookie.slice(i);
		var cookieAry = thisCookie.split("=");

		return cookieAry[1];
	}
	else
	{
		return null;
	}
}

// Sets cookie values. Expiration date is optional
// expire is a value in DAYS
function setCookie(name, value, expire)
{
	if (expire)
	{
		expire = expire * 1000*60*60*24; 
		var myDate = new Date();
		var expiryDate = new Date(myDate.getTime() + expire);
		expire = expiryDate.toGMTString();
	}

	document.cookie = name + "=" + value + ( (expire == null) ? "" : ("; expires=" + expire) );
}