// Features
/*

author: scott lenger

last updated: 4/29/2009 - EJR
- turned variable 'listHeading' into an argument defaulted to 'h3'

instructions:
1. link to file
2. add "setFeatures();" to onload function
3. make sure container div id and list heading tag match what is defined at the beginning of the script.

*/

// These XHTML/CSS id's must match
var featureId = "features"; // id of features containing div
//var listHeading = "h3";

function setFeatures(startRandom,listHeading) {
	// default arguments and variables
 	listHeading = typeof(listHeading) != 'undefined' ? listHeading : 'h3';
	var getFeatureHeader = '';
	
	// add a little CSS to give the impression of links
	if(!document.getElementById(featureId)) {return;} // make sure the XHTML id matches
	
	// add the javascript only css
	var featureList = document.getElementById(featureId);
	featureList.className = "compact";
	
	// show the first child list by default
	var getFeatureHeader = featureList.getElementsByTagName(listHeading);
	var startNode = 0;
	if (startRandom == "true") { // if true, start with a random list node
		var randomMax = getFeatureHeader.length-1; // count the total # of nodes subtracting one since array's begin at 0.
		var startNode = Math.floor(Math.random() * (randomMax - 0 + 1)) + 0;  // get random node: return Math.floor(Math.random() * (max - min + 1)) + min; (from: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Math:random)
	}
	getFeatureHeader[startNode].parentNode.className = 'fcurrent';
	
	// give parent li onclick
	for (var i=0; i<getFeatureHeader.length; i++) {
		getFeatureHeader[i].parentNode.onclick = function() {
			hideFeatures(); // removes previous list
			this.className += " fcurrent"; // shows selected list
		}
	}
	
	// removes fcurrent class from parent wrapper li
	function hideFeatures() {
		for (var i=0; i<getFeatureHeader.length; i++) {
			getFeatureHeader[i].parentNode.className = getFeatureHeader[i].className.replace(" fcurrent", "");
		}
	}

	 /*
	// jQuery Version
	$("ul#features").find("ul").eq(0).css({display: "block"});
	$("ul#features").find("h3").eq(0).addClass("fcurrent");
	
	// give h3's onclick function
	$("ul#features li h3").click(function() {
		// hide all child lists, then show the requested list
		$("ul#features li ul").hide();
		$(this).parents("li").children("ul").show(); // fadeIn also works nicely depending on bg
		// remove h3 class and assign to current
		$("ul#features li h3").removeClass("fcurrent");
		$(this).parents("li").children("h3").addClass("fcurrent");
	});
	*/
}