// ****************************************
// *  Generic functions, DOM check.   
// *  ** Never delete this section **
// ****************************************

var isNS7 = 0;
var isNS9 = 0;
var isFF = 0;
var isSafari = 0;
var isIE = 0;
var isOpera9 = 0;
var isUnknown = 0;

var nav_agent;
var nav_browser;
var nav_version;

function checkBrowser() {
	nav_agent = navigator.userAgent;
	nav_browser = navigator.appName;
	nav_version = navigator.appVersion;
	
	// assign browser variables
	isNS7 = (nav_browser == "Netscape" && nav_agent.indexOf("Netscape/7") + 1)? 1: 0;
	isNS9 = (nav_browser == "Netscape" && nav_agent.indexOf("Navigator/9") + 1)? 1: 0;
	isFF = (nav_browser == "Netscape" && nav_agent.indexOf("Firefox/") + 1)? 1: 0;
	isSafari = (nav_browser == "Netscape" && nav_agent.indexOf("Safari") + 1)? 1: 0;
	isIE = (nav_browser == "Microsoft Internet Explorer" && nav_agent.indexOf("Opera") < 0)? 1: 0;
	isOpera9 = (nav_browser == "Opera" && nav_agent.indexOf("Opera/9") + 1)? 1: 0;
	
	isUnknown = (!isNS7 && !isNS9  && !isFF && !isSafari && !isIE && !isOpera9)? 1: 0;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		// add a function to the onLoad event
		window.onload = func;
	} else {
		window.onload = function() { 
			if (oldonload) { oldonload(); }
			func();
		}
	}
}

function getPageNum() {
	var page = " " + this.location.href + " ";
	var end = page.lastIndexOf(".php");
	var pageNum = page.substring(end - 1, end);

	if (pageNum == "x" || pageNum == ".") {
		pageNum = "0";
	}

	return pageNum;
}

function openWin(url, height, width) {
	window.open(url, "win",
	"toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=no, resizable=no, copyhistory=yes, width=" + width + ", height=" + height + " ");
}

// ****************************************
// *  Custom functions
// *  ** Add necessary functions here **
// ****************************************

function showBackground(element) {
	element.style.backgroundImage = "url(./images/glow.gif)";
}

function hideBackground(element) {
	element.style.backgroundImage = "url(none)";
}

function popupPic(gallery, image, max_images) {
	openWin("gallery.php?gallery=" + gallery + "&image=" + image + "&max_images=" + max_images, 420, 720);
}

function displayBrowser() {
	alert("agent: \n" + nav_agent + "\n\nbrowser: \n" + nav_browser + "\n\nversion: \n" + nav_version);
	
	alert("isNS7 = " + isNS7 + "\n" + 
	      "isNS9 = " + isNS9 + "\n" + 
	      "isFF = " + isFF + "\n" + 
	      "isSafari = " + isSafari + "\n" + 
	      "isIE = " + isIE + "\n" + 
	      "isOpera9 = " + isOpera9);
	      
	alert(nav_agent.indexOf("Opera"));
}

addLoadEvent(checkBrowser); 
