/*////////////////////////////////////////////////////////////
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")



// 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"));
// var pageTracker = _gat._getTracker("UA-4722717-1");
// pageTracker._initData();
// pageTracker._trackPageview();



// Set the Status Bar Message
var statusMsg = 'George P. Johnson';
window.defaultStatus=statusMsg;



// 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>');
}



// 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("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") {
			anchor.onclick = function PopupPic() {
				window.open('image.html?'+this.href+'&'+this.title, 'imagePopUp', 'resizable=1,width=20,height=20');
				return false;
			}
		}
	}
}



// Case Study - Multiple Images
function showStudyImage(imageURL, imageID) {
	document.getElementById(imageID).src = imageURL;
}



// Hide 'no javascript' Elements
function noJavascript() {
	if (!document.getElementsByTagName) return;
	var nojs = getElementsByClassName(document, "*", "noJavascript");
	for (var i=0; i<nojs.length; i++) {
		nojs[i].style.display = "none";
	}
}



// Toggle Function
function toggle(obj) {
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}



// jQuery Carousel Lite Functions
function startCarousel() {
//	$(function() {
		if (document.getElementById('carousel-control')) {
			if (document.getElementById('carousel-control').style.display != 'none') {
				$(".default .jCarouselLite").jCarouselLite({
					btnNext: "#carousel-control .next",
					btnPrev: "#carousel-control .prev",
					visible: 1,
					scroll: 1,
					// mouseWheel: false,
					// auto: 2500,
					// speed: 500,
					circular: false
				});
			}
		}
//	});
}



// Focus on Input Fields
// inputFocus = function () {
function inputFocus() {
	var focusEl = document.getElementsByTagName("INPUT");
	for (var i=0; i<focusEl.length; i++) {
		if ((focusEl[i].getAttribute("type") == "text")||(focusEl[i].getAttribute("type") == "password")) {
			focusEl[i].onfocus=function() {
				this.className+="sffocus";
			}
			focusEl[i].onblur=function() {
				this.className=this.className.replace(new RegExp("sffocus\\b"), "");
			}
		}
	}
	var focusTx = document.getElementsByTagName("TEXTAREA");
	for (var i=0; i<focusTx.length; i++) {
		focusTx[i].onfocus=function() {
			this.className+="sffocus";
		}
		focusTx[i].onblur=function() {
			this.className=this.className.replace(new RegExp("sffocus\\b"), "");
		}
	}
}
// if (window.attachEvent) window.attachEvent("onload", inputFocus);



// Global Cookie Function
function setCookie(NameOfCookie, value, expiredays, path, domain, secure) {
	//The first lines in the function converts the number of days to a valid date.
	var ExpireDate = new Date();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays*24*3600*1000));

	//The next line stores the cookie, simple by assigning
	//the values to the document.cookie-object
	//Note the date is converted to Greenwich Meantime using
	//the 'toGMTstring()'-function

	document.cookie = NameOfCookie +"="+ escape(value) +
	((expiredays == null)? "": ";expires="+ ExpireDate.toGMTString()) +
	((path == null)? "": (";path=" + path)) +
	((domain == null) ? "" : (";domain=" + domein)) +
	((secure == true) ?";secure":"");
}

function getCookie(NameOfCookie) {
	if(document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if(begin != -1) {
			// our cookie was set.
			// The value stored in the cookie is returned from the function
			begin += NameOfCookie.length + 1;
			end = document.cookie.indexOf(";",begin);
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin,end));
		}
	}
	return null;
	// Our cookie was not set.
	// The value "null" is returned from the function
}

function delCookie(NameOfCookie) {
	// The function simply checks if the cookie is set. If so expiredate is set to Jan. 1st 1970
	if(getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie +"=" +
		";expires= Thu, 01-Jan-70 00:00:01 GMT";
	}
}





function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

// ---
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
	Revised to support looking for multiple class names,
	no matter in which order they're applied to the element
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
// ---
// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
// ---
/*
	Examples of how to call the function:

	To get all a elements in the document with a "info-links" class:
    getElementsByClassName(document, "a", "info-links");

	To get all div elements within the element named "container", with a "col" and a "left" class:
    getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]);
*/
// ---





// 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', externalLinks);
EventManager.Add(window,'load', startCarousel);
EventManager.Add(window,'load', noJavascript);