/* 
matrix.js

Copyright 2009 Lifespaces, Inc., all rights reserved. 

Any copying or redistribution of any part of this document  
is strictly prohibited by law unless explicitly 
permitted by Lifespaces, Inc. 
*/

var d = null;
var e = null;
var i = 0.0;
var o = 0.0;
var oo= 0.0;
var od= null;
var a = 0;
var ad=null;
var barin_top = false;
var bin_t = 2;
var fo_t = 0;
var imgs = new Array("ixi","ixii","ixiii","iixi","iixii","iixiii","iiixi","iiixii","iiixiii");
var images = new Array("/img/i-meeting.png","/img/i-apple.png","/img/i-theater.png","/img/i-media.png","/img/i-video-conf.png","/img/i-hidden.png","/img/i-training.png","/img/i-award-winning.png","/img/i-boardroom.png");
var links = new Array("/meeting-room.php","/apple-integration.php","/home-theater.php","/media-room.php","/video-conferencing.php","/hidden-installation.php","/support.php","/award-winning.php","/boardrooms.php");
var exempt = null;
var interv_t = 300;
var f_t = 1.0;

function matrix(time,tt){

fo_t = time;
bin_t = 2;
exempt = document.getElementById("");

var over=document.createElement("div");
over.setAttribute("id","over");
over.setAttribute("class","over");
if((navigator.appName=="Netscape" && navigator.vendor == "Apple Computer, Inc.") || navigator.appName=="Microsoft Internet Explorer") over.style.top = 203+"px";
if(navigator.appName=="Microsoft Internet Explorer") over.style.filter = "alpha(opacity=100)";
else over.style.opacity=1;
document.getElementById("iicoli").appendChild(over);

if(navigator.appName != "Microsoft Internet Explorer") // cripple the already crippled
bars();

oo=1.0;
od=document.getElementById("over");

if(navigator.appName=="Microsoft Internet Explorer") fo_t = 20;
document.getElementById("matrix").style.backgroundColor = "black";

// sethacks();
fadeout(); 
sweep(true);
// switcher();

return;
}

function fadeout(){
if(oo > 0.0) {
oo -= 0.01;
if(navigator.appName=="Microsoft Internet Explorer") od.style.filter = "alpha(opacity="+oo*100+")";
else od.style.opacity = oo;
setTimeout(fadeout,fo_t);
}
else return document.getElementById("iicoli").removeChild(document.getElementById("over"));
}

function check_mouse() { /*
	if(exempt == null) sweep(false);
	else for(var i = 0; i <= imgs.length; i++) {
		if(imgs[i] != exempt.getAttribute("name")) { 
			if(navigator.appName=="Microsoft Internet Explorer") od.style.filter = "alpha(opacity="+50+")";
			else document.getElementById(imgs[i]).style.opacity = 0.5;
		}
	} */
}

function sethacks() {
	var ayes = document.getElementsByTagName("a");
	for(var i = 0; i <= ayes.length; i++) {
		if(ayes[i].childNodes[0].id) ayes[i].onMouseOut = out(ayes[i].childNodes[0].id);
		else if(ayes[i].childNodes[0].getAttribute) ayes[i].onMouseOut = out(ayes[i].childNodes[0].getAttribute("id"));
		else return;
	}
}

function bars(){
var vr = document.createElement("div");
var hr = document.createElement("div");
var vrt = document.createElement("div");
var hrt = document.createElement("div");

vr.setAttribute("id","vr");
hr.setAttribute("id","hr");
vrt.setAttribute("id","vrt");
hrt.setAttribute("id","hrt");

var m=document.getElementById("matrix");

m.appendChild(hr);
hr=document.getElementById("hr");
hrin();

m.appendChild(hrt);
hrt=document.getElementById("hrt");
hrtin();

barin_top = true;

m.appendChild(vr);
vr=document.getElementById("vr");
vrin();

m.appendChild(vrt);
vrt=document.getElementById("vrt");
vrtin();
return;
}

var barin_a = 0;

function hrin(){
if(barin_a != 100){
barin_a++;
document.getElementById("hr").style.top = barin_a+"px";
setTimeout(hrin,bin_t);
}
else {
return;
}
}

var barin_b = 0;

function hrtin(){
if(barin_b != 200){
barin_b++;
document.getElementById("hrt").style.top = barin_b+"px";
setTimeout(hrtin,bin_t);
}
else {
return;
}
}

var barin_c = 0;

