// Navbar Generator Mk II
// Written by James Baker (jabaker) for CNNSI.com
// version 1.1.0
// build 20020101a

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 supportsDisplayProperly = (IE4 || IE5 || NS6) ? 1 : 0;
// var last = 'defaultnav';
var imgsRoot = 'http://i.cnn.net/si';
// imgsRoot = 'http://a.cnn.net/si';
// imgsRoot = 'http://a1208.g.akamai.net/g/7/1208/380/1d/sportsillustrated.cnn.com';
// imgsRoot = '';
// imgsRoot = 'http://sportsillustrated.cnn.com';
var urlRoot = 'http://sportsillustrated.cnn.com';
document.isRemoteHosted = 0;


function Navbar (name) {

// define the array indices of various data elements
this.NAME = name;
var indexOf = 0;

this.ID = indexOf++;
this.TEXT = indexOf++;
this.URL = indexOf++;
this.CLASS = indexOf++;
// this.SCORETEXT = indexOf++;
// this.SCOREURL = indexOf++;
// this.SCORECLASS = indexOf++;
this.EVENTLIST = indexOf++;
this.EVENTCLASS = indexOf++;
this.SUBNAV = indexOf++;
this.SUBCLASS = indexOf++;
this.BULLET = indexOf++;

// define the array itself
	this.data = new Array;
	this.styles = new Array;
	this.styles['default'] = 'NavMain';
	this.styles['stripe'] = 'NavStripe';
	this.styles['hilite'] = 'NavHLight';
	this.styles['hilite2'] = 'NavHLight2';
	this.styles['scores'] = 'NavAlt';
	this.styles['alt'] = 'NavAlt';
	this.styles['sub'] = 'NavSubList';
// set the default width
	this.width = 120;
// assign the build function/method (to all Navbar object instances)
	this.build = Navbar_Build;
// assign our other function/methods too
	this.hasScores = Navbar_HasScores;
	this.hasSubnav = Navbar_HasSubnav;
	this.hasEvents = Navbar_HasEvents;
	this.hasBullet = Navbar_HasBullet;

}

// define some constants (in this case, array indicies for the Navbar objects to use)
// new Navbar (empty);

function Navbar_Build () {
	var navstr = "";
	navstr += '<table cellpadding="1" cellspacing="0" border="0" width="' + this.width + '" summary="' + this.NAME + '">\n';
	for (var i = 0; i < this.data.length; i++) {
//alert(i + ': ' + this.data[i].constructor);
		if (typeof this.data[i] == 'string') {
			navstr += this.data[i];
		} else if (this.data[i].constructor == Array) {
			navstr += '<tr valign="top">\n';
			if (this.hasBullet(i)) {
				if (typeof this.data[i][this.BULLET] == 'string') {
					navstr += this.data[i][this.BULLET];
				} else if (this.data[i][this.BULLET].constructor == Array) {
					navstr += '<td class="' + this.data[i][this.BULLET][4] + '"><img src="' + (imgsRoot ? imgsRoot : (document.isRemoteHosted ? urlRoot : '')) + this.data[i][this.BULLET][0] + '"'
						+ ' width="' + this.data[i][this.BULLET][2] + '" height="' + this.data[i][this.BULLET][3] + '"'
						+ ' border="0" alt="' + this.data[i][this.BULLET][1] + '" valign="middle"></td>';
				}
			}
			navstr += '<td class="' + this.data[i][this.CLASS] + '"'
			if (this.hasScores(i)) {
				navstr += ' width="98%"';
			} else if (this.hasBullet(i)) {
				navstr += '';
			} else {
				navstr += ' width="100%" colspan="2"';
			}
			navstr += '>';
			if (this.data[i][this.URL] != '') {
				navstr += '<a href="';
				if (IsRelativeURL(this.data[i][this.URL]) && document.isRemoteHosted) {
					navstr += urlRoot
				}
				navstr += this.data[i][this.URL] + '">' + this.data[i][this.TEXT] + '</a>';
			} else {
				navstr += this.data[i][this.TEXT];
			}
			if (this.hasSubnav(i)) {
				if (typeof this.data[i][this.SUBNAV] == 'string') {
					navstr += this.data[i][this.SUBNAV];
				} else if (typeof this.data[i][this.SUBNAV] == 'Subnav') {
					this.data[i][this.SUBNAV].build();
					navstr += this.data[i][this.SUBNAV].asHtml;
				}
			}
			if (this.hasEvents(i)) {
				navstr += this.data[i][this.EVENTLIST];
			}
			navstr += '</td>\n';
			if (this.hasScores(i)) {
				navstr += '<td class="' + this.data[i][this.SCORECLASS] + '"><a class="' + this.data[i][this.SCORECLASS] + '" href="' + this.data[i][this.SCOREURL]
					+ '">' + this.data[i][this.SCORETEXT] + '</a></td>\n';
			}
			navstr += '</tr>\n';
		}
	}
	navstr += '</table>\n';
	this.asHtml = navstr;
}

function Navbar_HasScores (index) {
/*
	if (this.data[index]) {
		if (this.data[index][this.SCORETEXT]) { return true; };
	}
*/
	return false;
}

function Navbar_HasSubnav (index) {
	if (this.data[index]) {
		if (this.data[index][this.SUBNAV]) { return true; };
	}
	return false;
}

function Navbar_HasEvents (index) {
	if (this.data[index]) {
		if (this.data[index][this.EVENTLIST]) { return true; };
	}
	return false;
}

function Navbar_HasBullet (index) {
	if (this.data[index]) {
		if (this.data[index][this.BULLET]) { return true; };
	}
	return false;
}

/* Unused object constructor */
function Subnav () {
	this.data = '';
}

function Hide_Div (id) {
	if (NS4) {
		document.layers[id].visibility = "hidden";
	} else if (IE4 || IE5) {
		document.all[id].style.display = "none";
	} else {
		obj = document.getElementById(id);
		obj.style.display = "none";
	}
}

function IsRelativeURL (url) {
	if (url.indexOf('http://') == 0) {
		return false;
	} else if (url.indexOf('https://') == 0) {
		return false;
	} else if (url.indexOf('ftp://') == 0) {
		return false;
	} else if (url.indexOf('mailto://') == 0) {
		return false;
	} else {
		return true;
	}
}
