/* COOKIE MANAGEMENT */
/* adaped from neGlobal.js, by Andy Lottman */
/* needs to be replaces with global cookie handling */
var rbCookies;
function rbAllCookies() {
   rbCookies = new Array();
   if (document.cookie) {
	  var temp = document.cookie.split("; ");
	  for (var i=0; i<temp.length; i++) {
		 var cook = temp[i].split("=");
		 rbCookies[cook[0]] = cook[1];
	  }
   }
}
rbAllCookies();

function rbSetCookie(name,val,expDays) {
 var cs = name+"="+escape(val);
 if (expDays) {
	var exp = new Date();
	exp.setTime(exp.getTime() + 1000*60*60*24*expDays);
	cs += "; expires="+exp.toGMTString();
 }
 cs += "; path=/";
 document.cookie=cs;
}

function rbGetCookie(which) {
   if (rbCookies[which]) return unescape(rbCookies[which]);
   else return false;
}
/* END COOKIE MANAGEMENT */


Event.onDOMReady(function() {

	var fxHeight = new Array();
	var fxOpacity = new Array();
	var saveState = new Array(1,0,0,0); // default;
	if (rbGetCookie("xnav")) { // override with cookie val, if available
		saveState = rbGetCookie("xnav").split(",");
	}
	
	var grps = document.getElementsByClassName("xNavGrp", "xNav");

	function BuildOnclickFx(obj, where, x) {
		var d = (where.childNodes.length*10<500) ? where.childNodes.length*15 : 500; // variable speed, depending on length. cap at 500ms
		fxHeight[x] = new fx.Height(where.id, {duration: d});
		fxOpacity[x] = new fx.Opacity(where.id, {duration: d});
		obj.onclick = function() {
			fxHeight[x].toggle();
			fxHeight[x].options.onComplete = function(){ 
				saveState[x] = (this.now==0) ? 0 : 1;
				rbSetCookie("xnav",saveState,30);
			}
			fxOpacity[x].toggle();
		}
		obj.onmouseover = function() {
			this.id = "hover";
		}
		obj.onmouseout = function() {
			this.id = "";
		}
		
		if (saveState[x]!=1) {
			fxHeight[x].hide();
			fxOpacity[x].hide();
		}
	}
	
	for(var x=0;x<grps.length;x++) {
		var theH3 = grps[x].getElementsByTagName("H3");
		var theH3A = theH3[0].getElementsByTagName("A");
		var theUL = grps[x].getElementsByTagName("UL");
		
		var btn = document.createElement("DIV");
		btn.className = "btn";
		var btnObj = theH3[0].appendChild(btn);
		
		theUL[0].id = "xNav-"+x;
		theH3A[0].onfocus = function() {this.blur()};

		BuildOnclickFx(btnObj, theUL[0], x);
	}
});	

var showGrp = 1; // which nav group to display on page load? (zero-based)
