// JavaScript Document

showbar=0;

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

function highlightPage() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("navigation")) return false;
  var nav = document.getElementById("navigation");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    var currenturl = window.location.href;
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "here";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
    }
  }
}

//addLoadEvent(highlightPage);

function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
 /* if (!elem.style.top) {
    elem.style.top = "0px";
  }*/
  var xpos = parseInt(elem.style.left);
 // var ypos = parseInt(elem.style.top);
  if (xpos == final_x /*&& ypos == final_y*/) {
	if(showbar == 0){
		elem.style.display='none';
	  }
    return true;
  }
  
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
	
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
 /* if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }*/
  elem.style.display='inline';
  elem.style.left = xpos + "px";
 // elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}

function prepareSlideshow() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("secondarynav")) return false;
  var secondarynav = document.getElementById("secondarynav");
 var slideshow = document.createElement("div");
  slideshow.setAttribute("id","slideshow");
/*  var frame = document.createElement("img");
  frame.setAttribute("src","images/frame.gif");
  frame.setAttribute("alt","");
  frame.setAttribute("id","frame");
  slideshow.appendChild(frame);
*/  var preview = document.createElement("img");
  preview.setAttribute("src","/images/background-cylon.gif");
  preview.setAttribute("alt","a glimpse of what awaits you");
  preview.setAttribute("id","preview");
  slideshow.appendChild(preview);
  insertAfter(slideshow,secondarynav);
  var links = document.getElementsByTagName("a");
 // for (var i=0; i<links.length; i++) {
	//links[i].onmouseover  
    themouseover = function() {
		showbar=1;
      var destination = this.getAttribute("href");
	  if(this.className == 'navlink'){
		  if (destination.indexOf("about.cfm") != -1 ) {
			moveElement("preview",0,0,5);
		  }
		  if (destination.indexOf("work.cfm") != -1) {
			moveElement("preview",102,0,5);
		  }
		  if (destination.indexOf("clients.cfm") != -1) {
			moveElement("preview",206,0,5);
		  }
		  if (destination.indexOf("press.cfm") != -1) {
			moveElement("preview",321,0,5);
		  }
		  if (destination.indexOf("leadership.cfm") != -1) {
			moveElement("preview",468,0,5);
		  }
		}
    }
	
	document.getElementById('linkabo').onmouseover = themouseover;
	document.getElementById('linkwor').onmouseover = themouseover;
	document.getElementById('linkcli').onmouseover = themouseover;
	document.getElementById('linknew').onmouseover = themouseover;
	document.getElementById('linklea').onmouseover = themouseover;
	
	themouseout = function() {
      var destination = this.getAttribute("href");
	  if(this.className == 'navlink'){
		  if (destination.indexOf("about.cfm") != -1 ) {
			moveElement("preview",0,0,5);
		  }
		  if (destination.indexOf("work.cfm") != -1) {
			moveElement("preview",102,0,5);
		  }
		  if (destination.indexOf("clients.cfm") != -1) {
			moveElement("preview",206,0,5);
		  }
		  if (destination.indexOf("press.cfm") != -1) {
			moveElement("preview",321,0,5);
		  }
		  if (destination.indexOf("leadership.cfm") != -1) {
			moveElement("preview",468,0,5);
		  }
		}
		showbar=0;
		//moveElement("preview",-100,0,0);
		document.getElementById("preview").style.display='none';
    }
	
	document.getElementById('linkabo').onmouseout = themouseout;
	document.getElementById('linkwor').onmouseout = themouseout;
	document.getElementById('linkcli').onmouseout = themouseout;
	document.getElementById('linknew').onmouseout = themouseout;
	document.getElementById('linklea').onmouseout = themouseout;
	
  //}
}

//addLoadEvent(prepareSlideshow);