// 04-27-06

var themeSelection = 0;
var image_dir = "/img/";
var cStringOffset = 1;
var isSafari = navigator.userAgent.indexOf('Safari') != -1;
var expires = null;
var baseLinkID = null;

var date = new Date();
date.setTime(date.getTime()+(2*60*60*1000));
var exm = date.toGMTString();

// order: text,image,tab
var xx = new Array(); 
var xx2 = new Array();
var xx3 = new Array();

var af = new Array();
var ap = new Array();
var sel = new Array();

function dock(sel) {
		// nesting target divs in a table hurts firefox's ability to 
		// update div window length -- maybe others too (not Safari or IE)
		if(!isSafari && !document.all) {
			// instead of reloading page, mess with div height
			document.getElementById("content").style.height = 40;
			document.getElementById("content").style.height = document.getElementById("textContainer").style.height;
		}
	baseLinkID = sel.substring(3,sel.length);
	cStringOffset = baseLinkID.length;
	resetContentThemes();
	document.getElementById(sel).className = "hotF";
	document.images["ap"+baseLinkID].src = image_dir+"item_arrow_down.gif";
        for(i=0;i<xx.length;i++) {
		  document.getElementById(xx[i]).style.display = ("af"+baseLinkID == xx[i]) ? 'block':'none';
		  //this.focus();
        }
	if(xx.length>=10) {cStringOffset=2;}  // for sel id's greater than 9
	if(isSafari) {expires=exm;}  // safari doesn't clean out cookies w/out expirations
	document.cookie = "sel=" +baseLinkID+"; expires="+expires+";";
}

function setThemeLayout(http_loc,numTopLinks) {
	
	if(numTopLinks>0){
		var ct = readLastCookie();
		doLinkStructure(numTopLinks);
		
	if(ct.length == cStringOffset) {  // lousy check for our digit value 
		dock('sel'+ct);
	} else {
		if(xx2!=null) {
			var targetArrow = xx2[0];
				document.getElementById('sel1').className = 'hotF';
				document.images[targetArrow].src = image_dir+'item_arrow_down.gif';
		} else { 
			return false; 
		}			
				
	}
		
	} else {
		// null
		
	}
	
	switch(http_loc) {
		case 1:
		    swap('about','sub_nav_about_on');
			break;
		case 2:
			swap('community','sub_nav_community_on');
			break;
		case 3:
			swap('events','sub_nav_events_on');
			break;
		case 4:
			swap('opportunities','sub_nav_opportunities_on');
			break;
		case 5:
			swap('projects','sub_nav_projects_on');
			break;
	}
		
	themeSelection = http_loc;
}



function doLinkStructure(numLinks) {
	fillByTarget(numLinks);	
		xx = af;
		xx2 = ap;
		xx3 = sel;
}

function fillByTarget(numLinks) {
	for(i=1;i<=numLinks;i++) {
		sel[i-1] = "sel"+i;ap[i-1] = "ap"+i;af[i-1] = "af"+i;
	}
}

function resetContentThemes() {
	
	for(i=0;i<xx2.length;i++) {
		document.images[xx2[i]].src = image_dir+"item_arrow.gif";
	}
				
	for(i=0;i<xx3.length;i++) {
		document.getElementById(xx3[i]).className= "hot";
	}

}

function swap(imgName,imgObj,theme,layer) {
	
   if ((document.images) && (theme!=themeSelection)) {
       document.images[imgName].src = eval(imgObj+".src");
    }
}

function readLastCookie()
{
	// cookie hack
	var cookieList = document.cookie.split(';');
	var num = cookieList.length;
	if(isSafari) {cookieList = cookieList.reverse();}  // last cookie first
	var cookieItem = cookieList[num-1];

	if(num) {
		var vpos = cookieItem.indexOf("=");
		if (cookieItem.charAt(0)=='') cookieItem = cookieItem.substring(1,cookieItem.length);
			return cookieItem.substring(vpos+1,cookieItem.length);
	}
	else {
		return null;
	}
}

// end
