var timerID = 0;
var shownav = true;
var xvisx = "hidden";

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseLocation;

// this is unbe- way u cant get the int of a div without doing this
// to make it work on all browers is beyond me! unreal messing around.
function intersects(x, y, ss) {
  // alert("nav array: " + document.getElementById("scrollNav").style);
  // yes this hackz the "zone" div. we need to offset that in its own style.
  var offleft = 0; // parseInt(document.getElementById("scrollNav").style.left.replace("px", ""));
  var offtop = 0; // arseInt(document.getElementById("scrollNav").style.top.replace("px", ""));

  var top = parseInt(ss.top.replace("px", "")) + offtop;
  var left = parseInt(ss.left.replace("px", "")) + offleft;
  var width = parseInt(ss.width.replace("px", ""));
  var height = parseInt(ss.height.replace("px", ""));

  if((x < (left + width)) && (x > left) && (y < (top + height)) && (y > top)) {
    return true;
  }

  return false;
}


// bound to be an arse- and as alway was. returns the mouse loc- all browsers.
function getMouseLocation(e) {
  var mouseLocation = new Array(2);

  if (IE) { // grab the x-y pos.s if browser is IE
  mouseLocation[0] = event.clientX + document.body.scrollLeft;
  mouseLocation[1] = event.clientY + document.body.scrollTop;
} else {  // grab the x-y pos.s if browser is NS
mouseLocation[0] = e.pageX;
mouseLocation[1] = e.pageY;
}

if (mouseLocation[0] < 0){mouseLocation[0] = 0;}
if (mouseLocation[1] < 0){mouseLocation[1] = 0;}

if (isNaN(mouseLocation[0])){mouseLocation[0] = 0;}
if (isNaN(mouseLocation[1])){mouseLocation[1] = 0;}

if(checkNavDivs(mouseLocation)) {
  if(!shownav) setVisable("visible"); shownav = true; timerID = 0; xvisx = "visible";
} else {
  if(true) {
    if(shownav) setVisable("hidden"); shownav = false; timerID = 0; xvisx = "hidden";
  }
}



return true;
}

function setVisable(vis) {
	var nav = getElementsByClass("nav", null, "div");
	var eles = new Array();
	var elecount = 0;

	for(i = 0; i < nav.length; i++) {
                var visx = nav[i].style.visibility + "";
		if(visx != vis) {
			eles[elecount] = nav[i];
			elecount ++;
		}
	}

//	alert("tick tock:  " + vis);

        if(elecount > 0){
          var randomnumber = (Math.floor(Math.random()*eles.length));
          eles[randomnumber].style.visibility = xvisx;
          var timestring= 'setVisable("'+vis+'")';
          timerID = window.setTimeout(timestring, 100);
        }
}

// [99] runs over all the divs looking to see if the mouse hit.
function checkNavDivs(mouseLocation) {
  var nav = getElementsByClass("scroll", null, "div");
  for(i = 0; i < nav.length; i++) {
    if(intersects(mouseLocation[0], mouseLocation[1], document.getElementById("scroll").style)) {
      return true;
    }
  }

  return false;
}

// hides and shows the nav.
function switchNavVisable(flag) {
  var nav = getElementsByClass("nav", null, "div");

  for(i = 0; i < nav.length; i++) {
    document.getElementById(nav[i].id).style.visibility = flag;
  }

  return false;
}

// why we cant get an element by class i dont no!
function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();

  if ( node == null ) node = document;
  if ( tag == null ) tag = '*';

  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// EMAIL ENCRYPT
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++

function ch1(x){var yy=2;var z=0;var xx="";for(var y=0;y<x.length;y++){z=x.charCodeAt(y);xx+=String.fromCharCode(z-yy);}return xx;}function Kontakt(x){location.href=ch1(x);}