function vrin(){
if(barin_c != 183){
barin_c++;
document.getElementById("vr").style.left = barin_c+"px";
setTimeout(vrin,bin_t);
}
else {
return;
}
}

var barin_d = 0;

function vrtin(){
if(barin_d != 365){
barin_d++;
document.getElementById("vrt").style.left = barin_d+"px";
setTimeout(vrtin,bin_t);
}
else {
return;
}
}

function followup(suspect) { /*
	if((exempt == null) || (exempt.getAttribute("name") != suspect.getAttribute("id"))) {
		if(navigator.appName=="Microsoft Internet Explorer") suspect.style.filter = "alpha(opacity="+50+")";
		else suspect.style.opacity = 0.5;
	}
	else setTimeout("followup("+suspect+")",20); */
}

function hover(id){
d=document.getElementById(id);
exempt = d;
exempt.setAttribute("name",id);
i = 0.5;
opac();
check_mouse();
i = 0.0;
setTimeout("followup("+d+")",20);
}

function out(id){
e = document.getElementById(id);
o = 1.0;
// deopac();
exempt = null;
// check_mouse();
}

function deopac(){
if(o>=0.6){
o -= 0.1;
if(navigator.appName=="Microsoft Internet Explorer") e.style.filter = "alpha(opacity="+o*100+")";
else e.style.opacity = o;
setTimeout(deopac,30);
}
else return;
}

function opac(){
if(i<=1.0){
i += 0.1;
if(navigator.appName=="Microsoft Internet Explorer") d.style.filter = "alpha(opacity="+i*100+")";
else d.style.opacity = i;
setTimeout(opac,40);
}
else return brighten_all();
}

function brighten_all() { 
		for(var i = 0; i <= imgs.length; i++) { 
			if(navigator.appName=="Microsoft Internet Explorer") od.style.filter = "alpha(opacity="+100+")";
			else document.getElementById(imgs[i]).style.opacity = 1.0; 
		}
}

function sweep(again) {}

function clearall() { /*
	exempt = null;
	for(var i = 0; i <= imgs.length; i++) {
			if(navigator.appName=="Microsoft Internet Explorer") od.style.filter = "alpha(opacity="+50+")";
			else document.getElementById(imgs[i]).style.opacity = 0.5;
	} */
}

function switcher() {
	var newid = ( Math.floor ( Math.random ( ) * imgs.length + 1 ) ); // start it off at random, else errors arise
	
	while(true) { // breaks and continues below to control flow
		if(exempt != null && imgs[newid] == exempt.getAttribute("id")) { // don't switch an image the user is hovering over
			newid = ( Math.floor ( Math.random ( ) * imgs.length + 1 ) ); // reset newid to a new random value
			continue; // starts while loop over again
		}
		else { // newid = the id (string) of an image it is safe to swap out
			// check to see if the randomly selected image is already in use somewhere in the grid
			for(var i = 0; i <= imgs.length; i++) { // loop through them all
				if(document.getElementById(imgs[i]).src != images[newid] && i < imgs.length) continue; // keep going...
				else if(document.getElementById(imgs[i]).src != images[newid] && i == imgs.length) { // no match
					f_t = document.getElementById(imgs[i]).style.opacity; // we change this so much...
					fadeout(imgs[i]); // fade it to white so we can change it
					document.getElementById(imgs[i]).src = images[newid]; // set new image source while faded
					document.getElementById(imgs[i]).parentNode.setAttribute("href",ayes[newid]); // change link target of <a>
					fadein(imgs[i]); // fade it back in
					break; // break out of for loop
				}
				else switcher(); // hope this won't burst stacks; dirty hack to restart entirely
			}
			break; // break out of while loop, we're done.
		}
	}
	
	setTimeout(switcher,5000); // switch one every 5ish seconds (ish caused by execution/looping latency)
}
/*
function fadeout(id){
	idd = document.getElementById(id);
	if(f_t > 0.0) {
	f_t -= 0.1;
	if(navigator.appName == "Microsoft Internet Explorer") idd.style.filter = "alpha(opacity="+f_t*100+")";
	else idd.style.opacity = f_t;
	setTimeout(fadeout,interv_t);
	}
	else return 1;
}

function fadein(id){
	idd = document.getElementById(id);
	if(f_t < 1.0) {
	f_t += 0.1;
	if(navigator.appName == "Microsoft Internet Explorer") idd.style.filter = "alpha(opacity="+f_t*100+")";
	else idd.style.opacity = f_t;
	setTimeout(fadein,interv_t);
	}
	else return 1;
} */

function lnk() {

}
