var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
//var is_nav2 = (is_nav && (is_major == 2));
//var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
//var is_nav4up = (is_nav && (is_major >= 4));
//var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
//var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
//var is_gecko = (agt.indexOf('gecko') != -1);
 var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
//var is_ie3    = (is_ie && (is_major < 4));
//var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
//var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
//var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
//svar is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
//var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

window.onerror = null;			// turn off error handling.
var menu_item_active = 0;		// flag when a menu item is active.
var my_timer = null;				// has a timer been set? i.e. is it during a set timeout?
var l_ref;									// layer reference, IE/NS.
var l_style;								// layer style property, IE/NS.
var l_show;									// layer show property, IE/NS. 
var l_hide;									// layer hide property, IE/NS. 
var layer_is_on;						// name of the layer which is currently on.
var time_delay = 1000;				// delay of menu hiding.


if (is_nav6up) {
l_ref = "document.getElementById";
l_style = ".style";
l_show = "visible";
l_hide = "hidden";
}
else if (is_nav4) {
l_ref = "document.layers";
l_style = "";
l_show = "show";
l_hide = "hide";
}
else if (is_ie4up) {
l_ref = "document.all";
l_style = ".style";
l_show = "visible";
l_hide = "hidden";
}

var hidetimer = 0;

function toggle_visibility(to_show, name) {
	// decide if calling event is showing or hiding the menu.
	var s;
	if (to_show)
		s = l_show;			// show the menu.
	else
		s = l_hide;			// hide the menu.

	if (my_timer != null) {
		clearTimeout(my_timer);
		if (is_nav6up) 
			eval(l_ref + '("' + layer_is_on + '")' + l_style + '.visibility="' + l_hide + '"');
		else
			eval(l_ref + '["' + layer_is_on + '"]' + l_style + '.visibility="' + l_hide + '"');
	}
					
	if (name != "") {
		if (is_nav6up){
			eval(l_ref + '("' + name + '")' + l_style + '.visibility="' + s + '"');
			layer_is_on = name;	
		}	
		else {
			eval(l_ref + '["' + name + '"]' + l_style + '.visibility="' + s + '"');
			layer_is_on = name;		
		}	
	}
}

function hide_other_menu() {
	toggle_visibility(false, "");
}

function menu_item_over() {
	clearTimeout(my_timer)
	menu_item_active = 1;
}
	
function menu_item_out() {
	menu_item_active = 0 
	my_timer = setTimeout('toggle_visibility(false, "' + layer_is_on + '")', time_delay);
}

function header_out_timer() {	
	my_timer = setTimeout("header_out()", time_delay);
}

function header_out() {
	if (menu_item_active == 0)
		hide_other_menu();
}

function swapImage(img_name,img_src) {
  document[img_name].src=img_src;
}

function openWindow(url) {
  popupWin = window.open(url, 'newwin', 'width=400,height=400,scrollbars=no')
}

function centerLayout(){
	var layoutWidth = 725;
	var bodyWidth;
	var scroll_bar_width;

	if ((document.all) || (document.layers) || (document.getElementById)) { 

		if (navigator.appName == 'Netscape') {
			bodyWidth = window.innerWidth;
			scroll_bar_width = 8;
		}
		else {
			bodyWidth = document.body.offsetWidth;
			scroll_bar_width = 22;
		}

		var theOffset = Math.round((bodyWidth - layoutWidth - scroll_bar_width) / 2);
					
		if (theOffset < 0){
			theOffset = 0 
		}
		if (theOffset >= 0){
			var sections;
			var left_pos;
			var starter = (171 + theOffset);
			sections = new Array("m1", "m2", "m3");
			left_pos = new Array(starter, 0, 0);
			var v;
			var pos = 0;
			var p = 0;
			for(i = 0; i < sections.length; i++) {
				if (is_nav6up){
					v = eval(l_ref + '("' + sections[i] + '")' + l_style);
					pos =  pos + left_pos[i];
					v.left = pos + "px";
				}	
				else {
					v = eval(l_ref + '["'+ sections[i] + '"]' + l_style);
					pos =  pos + left_pos[i];
					v.left = pos;
				}
			} 
		}
	}
}
