// Determine browser

var browser = '';

if (document.all) {
 	browser = 'ie4';
} else if (document.layers) {
	browser = 'ns4';
} else if (document.getElementById && !document.all) {
	browser = 'ns6';
}


// Rollover functions

var onstate = new Array();
var offstate = new Array();

onstate['company'] = new Image();
onstate['company'].src = '/images/company_2.gif';
onstate['products'] = new Image();
onstate['products'].src = '/images/products_2.gif';
onstate['installations'] = new Image();
onstate['installations'].src = '/images/installations_2.gif';
onstate['information_center'] = new Image();
onstate['information_center'].src = '/images/information_center_2.gif';
onstate['where'] = new Image();
onstate['where'].src = '/images/where_2.gif';
onstate['service_support'] = new Image();
onstate['service_support'].src = '/images/service_support_2.gif';
onstate['integrator'] = new Image();
onstate['integrator'].src = '/images/integrator_secure_2.gif';

offstate['company'] = new Image();
offstate['company'].src = '/images/company.gif';
offstate['products'] = new Image();
offstate['products'].src = '/images/products.gif';
offstate['installations'] = new Image();
offstate['installations'].src = '/images/installations.gif';
offstate['information_center'] = new Image();
offstate['information_center'].src = '/images/information_center.gif';
offstate['where'] = new Image();
offstate['where'].src = '/images/where.gif';
offstate['service_support'] = new Image();
offstate['service_support'].src = '/images/service_support.gif';
offstate['integrator'] = new Image();
offstate['integrator'].src = '/images/nav/integrator_secure.gif';


function menurollon(whichdoc,whichimg) {
	if (browser == 'ns4') {
		if (whichdoc != '') {
			eval("document.layers['" + whichdoc + "'].document.images['" + whichimg + "'].src = onstate['" + whichimg + "'].src");
		} else {
			eval("document.images['" + whichimg + "'].src = onstate['" + whichimg + "'].src");
		}
	} else {
		eval("document.images['" + whichimg + "'].src = onstate['" + whichimg + "'].src");
	}
}

function menurolloff(whichdoc,whichimg) {
	if (browser == 'ns4') {
		if (whichdoc != '') {
			eval("document.layers['" + whichdoc + "'].document.images['" + whichimg + "'].src = offstate['" + whichimg + "'].src");
		} else {
			eval("document.images['" + whichimg + "'].src = offstate['" + whichimg + "'].src");
		}
	} else {
		eval("document.images['" + whichimg + "'].src = offstate['" + whichimg + "'].src");
	}
}


// Section navigation rollover functions

onstate['sectnav1'] = new Image();
onstate['sectnav1'].src = '/images/common/yellowbullet.gif';
onstate['sectnav2'] = new Image();
onstate['sectnav2'].src = '/images/common/yellowbullet.gif';
offstate['sectnav1'] = new Image();
offstate['sectnav1'].src = '/images/common/dkgraybullet.gif';
offstate['sectnav2'] = new Image();
offstate['sectnav2'].src = '/images/common/ltgraybullet.gif';

function navrolloff(level,whichimg) {
	if (level == 1) {
		eval("document.images['sectnav" + level + "_" + whichimg + "'].src = offstate['sectnav1'].src");
	} else {
		eval("document.images['sectnav" + level + "_" + whichimg + "'].src = offstate['sectnav2'].src");
	}
}

function navrollon(level,whichimg) {
	eval("document.images['sectnav" + level + "_" + whichimg + "'].src = onstate['sectnav1'].src");
}



// Set up names of subnavigation divs
	
var submenus = new Array();
submenus[0] = 'company';
submenus[1] = 'products';
submenus[2] = 'installations';
submenus[3] = 'info';
submenus[4] = 'where';
submenus[5] = 'service';
submenus[6] = 'integrator';
submenus[7] = 'consultants';
submenus[8] = 'contact';


// Arrays to hold div dimensions and coordinates

var insideheight = new Array(submenus.length);
var insidewidth = new Array(submenus.length);
var xpos = new Array(submenus.length);
var ypos = new Array(submenus.length);
var xmin = new Array(submenus.length);
var xmax = new Array(submenus.length);
var ymin = new Array(submenus.length);
var ymax = new Array(submenus.length);
var increment = new Array(submenus.length);
var cliptop = new Array(submenus.length);

