var ids=new Array();

function init() {
	if (document.getElementById) {
		var tids = document.getElementsByTagName('div');
		for (i=0;i<tids.length;i++) {
			if (tids[i].className=="question")
				ids[ids.length]=tids[i];
			else if (tids[i].className=="flash")
				tids[i].onmouseover=flash;
			else if (tids[i].className=="echo")
				tids[i].onmouseover=move;
			else if (tids[i].className=="end")
				tids[i].onmouseup=end;
			else if (tids[i].id=="cyb")
				tids[i].onmouseup=cyb;
			else if (tids[i].id=="taisteli") {
				tids[i].onmouseover=tai;
				tids[i].onmouseout=notai;
			}
			else if (tids[i].id=="parantui") {
				tids[i].onmouseover=par;
				tids[i].onmouseout=nopar;
			}
			else if (tids[i].id=="aivokas") {
				tids[i].onmouseover=aiv;
				tids[i].onmouseout=noaiv;
			}
			else if (tids[i].id=="elinvuo") {
				tids[i].onmouseover=eli;
				tids[i].onmouseout=noeli;
			}
			else if (tids[i].className=="dark") {
				tids[i].onmouseup=ness;
				tids[i].onmouseover=dark;
			}
		}
		for(i=0;i<ids.length;i++)
			ids[i].onmouseup=setstate;
	}
	if (document.images) {
		pic1 = new Image(650,450); 
		pic1.src = "img/xriver.gif";
		shunt = new Image(225, 343);
		shunt.src = "img/shunt.gif";
	}
	document.onmousedown=falsey;
}

function cyb() {
	top.location="http://www.cyberartsweb.org/cpace/cyborg/ellis6.html";
}

function falsey() {
	return false;
}

function fixbg() {
	var bg = document.getElementById("bgimg");
	bg.style.backgroundPosition = "inherit";
	if (bg.style.backgroundRepeat == "repeat")
		bg.style.backgroundRepeat = "no-repeat";
	else
		bg.style.backgroundRepeat = "repeat";
}

function tai() {
	var number = Math.round(Math.random()*350);
	var tais = document.getElementById("tai");
	tais.style.posTop = 450 - number;
	tais.style.posLeft = 50;
	tais.style.display = "block";
}

function notai() {
	var tais = document.getElementById("tai");
	tais.style.display = "none";	
	fixbg();
}

function par() {
	var number = Math.round(Math.random()*350);
	var para = document.getElementById("par");
	para.style.posTop = 450 - number;
	para.style.posLeft = 490;
	para.style.display = "block";
}

function nopar() {
	var para = document.getElementById("par");
	para.style.display = "none";	
	fixbg();
}

function aiv() {
	var number = Math.round(Math.random()*350);
	var aivo = document.getElementById("aiv");
	aivo.style.posTop = 400;
	aivo.style.posLeft = number + 50;
	aivo.style.display = "block";
}

function noaiv() {
	var aivo = document.getElementById("aiv");
	aivo.style.display = "none";	
	fixbg();
}

function eli() {
	var number = Math.round(Math.random()*350);
	var elin = document.getElementById("eli");
	elin.style.posTop = 500;
	elin.style.posLeft = number + 50;
	elin.style.display = "block";
}

function noeli() {
	var elin = document.getElementById("eli");
	elin.style.display = "none";	
	fixbg();
}

function end() {
	var bg = document.getElementById("bgimg");
	bg.style.backgroundColor = "#000000";
//	bg.style.backgroundImage="url(img/shunt.gif)";
	var grid = document.getElementById("grid");
	grid.style.backgroundColor = "#FFFFFF";
	grid.style.background = "url(img/shunt.gif) no-repeat center";
	var box = document.getElementById("box");
	box.style.display = "none";
	var finalTxt = document.getElementById("final");
	finalTxt.style.display = "block";
	setTimeout("cyborg()",10000);
/*	box.style.backgroundColor = "#000000"; */
}

function cyborg() {
	if (document.getElementById) {
		var tids = document.getElementsByTagName('div');
		for (i=0;i<tids.length;i++) {
			if (tids[i].className=="eng")
				tids[i].style.display = "none";
		}
	}
	document.body.bgColor="#FFFFFF";
	var finalTxt = document.getElementById("final");
	finalTxt.style.display = "none";
	var bg = document.getElementById("bgimg");
	bg.style.backgroundColor = "#FFFFFF";
	bg.style.backgroundImage = "none";
	var borg = document.getElementById("cyborg");
	borg.style.display = "block";
	var medi = document.getElementById("mediport");
	medi.style.display = "block";
	var medi = document.getElementById("brain");
	medi.style.display = "block";
}

function move() {
/*	alert(topecho + ", " + botecho); */
	var topecho = document.getElementById("topecho");
	var botecho = document.getElementById("botecho");
	topecho.style.display = "block";
	botecho.style.display = "block";
	topecho.style.posTop = 40;
	botecho.style.posTop = 550;
	this.onmouseover="";
	this.style.fontStyle="normal";
	moveEcho(50,550);
}

function moveEcho(start, finish) {
	var topecho = document.getElementById("topecho");
	var botecho = document.getElementById("botecho");
	if (start < finish) {
		topecho.style.posLeft = (start += 5);
		topecho.style.posTop = topecho.style.posTop - (start % 10)/5;
		botecho.style.posRight = (start);
		botecho.style.posTop = botecho.style.posTop + (start % 10)/5;
		setTimeout('moveEcho(' + start + ',' + finish + ')', 100);
	} else {
		topecho.style.display = "none";
		botecho.style.display = "none";
		var echo = document.getElementById("echo");
		echo.onmouseover=move;
		echo.style.fontStyle="italic";
	}
}

function flash() {
	var bg = document.getElementById("bgimg");
	bg.style.backgroundImage="url(img/xriver.gif)";
	setTimeout("revert()",500);
}

function dark() {
	this.style.fontStyle="normal";
/*	this.style.verticalAlign="middle"; */
	document.body.bgColor="#000000";
}

function ness() {
	this.style.textTransform="none";
	this.style.fontSize = "100%";
	document.getElementById("ness").style.fontSize = "100%";
	var lit = document.getElementById("light");
	lit.style.display="inline";
}

function revert() {
	var bg = document.getElementById("bgimg");
	bg.style.backgroundImage="url(img/river.gif)";
}

function showgrid() {
	box = document.getElementById("grid");
	/*alert(box+" "+box.style+" "+box.style.getPropertyValue('backgroundImage')+" "+box.id);*/
	/*box.style.background="url(../img/mask.gif) repeat top left";*/
	box.style.backgroundImage="url(img/mask.png)";
	box.style.backgroundRepeat="repeat";
}

function setstate() {
for (i=0;i<ids.length;i++) {
	if (ids[i]==this) {
		this.style.display="none";
		showgrid();
		var d=this.parentNode.getElementsByTagName('div')[1];
		if (d.style.display=="inline")
			d.style.display="none";
		else d.style.display="inline";
	}}
}

function expandall() {
	if (document.getElementById) {
		for (i=0;i<ids.length;i++)
			ids[i].parentNode.getElementsByTagName('div')[1].style.display = "inline";
}}

function collapseall() {
	if (document.getElementById) {
		for(i=0;i<ids.length;i++)
			ids[i].parentNode.getElementsByTagName('div')[1].style.display = "none";
}}

window.onload = init;