/*
 * $Id: homescript.js,v 1.0 2004/10/11 16:10:25 Owner Exp Owner $
 * $Log: homescript.js,v $
 * Revision 1.0  2004/10/11 16:10:25  Owner
 * Initial revision
 *
 */
/*
 * Debugging aid
 */
var DebugStr = "";

/*
 * Triangle label highlighting
 */
var trmap = new Array();
var trtimeid;
var trshow = -1;

function coords2array(cs) {
	var ca = cs.match(/\d+/g);
	for (var i = 0; i < ca.length; i++) {
		ca[i] = parseInt(ca[i]);
	}
	return ca;
}

function filltrmap(trid) {
	trel = document.getElementById(trid);
	var areas = trel.getElementsByTagName("AREA");
	var rnum = 0;
	if (areas) {
		for (var i = 0; i < areas.length; i++) {
			if ((areas[i].shape == "RECT") ||
			    (areas[i].shape == "rect")) {
				trmap[rnum++] = coords2array(areas[i].coords);
			}
		}
	}
}

function shthexpanded(t, r, b, l) {
	var thstyle=document.getElementById("th").style;
	thstyle.clip=
	"rect(" + t + "px " + r + "px " + b + "px " + l + "px)";
	thstyle.visibility='visible';
}

function shth(tri) {
	if (tri >= trmap.length) return;
	var coords = trmap[tri];
	if (!coords) return;
	shthexpanded(coords[1], coords[2], coords[3], coords[0]);
}

function hideth() {
	var thstyle=document.getElementById("th").style;
	thstyle.visibility='hidden';
}

function stopth() {
	hideth();
	clearTimeout(trtimeid);
	trshow = -1;
}

function animatetr() {
	if (++trshow < trmap.length) {
		shth(trshow);
		trtimeid = setTimeout("animatetr()", 2000);
	} else {
		stopth();
	}
}

/*
 * Bottom section position adjustment.
 * Might want to make bottomsection invisible until onload calls putbottom.
 */
function putbottom() {
	var bottomobj = document.getElementById("bottomsection");
	var leftheight = xHeight("leftnavcontent") + 60;
	var triangleht = xHeight("trcontent");
	var sidebarht  = xHeight("sidebarcontent");

	var maxht = Math.max(leftheight, Math.max(triangleht, sidebarht))
		+ 30;

	xHeight("leftnav", maxht);
	xHeight("tr", maxht);
	xHeight("sidebar", maxht);

	bottomobj.style.visibility = "visible";
}

/*
 * Select and write the quote of the day
 */
function getquote(num, source) {
	var listelem = document.getElementById(source);
	var len = listelem.childNodes.length;

	var bqarray = new Array();
	for (var i = 0; i < len; i++) {
		if (listelem.childNodes[i].nodeType == 1
		&&  listelem.childNodes[i].nodeName == "BLOCKQUOTE")
			  bqarray[bqarray.length] = listelem.childNodes[i];
	}

	num = bqarray.length ? num % bqarray.length : 0;

	return(bqarray[num]);
}

function gethead(source) {
	var listelem = document.getElementById(source);
	var len = listelem.childNodes.length;

	for (var i = 0; i < len; i++) {
		if (listelem.childNodes[i].nodeType == 1
		&&  listelem.childNodes[i].nodeName == "H1")
			  return(listelem.childNodes[i]);
	}
	return(null);
}

function movequote(num, newpstr, source) {
	var newp = document.getElementById(newpstr);
	if (!newp) return;
	var qobj = getquote(num, source);
	if (qobj && qobj.nodeType == 1) {
		var qhead = gethead(source);
		if (qhead) newp.appendChild(qhead);
		newp.appendChild(qobj);
	}
}

/*
 * Initialize all dynamic presentation.
 */
function init() {
	var dateobj = new Date();
	var today = (dateobj.valueOf()/86400000).toFixed(0);
	movequote(today, "sidebarcontent", "qlist");
	movequote(today, "sidebarcontent", "slist");
	putbottom();
	filltrmap("triangle");
	// animatetr();
	trtimeid = setTimeout("animatetr()", 2000);
	window.status = DebugStr;
}