var ymenu;
var menuheight;
var activemenu;
var animstep = new Array(submenus.length);				// Track at which step in animation each div is

var timerflag = 0;
var detimerflag = 0;
var animstepsum = 0;

var numsteps = 4;						// Number of steps in animation


// Move the subnavigation divs to the bottom of the navigation buttons 

function initializemenus() {
	for (i = 0; i < submenus.length; i++) {
		whichnav = submenus[i];
		if (browser == 'ie4') {
			insideheight[i] = eval('document.all.divnav' + whichnav + '.offsetHeight');
			insidewidth[i] = eval('document.all.divnav' + whichnav + '.offsetWidth');
			cliptop[i] = insideheight[i];
			xpos[i] = eval('document.all.divnav' + whichnav + '.offsetLeft');
			menuheight = document.all.divnavmain.offsetHeight;
			ymenu = document.all.divnavmain.offsetTop + menuheight;
			ypos[i] = ymenu - insideheight[i]; 
			xmin[i] = xpos[i];
			xmax[i] = xpos[i] + insidewidth[i];
			ymin[i] = ymenu - menuheight;
			ymax[i] = ymenu + insideheight[i];
			eval('document.all.divnav' + whichnav + '.style.top = "' + Math.ceil(ypos[i]) + 'px"');
			eval('document.all.divnav' + whichnav + '.style.clip = "rect(' + Math.floor(cliptop[i]) + 'px auto auto auto)"');
		} else if (browser == 'ns4') {
			insideheight[i] = eval('document.layers.divnav' + whichnav + '.document.height');
			insidewidth[i] = eval('document.layers.divnav' + whichnav + '.document.width');
			cliptop[i] = insideheight[i];
			xpos[i] = eval('document.layers.divnav' + whichnav + '.left');
			menuheight = document.layers.divnavmain.document.height;
			ymenu = document.layers.divnavmain.top + menuheight;
			ypos[i] = ymenu - insideheight[i];
			xmin[i] = xpos[i];
			xmax[i] = xpos[i] + insidewidth[i];
			ymin[i] = ymenu - menuheight;
			ymax[i] = ymenu + insideheight[i];
			eval('document.layers.divnav' + whichnav + '.moveTo(' + xpos[i] + ',' + ypos[i] + ')');
			eval('document.layers.divnav' + whichnav + '.clip.top = ' + cliptop[i]);

			// Navigator 4 for Windows doesn't display the background image, so make it gray

			if (navigator.platform.indexOf('Win') != -1) {
				eval('document.layers.divnav' + whichnav + '.bgColor = "#333333"');
			}
		} else if (browser == 'ns6') {
			insideheight[i] = eval('document.getElementById("divnav' + whichnav + '").offsetHeight');
			insidewidth[i] = eval('document.getElementById("divnav' + whichnav + '").offsetWidth');
			cliptop[i] = insideheight[i];
			xpos[i] = parseInt(eval('document.getElementById("divnav' + whichnav + '").offsetLeft'));
			menuheight = document.getElementById('divnavmain').offsetHeight;
			ymenu = document.getElementById('divnavmain').offsetTop + menuheight;
			ypos[i] = ymenu - insideheight[i];
			xmin[i] = xpos[i];
			xmax[i] = xpos[i] + insidewidth[i];
			ymin[i] = ymenu - menuheight;
			ymax[i] = ymenu + insideheight[i];
			eval('document.getElementById("divnav' + whichnav + '").style.top = "' + ypos[i] + 'px"');
			eval('document.getElementById("divnav' + whichnav + '").style.clip = "rect(' + cliptop[i] + 'px,auto,auto,auto)"');
		}
		increment[i] = insideheight[i] / numsteps;
		animstep[i] = 0;
	}
	
}


// Activate menu when rolled over

function activatemenu(menunum) {
	cleartimer();
	whichmenu = submenus[activemenu];
	if (activemenu != null) {
		menurolloff('divnavmain',whichmenu);
	}
	activemenu = menunum;
	settimer();
	whichmenu = submenus[activemenu];
	if (activemenu != null) {
		menurollon('divnavmain',whichmenu);
	}
}


// Deactivate all menus on mouseout

