/*////////////////////////////////////////////////////////////
JavaScript Code Library
Developed by GrafX Design Division Pty Ltd
http://www.grafx.com.au

Last Checked In By : Richard Czeiger
Public Revision No : 1.0

The software and related user documentation are
protected under copyright laws and remain the sole
property of GrafX Design Division. Full license is
available on the GrafX Design Division web site or
in the original download.

Technical support is available via the GrafX web site at
http://www.grafx.com.au
////////////////////////////////////////////////////////////*/



// Get the hacked stylesheet
document.write('<style type="text/css">@import url("styles/hacks.css");</style>');



// Suppress JavaScript Errors
window.onerror=new Function("return true")



// Set the Status Bar Message
var statusMsg = "Mates Technology";
window.defaultStatus=statusMsg;



// Google Analytics Tracking Code
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function googleAnalytics() {
	var pageTracker = _gat._getTracker("UA-1477859-20");
	pageTracker._initData();
	pageTracker._trackPageview();
}



// Fixes IE6 CSS Rendering Bug
if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
function fixWinIE() {
	if (document.body.scrollHeight < document.body.offsetHeight) { document.body.style.display = 'block'; }
}



// Spam Suppression for Emails
function stopSpam(name, domain, subject) {
	var symbol = '@';
	// Took out the Subject due to MS fault in Outlook Express (Source - http://support.microsoft.com/kb/q182985/ )
	// document.write('<a href="mailto:' + name + symbol + domain + '&subject=' + subject + '">' + name + symbol + domain + '</a>');
	document.write('<a href="mailto:' + name + symbol + domain + '">' + name + symbol + domain + '</a>');
}



// Roll Over Nav
sfHover = function() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+= " sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
// Initiated below
// if (window.attachEvent) window.attachEvent("onload", sfHover);



// XHTML External Link Script
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];

		if (anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title=='') ? "Opens in a new window" : anchor.title + " [opens in a new window]";
			anchor.className+=" external";
		}

		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") {
			anchor.onclick = function () {
				window.open(this.href, 'popup', 'resizable=0,scrollbars=0,width=921,height=595,top=20,left=20');
				return false;
			}
		}

	}
}



// Clean Up Footer Links Background
function footerLinks() {
	if (!document.getElementsByTagName) return;
	var footer = document.getElementById("footer");
	var footerLinks = footer.getElementsByTagName("ul")[0];
	footerLinks.firstChild.className = 'noBG';
}



// Toggle Function
function toggle(obj) {
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}



// Toggle Object
function toggleDOM(obj, show, hide) {
	obj = document.getElementById(obj);
	if (cssClass('check',obj,hide)) {
		cssClass('swap',obj,hide,show);
	} else {
		cssClass('swap',obj,show,hide);
	}
	return false;
}



// Pop Up Image Window
function PopupPic(sPicURL) {
	window.open('image?'+sPicURL, 'imagePopUp', 'resizable=1,width=20,height=20');
}



// Event-Manager Script by Keith Gaughan
// For implementations that don't include the push() methods for arrays.
if (!Array.prototype.push) {
	Array.prototype.push = function(elem) {
		this[this.length] = elem;
	}
}

var EventManager = {
	_registry: null,

	Initialise: function() {
		if (this._registry == null) {
			this._registry = [];
			// Register the cleanup handler on page unload.
			EventManager.Add(window, "unload", this.CleanUp);
		}
	},

	// Registers an event and handler with the manager.
	Add: function(obj, type, fn, useCapture) {
		this.Initialise();
		// If a string was passed in, it's an id.
		if (typeof obj == "string")
			obj = document.getElementById(obj);
		if (obj == null || fn == null)
			return false;
		// Mozilla/W3C listeners?
		if (obj.addEventListener) {
			obj.addEventListener(type, fn, useCapture);
			this._registry.push({obj: obj, type: type, fn: fn, useCapture: useCapture});
			return true;
		}
		// IE-style listeners?
		if (obj.attachEvent && obj.attachEvent("on" + type, fn)) {
			this._registry.push({obj: obj, type: type, fn: fn, useCapture: false});
			return true;
		}
		return false;
	},

	// Cleans up all the registered event handlers.
	CleanUp: function() {
		for (var i = 0; i < EventManager._registry.length; i++) {
			with (EventManager._registry[i]) {
				// Mozilla/W3C listeners?
				if (obj.removeEventListener)
					obj.removeEventListener(type, fn, useCapture);
				// IE-style listeners?
				else if (obj.detachEvent)
					obj.detachEvent("on" + type, fn);
			}
		}
		// Kill off the registry itself to get rid of the last remaining references.
		EventManager._registry = null;
	}
};



// Multiple Onload Functions to be called
EventManager.Add(window,'load', sfHover);
EventManager.Add(window,'load', footerLinks);
EventManager.Add(window,'load', externalLinks);
EventManager.Add(window,'load', googleAnalytics);