// CHECK CLIENT BROWSER & PLATFORM
// original code from http://developer.apple.com/internet/_javascript/
//
// USAGE:	browserNaming();
// NOTES:	call it from within an external JS document
// RESULT:	browserNew = true/false
//			browserName = IE/NS/Opera
//			browserNameLong = IE5/etc
//			Macintosh = true/false
// WORKS:	everything

	var its;
	var browserName;
	var browserNameLong;
	var browserNew;
	var preloadFlag = false;
	var Macintosh = navigator.userAgent.indexOf('Mac') > 0;

	function its() {
		var n = navigator;
		var ua = ' ' + n.userAgent.toLowerCase();
		var pl = n.platform.toLowerCase();
		var an = n.appName.toLowerCase();

		// browser version
		this.version = n.appVersion;
		this.nn = ua.indexOf('mozilla') > 0;

		// 'compatible' versions of mozilla aren't navigator
		if (ua.indexOf('compatible') > 0) { this.nn = false; }
		
		this.opera = ua.indexOf('opera') > 0;
		this.ie = ua.indexOf('msie') > 0;
		this.major = parseInt(this.version);
		this.minor = parseFloat(this.version);

		// platform
		this.mac = ua.indexOf('mac') > 0;
		this.win = ua.indexOf('win') > 0;

		// workaround for IE5 which reports itself as version 4.0
		if (this.ie) {
			if (ua.indexOf("msie 5") > 1) {
				var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
				this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
			}
		}

		return this;
	}

	function browserNaming() {
		its = new its();
		
		// is it a DOM-enabled browser?
		if (!document.getElementById) {
			browserNew = false;
		} else {
			browserNew = true;
		}

		// need the name, too
		if (its.opera) {
			browserName = "Opera";
		} else if (its.ie) {
			browserName = "IE";
		} else {
			browserName = "NS";
		}

		// and the number
		browserNameLong = browserName + its.major;
	}

//	PRELOAD FUNCTION
//	WORKS:	ie4+, ns4+, opera5
//	USAGE:	usually called on in the <body onload="preloadMe();" onload="preloadMe();> or window.onload
//	NOTES:	requires create object function; flag variable must be unique and globally initialized to false
	var preloadMeFlag = false;
	function preloadMe() {
		createObject('homeOff','/bin/images/menu/home_off.gif');
		createObject('homeOn','/bin/images/menu/home_on.gif');
		createObject('companyOff','/bin/images/menu/company_off.gif');
		createObject('companyOn','/bin/images/menu/company_on.gif');
		createObject('productsOff','/bin/images/menu/products_off.gif');
		createObject('productsOn','/bin/images/menu/products_on.gif');
		createObject('servicesOff','/bin/images/menu/services_off.gif');
		createObject('servicesOn','/bin/images/menu/services_on.gif');
		createObject('contactOff','/bin/images/menu/contact_off.gif');
		createObject('contactOn','/bin/images/menu/contact_on.gif');
		preloadMeFlag = true;
	}

//	CREATE OBJECT FUNCTION
//	WORKS:	ie4+, ns4+, opera5
//	USAGE:	usually called from a preload function
//	NOTES:	n/a
	function createObject(imgName, imgSrc) {
		if (browserNew && (browserName == "NS")) {		// a DOM-compatible browser
			var tempImg = document.createElement("img");
			tempImg.src = imgSrc;
			tempImg.id = imgName;
			tempImg.style.visibility = 'hidden';
			tempImg.style.position = 'absolute';
			tempImg.style.top = 0;
			document.body.appendChild(tempImg);
		} else {		// a non-DOM-compatible browser
			eval(imgName+' = new Image()');
			eval(imgName+'.src = "'+imgSrc+'"');
		}
	}

//	OBJECT SWITCHING
//	WORKS:	ie4+, ns4+, opera5
//	USAGE:	<a href="" onmouseover="changeImage(null, 'buttonname', 'buttonnameon', 'preloadMeFlag');" onmouseout="changeImage(null, 'buttonname', 'buttonnameoff', 'preloadMeFlag');">
//	NOTES:	if the image is in a DIV, substitute 'null' with the DIV name.
	function changeImage(layer, imgName, imgObj, flag) {
		if (eval(flag)) {
			if (browserNew && (browserName == "NS")) {		// a DOM-compatible browser
				thisImage = document.getElementById(imgName);
				newImage = document.getElementById(imgObj);
				newSrc = newImage.getAttribute("src");
				thisImage.setAttribute("src", newSrc);
			} else {		// a non-DOM-compatible browser
				if ((browserName == "NS") && layer!=null) { eval('document.'+layer+'.document.images["'+imgName+'"].src = ' + imgObj + '.src'); }
				else { document.images[imgName].src = eval(imgObj + ".src"); }
			}
		}
	}

//	POPUP WINDOW
//	WORKS:	ie4+, ns4+, opera5
//	USAGE:	<a href="newpage.html" onclick="spawnWindow('newpage.html', 'windowname', 400, 300, true, false, false, false, false, true); return false;">
//	NOTES:	n/a
	function spawnWindow(windowURL, windowName, popWidth, popHeight, popResizable, popScrollbar, popMenubar, popToolbar, popLocation, popStatus) {
		if (navigator.userAgent.indexOf('Mac') > 0) { if (browserNameLong == "IE4" || browserNameLong == "IE4.5") { popHeight = parseInt(popHeight + 17); } }
		var windowAttribs = 'width=' + popWidth + ', height=' + popHeight + ', resizable=' + Number(popResizable) + ', scrollbars=' + Number(popScrollbar) + ', menubar=' + Number(popMenubar) + ', toolbar=' + Number(popToolbar) + ', location=' + Number(popLocation) + ', status=' + Number(popStatus);
		var remote = window.open(windowURL, windowName, windowAttribs);
		if (remote != null) { if (remote.opener == null) { remote.opener = self; } }
		remote.focus();
	}

	function spawnPDF(thisURL) {
		spawnWindow(thisURL, 'pdf', 700, 500, true, false, false, false, false, true);
		return false;
	}
	
	function spawnIMG(thisURL) {
		spawnWindow(thisURL, 'img', 600, 500, true, false, false, false, false, true);
		return false;
	}

