function setImage(a_iX, a_iY, a_sImg, a_sURL, a_sStatus, a_sClass) {
	if (a_sImg == null)   { a_sImg = "/images/square.gif"; }
	if (a_sClass == null) { a_sClass = ""; }
	
	oImg           = document.createElement("IMG");
	oImg.id        = "img_" + a_iX + "_" + a_iY;
	oImg.className = a_sClass;
	oImg.src       = a_sImg;
	oImg.alt       = 
	oImg.title     = (a_sStatus == null ? "" : a_sStatus);
	
	oImg.style.position = "absolute";
	oImg.style.left = (16 + (a_iX * 12)) + "px";
	oImg.style.top  = ( 8 + (a_iY * 12)) + "px";
	
	if (a_sURL == null) {
		document.body.appendChild(oImg);
	} else {
		oA           = document.createElement("A");
		oA.id        = "a_" + a_iX + "_" + a_iY;
		oA.className = a_sClass;
		oA.href      = a_sURL;
		oA.appendChild(oImg);
		if (a_sStatus != null) {
			oA.title       = a_sStatus; 
			oA.onmouseover = Function("window.status = \"" + a_sStatus + "\"; return true;");
			oA.onmouseout  = Function("window.status = \"\"; return true;");
		}
		document.body.appendChild(oA);
	}
}

function delImage(a_iX, a_iY) {
	if (oE = document.getElementById("a_" + a_iX + "_" + a_iY)) {
		document.body.removeChild(oE);
	}
	if (oE = document.getElementById("img_" + a_iX + "_" + a_iY)) {
		document.body.removeChild(oE);
	}
}

function setItem(a_iX, a_iY, a_sImg, a_sText, a_sURL, a_sTarget) {
	setImage(a_iX, a_iY, a_sImg, null, null, null);
	
	var oDiv = document.createElement("DIV");	
	oDiv.id             = "item_" + a_iX + "_" + a_iY;
	oDiv.className      = "category";
	oDiv.style.position = "absolute";
	oDiv.style.left     = (16 + ((a_iX + 1) * 12)) + "px";
	oDiv.style.top      = ( 6 + ( a_iY      * 12)) + "px";

	oA = document.createElement("A");
	oA.href         = a_sURL;
	if (a_sTarget != null) { oA.target = a_sTarget; }
	oA.title        = a_sText;
	oA.onmouseover  = Function("window.status = \"" + a_sText + "\"; return true;");
	oA.onmouseout   = Function("window.status = \"\"; return true;");
	oA.appendChild(document.createTextNode(a_sText));
	
	oDiv.appendChild(oA);	
	document.body.appendChild(oDiv);
	
	return oDiv;
}

function setItemText(a_iX, a_iY, a_sText) {
	var oDiv = document.getElementById("item_" + a_iX + "_" + a_iY);
	if (oDiv) {
		oDiv.childNodes[0].childNodes[0].nodeValue = a_sText;
	}
}

function setInnerHTML(a_sId, a_sHTML) {
	if (document.getElementById) {
		document.getElementById(a_sId).innerHTML = a_sHTML;
	} else if (document.layers) {
		with (document.layers[a_sId].document) {
			open();
			write(a_sHTML);
			close();
		}
	} else {
		return false;
	}
	return true;
}


function initIntro() {
	setImage(45, 20, "/images/online.gif", null, "PACT Online", null);
	setImage(62, 20, "/images/enter-grey.gif", "?go=enter", "Enter", null);
	
	oPreload = new Image();
	oPreload.src = "/images/square.gif";
	oPreload.src = "/images/enter-orange.gif";
	setTimeout("animateSquares()", iInitTimeOut);
}

function animateSquares() {
	if (bClear) {
		iLength = document.body.childNodes.length - 1;
		for (i = iLength; i >= 0; i--) {
			if (document.body.childNodes[i].className == "anim") { 
				document.body.removeChild(document.body.childNodes[i]); 
			}
		}		

		delImage(62, 20);
		setImage(62, 20, "/images/enter-grey.gif", "?go=enter", "Enter", null);

		bClear = false;
	}

	setImage(aSquares[iLastIndex] + iLastSquare, 20, null, null, null, "anim");
	
	iLastSquare++;
	if (iLastSquare >= aSquares[iLastIndex + 1]) {
		iLastIndex += 2;
		iLastSquare = 0;
	}
	if (iLastIndex >= aSquares.length) {
		iLastIndex  = 0;
		iLastSquare = 0;
		bClear      = true;
		
		iIntroCounter++;
		if (iIntroCounter < iIntroRepeat) setTimeout("animateEnter()", iTimeOut);
		else document.location = "index.php?go=enter";
	} else {
		setTimeout("animateSquares()", iTimeOut);
	}
}

