// DHTML Navbar Generator and Controller Script for CNNSI.com
// written by Dennis Davis and James Baker
// [requires definition of 'navbarData' array and properties]
//
// version 1.2.2; June 6, 2001
//   * changed image references to use i.cnn.net vs. relative URL's to allow for
//     partner sites to call this script, rather than duplicating/modifying it
// version 1.2.1; May 18, 2001
//   * altered navbarData array structure again, to accommodate individual items
//     using different class attributes (and optionally another when expanded)
// version 1.2.0; May 14, 2001
//   * added iOf (index of) array to allow re-organizing elements of navbarData
//     without re-coding array references every time
//   * allowed for definition of navbarData.subhead
//     (html which comes after navbar 'stripe' cell and before first link)
// version 1.1.0; May 10, 2001
//   * fixed navbar generation to work on NS6
// version 1.0.1; May 09, 2001
//   * avoided generating navbars on NS6 (didn't work right);
//   * added function makeShowAllArrows to allow hiding of the arrows
//     on NS6 or non-JS browsers
// version 1.0.0; May 2001
//   * *shrug* this is where it started...
//   * placed on the site after many development versions were tried internally

var NS4 = (document.layers) ? 1 : 0;
var NS6 = (!document.all && document.getElementById) ? 1 : 0;
var IE4 = (document.all && !document.getElementById) ? 1 : 0;
var IE5 = (document.all && document.getElementById) ? 1 : 0;
var PopupWorks = (NS4 || IE4 || IE5) ? 1 : 0;
var last = "holder";

// I don't know WHY this is needed, but it seems to be. *shrug*
if (NS6) { document.write('<style type="text/css"> .NavMenu TD {padding: 2px;} </style>'); }

// Define the structure of the expected array 'navbarData'
//   so we can add/remove/re-arrange features as needed
//   without re-coding all the array references in the script
var iOf = Array();
	iOf.id = 0;			// id name for div element
	iOf.lTxt = 1;		// link text
	iOf.lUrl = 2;		// link URL
	iOf.lClass = 3;		// link class name
	iOf.sTxt = 4;		// scores link text
	iOf.sUrl = 5;		// scores link URL
	iOf.sClass = 6;		// scores class name
	iOf.subData = 7;	// subnavigation HTML data
	iOf.subClass = 8;	// subnavigation class name
	iOf.subBgImg = 9;	// subnavigation cell background image

if (PopupWorks || NS6) {
//	alert('PopupWorks == ', PopupWorks);
	var navigation = genLayers();
}

function showAll(name,width,height) {
	if (NS4) {
		if (!document.layers[name]) { name = "holder"; };
		document.layers[name].visibility = "show";
		document.layers[name].left = navbarData.xLoc + width;
		document.layers[name].top = navbarData.yLoc + height;
	} else if (IE4 || IE5) {
		if (!document.all[name]) { name = "holder"; };
		document.all[name].style.visibility = "visible";
		document.all[name].style.pixelLeft = navbarData.xLoc + width;
		document.all[name].style.pixelTop = navbarData.yLoc + height;
	} else {
		if (!document.getElementById(name)) { name = "holder"; };
		idN = document.getElementById(name);
		idN.style.visibility = "visible";
		idN.style.left = navbarData.xLoc + width;
		idN.style.top = navbarData.yLoc + height;
	}
	killWindow(last)
	last = name;
}

function killWindow(last) {
	if (NS4) {
		document.layers[last].visibility = "hidden";
		document.layers[last].left = navbarData.xLoc;
		document.layers[last].top = navbarData.yLoc;
	} else if (IE4 || IE5) {
		document.all[last].style.visibility = "hidden";
		document.all[last].style.pixelLeft = navbarData.xLoc;
		document.all[last].style.pixelTop = navbarData.yLoc;
	} else {
		idL = document.getElementById(last);
		idL.style.visibility = "hidden";
		idL.style.left = navbarData.xLoc;
		idL.style.top = navbarData.yLoc;
	}
}

function makeShowAllArrow(name,saWidth,saHeight) {
	if (PopupWorks || NS6) {
		document.write('<a href="javascript:showAll(\'' + name + '\',' + saWidth + ',' + saHeight + ');"><img src="http://i.cnn.net/si/images/misc/nav_folderClosed.gif" width="11" height="11" border="0"></a>');
	}
}

