window.onload = function() {
	// scripts added to widget.js:
	setFeatureRows();
}

function setFeatureRows() {
	var c = getTags(document,'td');		
	for (var i = 0; i < c.length; i++) {		
		if (hasClass(c[i],'moreInfo')) {
			if (c[i].addEventListener) {
				c[i].addEventListener('mouseover',showFeature,false);	
				c[i].addEventListener('mouseout',hideFeature,false);						
			}
			else {
				c[i].onmouseover = showFeature;
				c[i].onmouseout = hideFeature;
			}	
		}
	}
}

function showFeature(e,caller) {
	if (!caller) caller = this;		
	var row = getParent(caller);
	var tbody = getParent(row);
	var allRows = getChildren(tbody);
	var nextRow = row.rowIndex;		
	hideFeature();				
	addClass(row,'selectedFeature');
	addClass(allRows[nextRow],'selectedFeature');
}

function hideFeature() {				
	var tr = getTags(document,'tr');		
	for (var i = 0; i < tr.length; i++) {
		if (hasClass(tr[i],'selectedFeature')) {
			removeClass(tr[i],'selectedFeature');
		}
	}
}

// this replaces getElementsWithTagName
// works in IE4+, NS6+
function getTags(obj, tagName){
	// we can take in an id string or an object pointer
	// if it's a string, just use getObject on the id
	if (typeof(obj) == 'string') obj = getObject(obj);
	
	if (obj.getElementsByTagName){
		return obj.getElementsByTagName(tagName);
	}
	else if (document.all){
		if (tagName == "*"){
			return obj.all;
		}
		else{
			// IE4 (and maybe some other browsers) support this method
			// but tagname must be in uppercase
			tagName = tagName.toUpperCase();
			return obj.all.tags(tagName);
		}
	}
	else{
	// we can't get the tags, so we'll return nothing
	return null;
	}
}

// returns true if the object has the specified class
function hasClass(obj, className){
	// we can take in an id string or an object pointer
	// if it's a string, just use getObject on the id
	if (typeof(obj) == 'string') obj = getObject(obj);
	
	if (obj.className){
		var classes = obj.className.split(" ");
		for (var i = 0; i < classes.length; i++){
			if (classes[i]	== className){
				return true;
			}
		}
		return false;
	}
	else{
		return false;
	}
}

// return the object's parent
// this does not work in NS 4.x
function getParent(obj){
	// we can take in an id string or an object pointer
	// if it's a string, just use getObject on the id
	if (typeof(obj) == 'string') obj = getObject(obj);
	
	if (obj.parentNode){
		return obj.parentNode;
	}
	else if (obj.parentElement){
		return obj.parentElement;
	}
	else if (obj.parentLayer){
		return obj.parentLayer;
	}
	else{
		// we can't get the parent, so return null
		return null;
	}
}

// this is a more compatible version of element.childNodes
// works in IE4+, NS6+
// moz/opera count whitespace nodes, but IE does not
function getChildren(obj){
	// we can take in an id string or an object pointer
	// if it's a string, just use getObject on the id
	if (typeof(obj) == 'string') obj = getObject(obj);
	
	if (obj.childNodes){
		// for non IE browsers, we need to clean out the whitespace nodes
		// for consistency
		var nonWhitespace = new Array();
	
		for (var i = 0; i < obj.childNodes.length; i++){
			if (obj.childNodes[i].tagName != null && obj.childNodes[i].tagName != "!"){
				nonWhitespace[nonWhitespace.length] = obj.childNodes[i];
			}
		}
		return nonWhitespace;
	}
	else if (obj.children){	
		var nonWhitespace = new Array();
	
		// don't include comment tags (tags that have a tagName of !)
		for (var i = 0; i < obj.children.length; i++){
			if (obj.children[i].tagName != "!"){
				nonWhitespace[nonWhitespace.length] = obj.children[i];
			}
		}
		return nonWhitespace;
	}
	else if (obj.layers){
		return obj.layers;
	}
	else{
	// we can't get the tags, so we'll return nothing
	return null;
	}
}

// add the CSS class to the object
function addClass(obj, className){
	// we can take in an id string or an object pointer
	// if it's a string, just use getObject on the id
	if (typeof(obj) == 'string') obj = getObject(obj);
	
	if (!hasClass(obj, className)){
		if (obj.className == null || obj.className == ""){
			obj.className = className;
		}
		else{
			// append this to the list of existing classes
			obj.className = obj.className + " " + className;
		}
	}
}

// remove the CSS class (if it exists)
function removeClass(obj, className){
	// we can take in an id string or an object pointer
	// if it's a string, just use getObject on the id
	if (typeof(obj) == 'string') obj = getObject(obj);
	
	var classes = obj.className.split(" ");
	var newClasses = new Array();
	
	for (var i = 0; i < classes.length; i++){
		if (classes[i]	!= className){
			newClasses[newClasses.length] = classes[i];
		}
	}
	
	var newClassString = newClasses.join(" ");
	obj.className = newClassString; 
}

