/*////////////////////////////////////////////////////////////
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
////////////////////////////////////////////////////////////*/



// Tracking for SEO
var ns_data,ns_hp,ns_tz,ns_rf,ns_sr,ns_img,ns_pageName;
ns_pageName= this.location;
document.cookie='__support_check=1';ns_hp='http';
ns_rf=document.referrer;ns_sr=window.location.search;
ns_tz=new Date();if(location.href.substr(0,6).toLowerCase() == 'http:')
ns_hp='http';ns_data='&an='+escape(navigator.appName)+ 
'&sr='+escape(ns_sr)+'&ck='+document.cookie.length+
'&rf='+escape(ns_rf)+'&sl='+escape(navigator.systemLanguage)+
'&av='+escape(navigator.appVersion)+'&l='+escape(navigator.language)+
'&pf='+escape(navigator.platform)+'&pg='+escape(ns_pageName);
ns_data=ns_data+'&cd='+screen.colorDepth+'&rs='+escape(screen.width+ ' x '+screen.height)+
'&tz='+ns_tz.getTimezoneOffset()+'&je='+ navigator.javaEnabled();
ns_img=new Image();ns_img.src=ns_hp+'://tracker.statgauge.com/statistics.aspx'+
'?v=1&s=213&acct=226764'+ns_data+'&tks='+ns_tz.getTime();



// 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 = "Arthur's Pizza";
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>');
}



// 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("href") && 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.className == "u") {
			anchor.onclick = anchor.onclick = function () {
				alert('Coming Soon!');
				return false;
			}
		}

	}
}



// Upside Down Text
function flip() {
	var result = flipString("arthur's pizza");
	document.getElementById('upside-down').getElementsByTagName('a')[0].innerHTML = result;
}

function flipString(aString) {
	var last = aString.length - 1;
	var result = new Array(aString.length)
	for (var i = last; i >= 0; --i) {
		var c = aString.charAt(i)
		var r = flipTable[c]
		result[last - i] = r != undefined ? r : c
	}
	return result.join('')
}

var flipTable = {
	a : '\u0250',
	b : 'q',
	c : '\u0254',
	d : 'p',
	e : '\u01DD',
	f : '\u025F',
	g : '\u0183',
	h : '\u0265',
	i : '\u0131',
	j : '\u027E',
	k : '\u029E',
	l : '\u05DF',
	m : '\u026F',
	n : 'u',
	r : '\u0279',
	t : '\u0287',
	v : '\u028C',
	w : '\u028D',
	y : '\u028E',
	'.' : '\u02D9',
	'[' : ']',
	'(' : ')',
	'{' : '}',
	'?' : '\u00BF',
	'!' : '\u00A1',
	"\'" : ',',
	'<' : '>',
	'_' : '\u203E',
	'"' : '\u201E',
	'\\' : '\\',
	';' : '\u061B',
	'\u203F' : '\u2040',
	'\u2045' : '\u2046',
	'\u2234' : '\u2235'
}

for (i in flipTable) {
	flipTable[flipTable[i]] = i
}



// Converts to Title Case
function capitalizeNames(str) {
	str = str.replace(/ +/g,' ');
	var names = str.split(' ');
	for(var i = 0; i < names.length; i++) {
		if(names[i].length > 1) {
			// Killed because of "BBQ"
			// names[i] = names[i].toLowerCase();
			letters = names[i].split('');
			letters[0] = letters[0].toUpperCase();
			names[i] = letters.join('');
		} else { names[i] = names[i].toUpperCase(); }
	}
	str = names.join(' ');
	return str;
}



// Toggle Function
function toggle(obj) {
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}



// Pop Up Generic Window
function Popup(ref, s, w, h) {
	window.open(ref, 'newWin', 'resizable=1,scrollbars=' + s + ',width=' + w + ',height=' + h + '');
}



// Pop Up Image Window
function PopupPic(sPicURL) {
	window.open('image.html?'+sPicURL, 'imagePopUp', 'resizable=1,width=20,height=20');
}



function cssClass(action,object,class1,class2) {
	// swap 		replaces class class1 with class class2 in object.
	// add 			adds class class1 to the object.
	// remove 	removes class class1 from the object.
	// check 		test if class class1 is already applied to object and returns true or false.
	switch (action) {
		case 'swap':
		object.className=!cssClass('check',object,class1)?object.className.replace(class2,class1): object.className.replace(class1,class2);
	break;
	case 'add':
		if(!cssClass('check',object,class1)){object.className+=object.className?' '+class1:class1;}
	break;
	case 'remove':
		var rep=object.className.match(' '+class1)?' '+class1:class1;
		object.className=object.className.replace(rep,'');
	break;
	case 'check':
		return new RegExp('\\b'+class1+'\\b').test(object.className)
	break;
	}
}



// 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;
}



// Global Cookie Function
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	setCookie(name,'',-1);
}



// 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', externalLinks);
EventManager.Add(window,'load', flip);