function animateEnter() {
	delImage(62, 20);
	setImage(62, 20, "/images/enter-orange.gif", "?go=enter", "Enter", null);
	setTimeout("animateSquares()", iRepTimeOut);
}


//==== menu functions ====//
//========================//
function buildMenu(a_iID) {
	aMenu  = aMenus[a_iID];
	if (aMenu[1] != "") {
		iPos   = aMenu[0];
		aItems = aMenu[1].split("|");
		
		oUL = document.createElement("UL");
		oUL.id         = "menu_" + a_iID;
		oUL.className  = "category";
		oUL.style.left = (16 + (iPos * 12)) + "px";
		
		for (i = 0; i < aItems.length; i++) {
			aItem = aItems[i].split(";");		

			oA = document.createElement("A");
			oA.id          = "menu_a_" + aItem[0];
			oA.className   = "subcategory menu_arrow";
			oA.href        = "javascript:clickSubMenu(" + aItem[0] + ")";
			oA.iSubMenuId  = aItem[0];
			oA.title			 = aItem[1];
			oA.onmouseover = function() { window.status = this.title; return true; };
			oA.onmouseout  = function() { window.status = ""; return true; };
			oA.appendChild(document.createTextNode(aItem[1]));
			oLI = document.createElement("LI");
			oLI.appendChild(oA);
			oUL.appendChild(oLI);
		}
		document.body.appendChild(oUL);
	}	
}

var iPrevMenu = null;
function clickMenu(a_iID) {
	alert(a_iID);
	if (oE = document.getElementById("menu_" + iPrevMenu)) {
		//---- hide previous menu ----//
		oE.style.visibility = "hidden";
		clickSubMenu(null);
	}
	
	if (a_iID != iPrevMenu) {
		if (oE = document.getElementById("menu_" + a_iID)) {
			//---- show existing ----//
			oE.style.visibility = "visible";
		} else {
			//---- build new ----//
			buildMenu(a_iID);
		}
		iPrevMenu = a_iID;
	} else {
		iPrevMenu = null;
	}	
}

function buildSubMenu(a_iID) {
	aSubMenu  = aSubMenus[a_iID];
	if (aSubMenu[1] != "") {
		iPos   = aSubMenu[0];
		aItems = aSubMenu[1].split("|");
		
		oUL = document.createElement("UL");
		oUL.id         = "submenu_" + a_iID;
		oUL.className  = "subcategory";
		oParent        = document.getElementById("menu_a_" + a_iID);		
		oUL.style.left = (16 + (iPos * 12) - 13 + oParent.offsetWidth) + "px";
		oUL.style.top  = (140 + 7 + oParent.offsetTop) + "px";
		
		for (i = 0; i < aItems.length; i++) {
			aItem = aItems[i].split(";");		

			oA = document.createElement("A");
			oA.className   = "object";
			oA.href        = "/?go=object&objectid=" + aItem[0];
			oA.onmouseover = Function("window.status = \"" + aItem[1] + "\"; return true;");
			oA.onmouseout  = Function("window.status = \"\"; return true;");
			oA.appendChild(document.createTextNode(aItem[1]));
			oLI = document.createElement("LI");
			oLI.appendChild(oA);
			oUL.appendChild(oLI);
		}
		document.body.appendChild(oUL);
	}	
}

var iPrevSubMenu = null;
function clickSubMenu(a_iID, a_oA) {
	if (oE = document.getElementById("submenu_" + iPrevSubMenu)) {
		//---- hide previous menu ----//
		oE.style.visibility = "hidden";
	}
	
	if (a_iID != iPrevSubMenu) {
		if (a_iID != null) {
			if (oE = document.getElementById("submenu_" + a_iID)) {
				//---- show existing ----//
				oE.style.visibility = "visible";
			} else {
				//---- build new ----//
				buildSubMenu(a_iID);
			}
		}
		iPrevSubMenu = a_iID;
	} else {
		iPrevSubMenu = null;
	}
}
