// GLOBAL VARIABLES
var d = document;
	
// DOM FUNCTIONS
var getElement = function(e) {
	return d.getElementById(e);
}
	
// POPUP WINDOW FUNCTION
var Popup = {
	open: function(domain, w, h, toggle, locbar) {
		this.options = {
			url: domain,
			width: w,
			height: h,
			left: screen.width / 2 - (w / 2),
			top: screen.height / 2 - (h / 2),
			scrollbars: toggle
		}
		
		if(locbar == 'undefined') {
			locbar = 'yes';
		}
		
		window.open(this.options.url, '', 'location=' + locbar + ', resizable=no, width=' + this.options.width + ',height=' + this.options.height + ',scrollbars=' + this.options.scrollbars + ',left=' + this.options.left + ',top=' + this.options.top);
	}
}

// OPEN LINKS IN POPUP WINDOW (THIS REQUIRES THE ABOVE SCRIPT)
function fnOpenWindow()
{
	// first store all anchor elements in an array
	var a = d.getElementsByTagName('a');
	
	// loop through the array checking for the rel 'external'
	for (var i=0; i<a.length; i++) {
		if (a[i].getAttribute('rel') == 'external') {
			var width = screen.availWidth;
			var height = screen.availHeight;
			a[i].onclick = function() { Popup.open(this.href, width, height, 1); return false; };
		}
	}
}

// ADD EVENT FUNCTION
function fnAddEvent(obj, evType, fn, useCapture)
{	
	// Gecko browsers (Mozilla / Firefox)
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} 
	// Internet Explorer 5+
	else if (obj.attachEvent) {
		var r = obj.attachEvent('on' + evType, fn);
		return r;
	}
	// This sets the event handler for NS4 & IE5/Mac.
	else {
		elm['on' + evType] = fn;
	}

}

// PPK - IMAGE MOUSEOVER FUNCTION
function fnInitMouseOvers(obj,ext) {
	if (getElement(obj) == null || getElement(obj) == 'undefined') {
		return false;
	}
	
	var o = getElement(obj);
	var links = o.getElementsByTagName('img');
	
	for(var i=0; i<links.length; i++) {
		if (links[i].className == 'current') { // check if object is already highlighted
			continue;
		} else if (links[i].className == 'nojs') {
			continue;
		}
			
		// store mouse over image src - but dont include the .gif extension
		var moSrc = links[i].src.substring(0, links[i].src.lastIndexOf('.'));
		
		// now add the new 'mouse over' extension
		moSrc += '_O.' + ext;
		
		// add a custom attribute to the image element called 'moSrc' and set its value to the image rollover
		links[i].moSrc = moSrc;
		
		// add a custom attribute to the image element called 'orgSrc; and set its value to the image src
		links[i].orgSrc = links[i].src;
		
		// set the mouseover event
		links[i].onmouseover = function() {
			this.src = this.moSrc;
		}
		
		// set the mouseout event
		links[i].onmouseout = function() {
			this.src = this.orgSrc;
		}
	}
}
	
// PPK BROWSER DETECT
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

// EVENT TRIGGERS
fnAddEvent(window, 'load', fnOpenWindow);
fnAddEvent(window, 'load', fnCRIMESetHandlers);
fnAddEvent(window, 'load', function(){ fnInitMouseOvers('splash-links','gif'); });

// TRIGGERED FUNCTIONS

function fnCRIMESetHandlers() {
	if (d.getElementsByTagName('body')[0].className != 'crime') {
		return false;
	}
	
	b = getElement('oSubmit');
	
	b.onclick = function() { 
		s = getElement('oSelect');
		sValue = s.options[s.selectedIndex].value;
		
		if (sValue == 'na') {
			// do nothing as the default option has been selected
		} else {
			document.location.href = sValue;
		}
	}
}

function fnEmployeeForm() {
	Popup.open('form.asp', '354', '590', 0, 0);
}
