var airbag = {
	init : function() {
		addLoadEvent(function() {
			// List function(s) to fire onload here
			airbag.test();
		});
	},

	/*
		Sample function - FPO
	*/
	test : function() {
		var something = true;
		return something;
	}
};

airbag.init();


/*-  Utility functions
----------------------------------------------------------------------*/
var utility = {
	isCompatible : function() {
		if (document.getElementById && document.getElementsByTagName && document.createElement) {
			return true;
		} else {
			return false;
		}
	},
	getParent : function (el, pTagName) {
		var c = unstoppabot;
		if (el == null) return null;
		else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
			return el;
		else
			return c.getParent(el.parentNode, pTagName);
	},
	safeAppend : function(target, str) {
		target += (target.length > 0 ? " ": "") + str;
		return target;
	},
	findWord : function(needle, haystack) {
		return haystack.match(needle + "\\b");
	},
	replaceWord : function(oldNeedle, newNeedle, haystack) {
		return haystack.replace(new RegExp(oldNeedle + "\\b", "g"), newNeedle);
	},
	getRandom : function(iMin, iMax) {
		return (Math.round(Math.random() * (iMax - iMin))) + iMin;
	},
	removeChildren : function(el) {
		if (el.hasChildNodes()) {
			while (el.firstChild) {
				el.removeChild(el.firstChild);
			}
		}
	},
	evt : function(el, mode, func, bool) {
		bool = (bool) ? true : false;
		if (el.addEventListener) {
			el.addEventListener(mode, func, bool)
		} else if (el.attachEvent) {
			el.attachEvent("on" + mode, func);
		}
	},
	pop : function(evt) {
		var evt = evt || getEventObject(evt);
		if (evt.stopPropagation) {
			evt.stopPropagation();
		} else {
			evt.cancelBubble = true;
		}
	},
	getElementsByClassName : function(className, tag, elm) {
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		return returnElements;
	},
	isSafari : function() {
		return test = (document.childNodes && !document.all && !navigator.taintEnabled) ? true : false;
	},
	isOpera : function() {
		return test = (window.opera) ? true : false;
	}
}

/*
	Find next/previous object.
	Brilliant methods by http://doiop.com/prevnext
*/
Object.prototype.nextObject = function() {
	var n = this;
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}
 
Object.prototype.previousObject = function() {
	var p = this;
	do p = p.previousSibling;
	while (p && p.nodeType != 1);
	return p;
}


/*
	Add Load Event (aka "Simon Willison is a goddamn rockstar")
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/*
	PNG fixes ()
*/
function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("div");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
	}
}
