var Airbag = {
	init : function() {
		var c = Airbag;
		var p = c.Project;
		var u = c.Utility;

		u.addLoadEvent(function() {
			if (u.isCompatible()) {
				// List function(s) to fire onload here
				p.tagIt();

				if (window.attachEvent && !window.XMLHttpRequest) {
					p.ieNav();
				}
			}
		});
	}

	,Config : {
		sHoverClass : "ie-hover"
		,sHTMLtag : "can-has-js"
		,sImgPath : "/-/img/"
	}

	/*
		CLIENT-SPECIFIC FUNCTIONS
	*/
	,Project : {
		ieNav : function() {
			var c = Airbag;
			var p = c.Project;
			var u = c.Utility;

			var oNav = [];
			var oLi = document.getElementById("menu").getElementsByTagName("li");

			for (var i = 0; i < oLi.length; i++) {
				if (u.wordFind("top", oLi[i].className)) {
					oNav.push(oLi[i]);
				}
			}

			if (oNav.length) {
				p.sfHover(oNav, c.Config.sHoverClass);
			}
		}

		,sfHover : function(oEls, sClass) {
			var c = Airbag;
			var u = c.Utility;

			for (var i = 0; i < oEls.length; i++) {
				oEls[i].onmouseover = function() {
					this.className = u.safeAppend(this.className, sClass);
				}

				oEls[i].onmouseout = function() {
					this.className = u.wordReplace(sClass, "", this.className);
				}
			}
		}

		,tagIt : function() {
			var c = Airbag;
			var u = c.Utility;

			var oHtml = document.getElementsByTagName("html")[0];

			if (oHtml) {
				oHtml.className = u.safeAppend(oHtml.className, c.Config.sHTMLtag);
			}
		}
	}

	/*
		UTILITY FUNCTIONS
	*/
	,Utility : {
		addLoadEvent : function(func) {
			var oldonload = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = func;
			} else {
				window.onload = function() {
					oldonload();
					func();
				}
			}
		}

		,isCompatible : function() {
			if (document.getElementById && document.getElementsByTagName && document.createElement) {
				return true;
			} else {
				return false;
			}
		}

		,safeAppend : function(target, str) {
			target += (target.length > 0 ? " ": "") + str;
			return target;
		}

		,wordFind : function(needle, haystack) {
			return haystack.match(needle + "\\b");
		}

		,wordReplace : function(oldNeedle, newNeedle, haystack) {
			return haystack.replace(new RegExp(oldNeedle + "\\b", "g"), newNeedle);
		}
	}
};

Airbag.init();