<!--
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

loaded = false;

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Image Swap

function preload(objname,imgsrc){
	eval(objname+' = new Image()');
	eval(objname+'.src = "'+imgsrc+'"');
}
function imgSwap(imgname,imgobj,div){
	if(document.layers && div != null){
		eval('document.'+div+'.document.images["'+imgname+'"].src = '+imgobj+'.src');
	}else{
		document.images[imgname].src = eval(imgobj+'.src');
	}
}

preload('i1_off', '/images/nav_mission_off.gif');
preload('i2_off', '/images/nav_products_off.gif');
preload('i3_off', '/images/nav_network_off.gif');
preload('i4_off', '/images/nav_contact_off.gif');

preload('i1_on', '/images/nav_mission_on.gif');
preload('i2_on', '/images/nav_products_on.gif');
preload('i3_on', '/images/nav_network_on.gif');
preload('i4_on', '/images/nav_contact_on.gif');

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Detect Constructor

Detect = function() {
	var agent = navigator.userAgent.toLowerCase(); 
	this._mac = agent.indexOf('mac') != -1;
	this._win = !this._mac;
	this._w3c = document.getElementById;
	this._iex = document.all;
	this._ns4 = document.layers;
}
Detect.prototype.getObj = function(name){
	if(this._w3c){
		return document.getElementById(name);
	}else if(this._iex){
		return document.all[name];
	}else if(this._ns4){
		return this.getObjNS4(document,name);
	}
}
Detect.prototype.getObjNS4 = function(obj, name){
	var d = obj.layers;
	var result,temp;
	for(var i=0; i<d.length; i++){
		if(d[i].id == name){
		 	result = d[i];
		}else if(d[i].layers.length){
			var temp = this.getObjNS4(d[i],name);
		}
		if(temp){
			result = temp;
		}
	}
	return result;
}
Detect.prototype.getStyle = function(obj){
	return (this._ns4) ? obj : obj.style;
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// MakeDiv Constructor --> inherit from Detect

MakeDiv = function(name){
	if(name){
		this._inherit = Detect; this._inherit(name);
		this._id  = name;
		this._el  = this.getObj(this._id);
		this._css = this.getStyle(this._el);
		this._obj = name+'Object'; eval(this._obj+'=this');
		this._timer = null;
		this._tweenRunning = false;
		return this;
	}
}
MakeDiv.prototype = new Detect();

MakeDiv.prototype.getLeft = function(){ // left position of the element
	return parseInt(this._css.left || 0);
}
MakeDiv.prototype.getTop = function(){ // top position of the element
	return parseInt(this._css.top || 0);
}
MakeDiv.prototype.getWidth = function(){ // width of the element
	if(this._ns4){
		 return this._el.document.width;
	}else{
		return this._el.offsetWidth;
	}
}	
MakeDiv.prototype.getHeight = function(){ // height of the element
	if(this._ns4){
		 return this._el.document.height;
	}else{
		return this._el.offsetHeight;
	}
}
MakeDiv.prototype.moveTo = function(x,y){ // move the element to a new position
	if(this._ns4){
		this._el.moveTo(x,y);
	}else{
		this._css.left = x;
		this._css.top  = y;
	}
}
MakeDiv.prototype.tweenTo = function(method, start, distance, time){  // time-based animation
	if(!this._tweenRunning){
		this._tweenTime = 0;
		var s = '['+start.toString()+']';
		var d = '['+distance.toString()+']';
		this._timer = setInterval(this._obj+'.tweenTo('+method+','+s+','+d+','+time+')', 100);
		this._tweenRunning = true;
	}
	if(++this._tweenTime > time){
		this.clearTween();
	}else{
		var x = method(this._tweenTime, start[0], distance[0], time);
		var y = method(this._tweenTime, start[1], distance[1], time);
		this.moveTo(x,y);
	}
}
MakeDiv.prototype.clearTween = function(){ // clear the tweenTo method
	clearInterval(this._timer);
	this._timer = null;
	this._tweenRunning = false;
}
easeOutQuad = function(t, b, c, d){
	t /= d;
	return -c * t*(t-2) + b;
}
easeOutExpo = function(t, b, c, d){
	return c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b;
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// MenuDiv Constructor --> inherit from MakeDiv

MenuDiv = function(name){
	if(name){
		this._inherit = MakeDiv; this._inherit(name);
		this._basex = this.getLeft();
		this._basey = this.getTop();
	}
}
MenuDiv.prototype = new MakeDiv();

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Menu Functions and Properties

menuLen  = 4; // Edit the number of top level menu links
curMenu  = 0;
subtimer = null;

function showMenu(num){
	if(loaded){

		curMenu = (curMenu==num) ? 0 : num;
		clearTimeout(subtimer);
		subtimer = null;
		if(curMenu != 0){
			var subHeight = eval('API.s'+num).getHeight();
			subtimer = setTimeout('showSub('+num+')', 500);
		}
		for(var i=1; i<=menuLen; i++){
			var ymove = (i<=num || curMenu==0) ? 0 : subHeight;
			var n = eval('API.n'+i);
			var s = eval('API.s'+i);
			var sx = n._basex;
			var sy = n.getTop();
			var dx = 0;
			var dy = (n._basey-n.getTop())+ymove;
			n.clearTween();
			n.tweenTo(easeOutExpo, [sx,sy], [dx,dy], 5);
			s.clearTween();
			s.moveTo(s._basex, s._basey);
			imgSwap('i'+i, 'i'+i+'_off', 'n'+i); // off
		}

	}
}
function showSub(num){
	var s = eval('API.s'+num);
	var sx = s.getLeft();
	var sy = s._basey;
	var dx = s.getWidth();
	var dy = 0;
	s.clearTween();
	s.tweenTo(easeOutQuad, [sx,sy], [dx,dy], 5);
	imgSwap('i'+num, 'i'+num+'_on', 'n'+num); // on
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Create an instance of the 'Detect' object.
// 'API' is also a place to put 'MakeDiv' and 'MenuDiv' objects.
API = new Detect();

function createObjects(){
	for(var i=1; i<=menuLen; i++){
		eval('API.n'+i+' = new MenuDiv("n'+i+'")');
		eval('API.s'+i+' = new MenuDiv("s'+i+'")');
	}
	loaded = true;
	showMenu(3); // open the first menu
}
onload = createObjects;

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//-->