function deactivatemenu() {
	detimer = setTimeout('activatemenu()',40);
	detimerflag = 1;
}


// Move all of the submenu divs

function movemenus() {
	for (i = 0; i < submenus.length; i++) {
		whichnav = submenus[i];
		if (i == activemenu) {
			if (animstep[i] < numsteps) {
				ypos[i] += increment[i]; 
				animstep[i]++;
				cliptop[i] = insideheight[i] - (animstep[i] * increment[i]);
			} else {
				cleartimer();
			}
		} else {
			if (animstep[i] > 0) {
				ypos[i] -= increment[i];
				animstep[i]--;
				cliptop[i] = insideheight[i] - (animstep[i] * increment[i]);
			}
		} 
		if (browser == 'ie4') {
			eval('document.all.divnav' + whichnav + '.style.top = "' + Math.ceil(ypos[i]) + 'px"');
			eval('document.all.divnav' + whichnav + '.style.clip = "rect(' + cliptop[i] + 'px,auto,auto,auto)"');
		} else if (browser == 'ns4') {
			eval('document.layers.divnav' + whichnav + '.moveTo(' + xpos[i] + ',' + Math.ceil(ypos[i]) + ')');
			eval('document.layers.divnav' + whichnav + '.clip.top = ' + cliptop[i]);
		} else if (browser == 'ns6') {
			eval('document.getElementById("divnav' + whichnav + '").style.top = "' + Math.ceil(ypos[i]) + 'px"');
			eval('document.getElementById("divnav' + whichnav + '").style.clip = "rect(' + cliptop[i] + 'px,auto,auto,auto)"');
		}
	}
	clearmenutimers();
} 


// Timer functions

function settimer() {
	if (timerflag == 1) {
		clearInterval(timer);
		timerflag = 0;
	}
	timer = setInterval('movemenus()',40);
	timerflag = 1;
}

function cleartimer() {
	if (timerflag == 1) {
		clearInterval(timer);
		timerflag = 0;
	}
}


// Clear all the timers when all menus deactivated

function clearmenutimers() {
	animstepsum = 0;
	for (i = 0; i < submenus.length; i++) {
		animstepsum += animstep[i];
	}
	if (animstepsum == 0) {
		cleartimer();
	}
}


// Check the cursor coordinates

function checkcoord(evnt) {
	if (activemenu != null) {
		whichnav = submenus[activemenu];
		if (browser == 'ie4') {
			if ((event.clientX < xmin[activemenu] || event.clientX > xmax[activemenu]) || (event.clientY < ymin[activemenu] || event.clientY > ymax[activemenu])){
				activatemenu();
			} else {
				activatemenu(activemenu);
			}
		} else if (browser == 'ns4' || browser == 'ns6') {
			if ((evnt.pageX < xmin[activemenu] || evnt.pageX > xmax[activemenu]) || (evnt.pageY < ymin[activemenu] || evnt.pageY > ymax[activemenu])) {
				activatemenu();
			} else {
				activatemenu(activemenu);
			}
		} 
	}
}


// Track the mouse movements

if (browser == 'ns4') {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = checkcoord;


// Initialize the menu divs

function init() {
	if (browser != 'ns6') {
		initializemenus();
	}
}


// Netscape 6 must wait for the page to load

function ns6init() {
	if (browser == 'ns6') {
		initializemenus();
	}
}


// Resize the page for Netscape 4

function resizer() {
	if (browser == 'ns4') {
		document.location = this.document.location;
	}
}


// Open the dealer locator window

function opendealer() {
	var newwin = window.open('http://go.vicinity.com/buellintld/prxStart.d','dealer','width=610,height=500,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes');
//	newwin.focus()
}


// Pop up functions

function openfixedpopup(loc,winname,w,h) {
	eval("var newwin = window.open(loc,'" + winname + "','width=" + w + ",height=" + h + ",top=0,left=0,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no')");
}

function openfixednoscrollpopup(loc,winname,w,h) {
	eval("var newwin = window.open(loc,'" + winname + "','width=" + w + ",height=" + h + ",top=0,left=0,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no')");
}

function openfixedscrollpopup(loc,winname,w,h) {
	eval("var newwin = window.open(loc,'" + winname + "','width=" + w + ",height=" + h + ",top=0,left=0,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no')");
}