function genLayers () {
	if (!navbarData.width) { navbarData.width = 125; };
	if (!navbarData.subhead) {
		navbarData.subhead = '<td class="NavHLight" colspan="2"><a class="NavHLight" href="/scoreboards/">scoreboards</a></td></tr>';
	}
	if (!navbarData.subheadrows) { navbarData.subheadrows = 1; }; // used to adjust the rowspan of the stripe to the proper length

	menu_txt = '<div id="holder" class="NavMenu"></div>';
//	wrote = 'Wrote: holder';
	for (var i = 0; i < navbarData.length; i++) {
		idName = navbarData[i][iOf.id];
		if ((! navbarData[i][iOf.subData] || navbarData[i][iOf.subData] == '') && idName != "main") { continue; }; // else { wrote += ', ' + idName; };
		menu_txt += '<div id="' + idName + '" class="NavMenu">'
			+ '<table bgcolor="black" border="0" cellpadding="2" cellspacing="0" width="' + navbarData.width + '"><tr><td>'
			+ '<table bgcolor="black" cellspacing="1" cellpadding="2" border="0" width="100%">'
			+ '<tr><td><img src="http://i.cnn.net/si/images/misc/blank_pixel.gif" width="3" height="1" alt="" border="0"></td>'
			+ '<td class="' + navbarData.headclass + '" colspan="2"><a class="' + navbarData.headclass + '" href="' + navbarData.headlink + '">' + navbarData.headtext + '</a></td></tr>'
			+ '<tr><td class="NavStripe" rowspan="' + (navbarData.length + navbarData.subheadrows) + '"><img src="http://i.cnn.net/si/images/misc/blank_pixel.gif" width="3" height="1" alt="" border="0"></td>'
			+ navbarData.subhead;
		for (var l = 0; l < navbarData.length; l++) {
			hasSubNav = (navbarData[l][iOf.subData] && navbarData[l][iOf.subData] != '') ? 1 : 0;
			if (!navbarData[l][iOf.subClass]) {
				navbarData[l][iOf.subClass] = "NavMain"
			}
			if (i == l && hasSubNav) {
				menu_txt += '<tr><td class="' + navbarData[l][iOf.subClass] + '" width="100%" colspan="2" ' + navbarData[l][iOf.subBgImg] + '>'
					+ '<a href="javascript:showAll(\'holder\',0,0);"><img src="http://i.cnn.net/si/images/misc/nav_folderOpen.gif" border="0"></a>'
					+ '<a class="' + navbarData[l][iOf.subClass] + '" href="' + navbarData[l][iOf.lUrl] + '">' + navbarData[l][iOf.lTxt] + '</a>'
					+ navbarData[l][iOf.subData] + '</td></tr>';
			}
			else {
				if (navbarData[l][iOf.sUrl]) {
					menu_txt += '<tr><td class="' + navbarData[l][iOf.lClass] + '" width="95%">';
					if (hasSubNav) {
						menu_txt += '<a href="javascript:showAll(\'' + navbarData[l][iOf.id] + '\',0,0);"><img src="http://i.cnn.net/si/images/misc/nav_folderClosed.gif" border="0"></a>';
					}
					menu_txt += '<a class="' + navbarData[l][iOf.lClass] + '" href="' + navbarData[l][iOf.lUrl] + '">' + navbarData[l][iOf.lTxt] + '</a></td>'
						+ '<td class="' + navbarData[l][iOf.sClass] + '"><a class="' + navbarData[l][iOf.sClass] + '" href="' + navbarData[l][iOf.sUrl] + '">' + navbarData[l][iOf.sTxt] + '</a></td></tr>';
				}
				else {
					menu_txt += '<tr><td class="' + navbarData[l][iOf.lClass] + '" colspan="2">';
					if (hasSubNav) {
						menu_txt += '<a href="javascript:showAll(\'' + navbarData[l][iOf.id] + '\',0,0);"><img src="http://i.cnn.net/si/images/misc/nav_folderClosed.gif" border="0"></a>';
					}
					menu_txt += '<a class="' + navbarData[l][iOf.lClass] + '" href="' + navbarData[l][iOf.lUrl] + '">' + navbarData[l][iOf.lTxt] + '</a></td></tr>';
				}
			}
		}
		menu_txt += '<tr><td class="' + navbarData.footclass + '" colspan="3" align="center">'
			+ '<a class="' + navbarData.footclass + '" href="' + navbarData.footlink + '">' + navbarData.foottext + '</a>';
		if (PopupWorks) {
			menu_txt += '<br><a href="#" onClick="stc(); return false;" onMouseOut="nd(); return true;"><img border="0" src="http://i.cnn.net/si/images/components/navotherbutton.gif" width="95" height="18"></a>';
		}
		menu_txt += '</td></tr></table></td></tr></table>'
			+ '</div>';
	}
//	alert(wrote + '\n');
	return menu_txt;
}

if (PopupWorks || NS6) {
	document.write(navigation);
}
