﻿/// <reference path="jquery-1.6.1-vsdoc.js" />
//This file contains functionality which appears at the top of the document as all Document ready functionality is placed at the bottom of the HTML document
var Header = {

	Default: (function () {
		function init() {
			window.onload = Header.OnLoadMgr.RunOnLoad;
		}

		return {
			init: init
		}
	})(),

	OnLoadMgr: (function () {

		var LoadInitList = [];

		function AddFunction(func) {
			LoadInitList.push(func);
		}

		function RunOnLoad() {
			for (x = 0; x < LoadInitList.length; x++) {
				var tmpFunc = new Function(LoadInitList[x]);
				tmpFunc();
			}
		}

		return {
			AddFunction: AddFunction,
			LoadInitList: LoadInitList,
			RunOnLoad: RunOnLoad
		}

	})(),

	DocReadyMgr: (function () {

		var ReadyInitList = [];

		function FunctionExits(arr, obj) {
			if (!Array.indexOf) {
				Array.prototype.indexOf = function (obj) {
					for (var i = 0; i < this.length; i++) {
						if (this[i] == obj) {
							return i;
						}
					}
					return -1;
				}
			} else {
				return (arr.indexOf(obj) != -1);
			}
		}

		function AddFunction(func) {
			if (!FunctionExits(ReadyInitList, func)) {
				ReadyInitList.push(func);
			}
		}

		function Run() {
			for (x = 0; x < ReadyInitList.length; x++) {
				var tmpFunc = new Function(ReadyInitList[x]);
				tmpFunc();
			}
		}

		return {
			AddFunction: AddFunction,
			ReadyInitList: ReadyInitList,
			Run: Run
		}

	})(),

	// Functionality to do with @font-face
	FontFace: (function () {

		//Firefox 3.5+ (gecko 1.9.1 inference), hide content till load (or 3 seconds) to prevent FOUT
		function hideContent() {
			(function () {
				var g = document, c = g.documentElement, a = g.createElement("style");
				if (c.style.MozTransform === "") {
					a.textContent = ".these-fonts-should-match-the-font-face-selector-list {visibility:hidden}";
					c.firstChild.appendChild(a);
					function b() {
						a.parentNode && a.parentNode.removeChild(a)
					}
					addEventListener("load", b, false);
					setTimeout(b, 3000)
				}
			})();
		}

		return {
			hideContent: hideContent
		}

	})(),

	Utility: (function () {

		function setBodyClass(body, classToAdd) {
			var bodyClass = body.className;
			body.className = bodyClass === '' ? classToAdd : bodyClass += ' ' + classToAdd;
		}

		function scriptWrite(scriptSrc) {
			var script = document.createElement("script");
			script.type = "text/javascript";
			script.src = scriptSrc;
			document.getElementsByTagName("head")[0].appendChild(script);
		}

		function getCookie(Name) {
			var search = Name + "="
			var returnvalue = "";
			if (document.cookie.length > 0) {
				offset = document.cookie.indexOf(search)
				// if cookie exists
				if (offset != -1) {
					offset += search.length
					// set index of beginning of value
					end = document.cookie.indexOf(";", offset);
					// set index of end of cookie value
					if (end == -1) end = document.cookie.length;
					returnvalue = unescape(document.cookie.substring(offset, end))
				}
			}
			return returnvalue;
		}

		return {
			setBodyClass: setBodyClass,
			scriptWrite: scriptWrite,
			getCookie: getCookie
		}
	})()
}

Header.Default.init();
