+// written by Dean Edwards, 2005\r
+// with input from Tino Zijdel, Matthias Miller, Diego Perini\r
+// http://dean.edwards.name/weblog/2005/10/add-event/\r
+\r
+function addEvent(element, type, handler) {\r
+ // Modification by Tanny O'Haley, http://tanny.ica.com to add the\r
+ // DOMContentLoaded for all browsers.\r
+ if (type == "DOMContentLoaded" || type == "domload") {\r
+ addDOMLoadEvent(handler);\r
+ return;\r
+ }\r
+ \r
+ if (element.addEventListener) {\r
+ element.addEventListener(type, handler, false);\r
+ } else {\r
+ // assign each event handler a unique ID\r
+ if (!handler.$$guid) handler.$$guid = addEvent.guid++;\r
+ // create a hash table of event types for the element\r
+ if (!element.events) element.events = {};\r
+ // create a hash table of event handlers for each element/event pair\r
+ var handlers = element.events[type];\r
+ if (!handlers) {\r
+ handlers = element.events[type] = {};\r
+ // store the existing event handler (if there is one)\r
+ if (element["on" + type]) {\r
+ handlers[0] = element["on" + type];\r
+ }\r
+ }\r
+ // store the event handler in the hash table\r
+ handlers[handler.$$guid] = handler;\r
+ // assign a global event handler to do all the work\r
+ element["on" + type] = handleEvent;\r
+ }\r
+};\r
+// a counter used to create unique IDs\r
+addEvent.guid = 1;\r
+\r
+function removeEvent(element, type, handler) {\r
+ if (element.removeEventListener) {\r
+ element.removeEventListener(type, handler, false);\r
+ } else {\r
+ // delete the event handler from the hash table\r
+ if (element.events && element.events[type]) {\r
+ delete element.events[type][handler.$$guid];\r
+ }\r
+ }\r
+};\r
+\r
+function handleEvent(event) {\r
+ var returnValue = true;\r
+ // grab the event object (IE uses a global event object)\r
+ event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);\r
+ // get a reference to the hash table of event handlers\r
+ var handlers = this.events[event.type];\r
+ // execute each event handler\r
+ for (var i in handlers) {\r
+ this.$$handleEvent = handlers[i];\r
+ if (this.$$handleEvent(event) === false) {\r
+ returnValue = false;\r
+ }\r
+ }\r
+ return returnValue;\r
+};\r
+\r
+function fixEvent(event) {\r
+ // add W3C standard event methods\r
+ event.preventDefault = fixEvent.preventDefault;\r
+ event.stopPropagation = fixEvent.stopPropagation;\r
+ return event;\r
+};\r
+fixEvent.preventDefault = function() {\r
+ this.returnValue = false;\r
+};\r
+fixEvent.stopPropagation = function() {\r
+ this.cancelBubble = true;\r
+};\r
+\r
+// End Dean Edwards addEvent.\r
+\r
+// Tino Zijdel - crisp@xs4all.nl This little snippet fixes the problem that the onload attribute on \r
+// the body-element will overwrite previous attached events on the window object for the onload event.\r
+if (!window.addEventListener) {\r
+ document.onreadystatechange = function(){\r
+ if (window.onload && window.onload != handleEvent) {\r
+ addEvent(window, 'load', window.onload);\r
+ window.onload = handleEvent;\r
+ }\r
+ }\r
+}\r
+\r
+// Here are my functions for adding the DOMContentLoaded event to browsers other\r
+// than Mozilla.\r
+\r
+// Array of DOMContentLoaded event handlers.\r
+window.onDOMLoadEvents = new Array();\r
+window.DOMContentLoadedInitDone = false;\r
+\r
+// Function that adds DOMContentLoaded listeners to the array.\r
+function addDOMLoadEvent(listener) {\r
+ window.onDOMLoadEvents[window.onDOMLoadEvents.length]=listener;\r
+}\r
+\r
+// Function to process the DOMContentLoaded events array.\r
+function DOMContentLoadedInit() {\r
+ // quit if this function has already been called\r
+ if (window.DOMContentLoadedInitDone) return;\r
+\r
+ // flag this function so we don't do the same thing twice\r
+ window.DOMContentLoadedInitDone = true;\r
+\r
+ // iterates through array of registered functions \r
+ for (var i=0; i<window.onDOMLoadEvents.length; i++) {\r
+ var func = window.onDOMLoadEvents[i];\r
+ func();\r
+ }\r
+}\r
+\r
+function DOMContentLoadedScheduler() {\r
+ // quit if the init function has already been called\r
+ if (window.DOMContentLoadedInitDone) return true;\r
+ \r
+ // First, check for Safari or KHTML.\r
+ // Second, check for IE.\r
+ //if DOM methods are supported, and the body element exists\r
+ //(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] \r
+ //in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)\r
+ if(/KHTML|WebKit/i.test(navigator.userAgent)) {\r
+ if(/loaded|complete/.test(document.readyState)) {\r
+ DOMContentLoadedInit();\r
+ } else {\r
+ // Not ready yet, wait a little more.\r
+ setTimeout("DOMContentLoadedScheduler()", 250);\r
+ }\r
+ } else if(document.getElementById("__ie_onload")) {\r
+ return true;\r
+ } else if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {\r
+ DOMContentLoadedInit();\r
+ } else {\r
+ // Not ready yet, wait a little more.\r
+ setTimeout("DOMContentLoadedScheduler()", 250);\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+// Schedule to run the init function.\r
+setTimeout("DOMContentLoadedScheduler()", 250);\r
+\r
+// Just in case window.onload happens first, add it there too.\r
+addEvent(window, "load", DOMContentLoadedInit);\r
+\r
+// If addEventListener supports the DOMContentLoaded event.\r
+if(document.addEventListener)\r
+ document.addEventListener("DOMContentLoaded", DOMContentLoadedInit, false);\r
+\r
+/* for Internet Explorer */\r
+/*@cc_on @*/\r
+/*@if (@_win32)\r
+ document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");\r
+ var script = document.getElementById("__ie_onload");\r
+ script.onreadystatechange = function() {\r
+ if (this.readyState == "complete") {\r
+ DOMContentLoadedInit(); // call the onload handler\r
+ }\r
+ };\r
+/*@end @*/\r