function show() {
	TD=this;
	do {
		TD=TD.parentNode;
	} while (TD.nodeName!="TD");

	UL=getFirstChildNode(document.getElementById("dropdown").cells[TD.cellIndex]);
	if (!UL) return false;
	UL.style.display="block";
	return true;
}

function hide() {
	UL=getFirstChildNode(document.getElementById("dropdown").cells[this.parentNode.cellIndex]);
	if (!UL) return false;
	// TODO: insert small time-out (~100ms)
	UL.style.display="none";
	return true;
}

function hover() {
	var links=document.getElementById("links");
	var dropdown=document.getElementById("dropdown");
	// mouseevents of links
	for (i=0;i<links.cells.length;i++) {
		A=links.cells[i].firstChild;
		if (A.nodeName!="A") continue;
		A.onmouseover=show;
		A.onmouseout=hide;
	}
	// mouseevents of dropdown
	for (i=0;i<dropdown.cells.length;i++) {
		UL=getFirstChildNode(dropdown.cells[i]);
		if (!UL) continue;
		UL.onmouseover=show;
		UL.onmouseout=hide;

		// change bg for UL's LIs
		LI=UL.firstChild;
		do {
			if (LI) {
				LI.onmouseover = function() {this.style.backgroundColor="white"};
				LI.onmouseout =  function() {this.style.backgroundColor=""};
			}
			LI=LI.nextSibling;
		} while (LI);
	}
}

function getFirstChildNode(TD) {
	for (var i=0; i<TD.childNodes.length;i++) {
		CN=TD.childNodes[i];
		if (CN.nodeType!=1) {
			continue;
		}
		return CN;
	}
	return false;
}

function resizeText() {
	var pictures=document.getElementById("pictures");
	var text=document.getElementById("text");

	if (!pictures) {
		text.style.width="70%";
	} else {
		var pic_w=pictures.scrollWidth;
		var pic_maxW=300;
		if (pic_w<pic_maxW)
			text.style.width="70%";
		else {
			text.style.paddingRight="30%";
		}
	}


	return true;
}

var IE=0;
var GECKO=0;
function getBrowser() {
	if (navigator.userAgent.match("Gecko")) {
		GECKO=1;
		return;
	} else if (navigator.userAgent.match("IE")) {
		IE=1;
		return;
	}
}

function main() {
	getBrowser();
	resizeText();
	hover();
}
window.onload=main;

