
/*
Script Name: Simple Javascript Browser/OS detection
Authors: Harald Hope, Tapio Markula, Websites: http://techpatterns.com/
http://www.nic.fi/~tapio1/Teaching/index1.php3
Script Source URI: http://techpatterns.com/downloads/javascript_browser_detection.php
Version 2.0.1
Copyright (C) 08 August 2004

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Lesser GPL license text:
http://www.gnu.org/licenses/lgpl.txt

*/

/*************************************************************
Light version, use for basic browser detection only. Use our
http://techpatterns.com/downloads/javascript_browser_detection.txt script for more
complex javascript browser detection.

Remember, always use method or object testing as your first choice, for example, if ( dom ) { statement; };

Let me know if you find an error or a failure to properly detect, or if there
is a relevant browser that has special needs for detection at our tech forum:
http://techpatterns.com/forums/forum-11.html
The main script is separated from the initial netscape 4 detection due to certain bugs in
netscape 4 when it comes to unknown things like d.getElementById. The variable declarations
of course are made first to make sure that all the variables are global through the page, 
otherwise a javascript error will occur because you are trying to use an undeclared variable.

We test for basic browser type (ie, op, or moz/netscape > 6)..

For more in depth discussion of css and browser issues go to:
http://www.nic.fi/~tapio1/Teaching/DynamicMenusb.php#detections
http://www.nic.fi/~tapio1/Teaching/FAQ.php3

***************************************************************/

/**************************************************************
Lite version, tests only for main types and browsers out there, 
this will cover you in almost all normal situations out there.
***************************************************************/

var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;

d = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( nua.indexOf( 'Linux' ) != -1 );

if ( !d.layers ){
	dom = ( d.getElementById );
	op = ( nua.indexOf( 'Opera' ) != -1 );
	konq = ( nua.indexOf( 'Konqueror' ) != -1 );
	saf = ( nua.indexOf( 'Safari' ) != -1 );
	moz = ( nua.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	ie = ( d.all && !op );
	ie4 = ( ie && !dom );

	/*
	ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
	Opera will register true in this test if set to identify as IE 5
	*/

	ie5x = ( d.all && dom );
	ie5mac = ( mac && ie5x );
	ie5xwin = ( win && ie5x );
}



/* From here down is the original ACA menu code.
 * Blue Ridge Solutions, Inc.  www.blueridges.com
 *
 */



function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

var _tid = 0;
var _mname = '';

function hideMenu() {
	killTimer();
	if(_mname.length) {
		v = document.getElementById(_mname);
		if(v)
			v.style.display = 'none';
	}
	_mname = '';
}

function killTimer() {
	if(_tid) clearTimeout(_tid);
	_tid = 0;
}

function startTimer() {
	_tid = setTimeout("hideMenu()", 1000);
}

function showMenu(n) {
	hideMenu();
	name = 'menua' + n;
	
	e = document.getElementById(name);
	x = findPosX(e);
	y = findPosY(e);
	
	// Display the menu in the right location
	_mname = 'menu' + n;
	v = document.getElementById(_mname);

	yp = y + 20;
	if(ie5x ) {
		yp += 17;
		x -= 2;
		if(mac) {
				yp -= 8;
				x -= 15;
		}
		x += 15;
	}
	if(saf) {
		yp += 6;
		x += 8;
	}
	if(konq) 
		yp -= 16;
	//x = x + 3;


	v.style.display = 'block';
	v.style.left = x+ 'px';
	v.style.top = yp + 'px';
	
	// Hide the menu after a timeout	
	_tid = setTimeout("hideMenu()", 2000);
	
}

