var d = document;
var mx = 0;
var my = 0;
var target = 0;
var tl = {x: 0, y: 0 };
var menu = false;
var filename = location.pathname.substring(location.pathname.lastIndexOf('/') + 1).split('?#');
filename = filename[0];

var nav_company = [6, 'company.htm', 'company_oa.htm'];
var nav_services = [83, 'services_pr.htm', 'services_wg.htm', 'services_pg.htm','services_mm.htm','services_kc.htm'];
var nav_team = [150, 'team_jt.htm', 'team_ln.htm', 'team_ja.htm', 'team_bn.htm', 'team_ah.htm', 'team_ev.htm'];
var nav_testimonials = [224, 'testimonials.htm', 'testimonials_qa.htm', 'testimonials_cs.htm', 'testimonials_fees.htm'];
var nav_showcase = [313, 'showcase_wg.php', 'showcase_pg.htm', 'showcase_mm.htm'];
var nav_contact = [386, 'contact.php'];
var nav_search = [0];
var nav_home = [0];


function g(o) {return document.getElementById(o);}

function showTime() {
	var timeNow = new Date();
	var date = timeNow.getDate();
	var month = timeNow.getMonth() + 1;
	var year = timeNow.getFullYear();
	var hour = timeNow.getHours();
	var minutes = timeNow.getMinutes();

	var day = timeNow.getDay();
	var days  = ((date < 10) ? "0" : "");
	var months  = ((month < 10) ? ".0" : ".");
	var hours  = ((hour < 10) ? "0" : "");
	var mins  = ((minutes < 10) ? ":0" : ":");

	g('dtDay').innerHTML = "&nbsp;&nbsp;Today's Date: " + date + "." + month + "." + year;
	g('dtHour').innerHTML = hours + hour + mins + minutes;
	setTimeout('showTime()',1000);
}

function menuLoop() {
	tl = itemPosition('menu');
	if(menu) {
		target = mx - tl.x - 36;
	}
	var currx = parseInt(g('menuBG').style.left);
	var go = currx + (target - currx) / 5;
	if(go < 0) go = 0;
	if(go > 390) go = 390;
	g('menuBG').style.left = go + 'px';
	setTimeout('menuLoop()',20);
}

function Is(){
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=this.agent.indexOf("Opera 5")>-1;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
	return this;
}

var is = new Is();

function mouse(e) {
	mx = parseInt((is.ie) ? window.event.clientX+d.body.scrollLeft : e.pageX);
	my = parseInt((is.ie) ? window.event.clientY+d.body.scrollTop : e.pageY);
}

function itemPosition(o) {
	var item = g(o);
	var coords = {x: 0, y: 0 };
	// single bit of browser-dependant code below
	while(item || (item && !(is.ie && is.mac))) {
		coords.x += item.offsetLeft;
		coords.y += item.offsetTop;
		item = item.offsetParent;
	}
	return coords;
}

document.onmousemove = mouse;

function load() {
	showTime();
	menuLoop();

}

function openWin(sURL, w, h) {
	var nWinHeight = h;
	var nWinWidth = w;
	var nWinTop = parseInt((screen.availHeight/2)-(nWinHeight/2)) - 80;
	var nWinLeft = parseInt((screen.availWidth/2)-(nWinWidth/2));
	var oWindow = window.open(sURL, "newwin", "width="+nWinWidth+",height="+nWinHeight+",top="+nWinTop+",left="+nWinLeft+",location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,status=no");
	oWindow.focus();
}

function writeHeader() {
	var out = '';
	out += '<table cellpadding="0" cellspacing="0" border="0">';
	out += '<tr>';
	out += '<td valign="top">';
	out += '<div style="width:466px; padding-top:23px;">';
	out += '<a href="/"><img src="images/logo.gif" width="250" height="46" border="0"></a>';
	out += '</div>';
	out += '</td>';
	out += '<td valign="top">';
	out += '<form class="searchBoxUp" name="tip_Form" onsubmit="search_form(tip_Form);return false;" style="margin:0px; padding-top:7px;">';
	out += '<table>';
	out += '<tr>';
	out += '<td><img src="/images/search1.gif" width="42" height="20"></td>';
	out += '<td><input type="text" name="d" style="margin-top:1px; width:112px; height:21px;"></td>';
	out += '<td><input type="image" src="images/goimage1.gif" width="28" height="28" onClick="search_form(tip_Form);return false;"></td>';
	out += '</tr>';
	out += '</table>';
	out += '</form>';
	out += '<div class="searchBoxDown">';
	out += '<div id="dtDay"></div>';
	out += '<div id="dtHour"></div>';
	out += '</div>';
	out += '</td>';
	out += '</tr>';
	out += '</table>';
	
	out += '<div class="menu" id="menu" onmouseover="menu = true;" onmouseout="menu = false;">';
	
	
	var nav = eval('nav_'+sectionname);
	if(nav) {
		target = nav[0];
	}
	else {
		target = 0;
	}
	out += '<div id="menuBG" class="menuBG" style="top:0px; left:'+(target-20)+'px; z-index:1;">&nbsp;</div>';
	out += '<a href="company.htm" style="padding-left:22px;">Company</a>';
	out += '<a href="services_pr.htm">Services</a>';
	out += '<a href="team_jt.htm">Team</a>';
	out += '<a href="testimonials.htm">Testimonials</a>';
	out += '<a href="showcase_wg.php">Showcase</a>';
	out += '<a href="contact.php" style="padding-right:23px;">Contact</a>';
	out += '<div class="mp3" onclick="openWin(\'/player.html\',300,100); return false;"><div class="text">launch MP3 music player</div></div>';
	out += '</div>';
	
	if(sectionname != 'home') {
		if( is_Flash || (is_nav4==true && Flash_Installed_Var>1) ){
			out += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="669" height="90">';
			out += '<param name="movie" value="/flash/'+sectionname+'.swf">';
			out += '<param name=quality value=high>';
			out += '<embed src="/flash/'+sectionname+'.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="669" height="90"></embed>';
			out += '</object>';
		} else {
			out += '<img src="images/banner_'+sectionname+'.jpg" width="669" height="90" alt="non-flash image" />';
		}
	}
	document.write(out);
}

function writeSideMenu() {
	var out = '<a href="./"><img src="images/company_home.gif" width="154" height="23" border="0"></a><br />';
	var nav = eval('nav_'+sectionname);
	if(nav.length > 1) {
		for(var i = 1; i < nav.length; i++) {
			if(nav[i] == filename) {
				out += '<a href="'+nav[i]+'"><img src="images/'+sectionname+'_nav'+(i)+'_on.gif" width="154" height="23" border="0"></a><br />';
			}
			else {
				out += '<a href="'+nav[i]+'"><img src="images/'+sectionname+'_nav'+(i)+'_off.gif" width="154" height="23" border="0"></a><br />';
			}
		}
	}
	document.write(out);
}

function step(n) {
	for(var i = 1; i <= 2; i++) {
		if(i != n) {
			g('step'+i).style.display = 'none';
		}
	}
	g('step'+n).style.display = 'block';
	return false;
}
