Script: Window.DomReady.js
3 	        Contains the custom event domready, for window.
4 	
5 	License:
6 	        MIT-style license.
7 	*/
8 	
9 	/* Section: Custom Events */
10 	
11 	/*
12 	Event: domready
13 	        executes a function when the dom tree is loaded, without waiting for images. Only works when called from window.
14 	
15 	Credits:
16 	        (c) Dean Edwards/Matthias Miller/John Resig, remastered for MooTools.
17 	
18 	Arguments:
19 	        fn - the function to execute when the DOM is ready
20 	
21 	Example:
22 	        > window.addEvent('domready', function(){
23 	        >       alert('the dom is ready');
24 	        > });
25 	*/
26 	
27 	Element.Events.domready = {
28 	
29 	        add: function(fn){
30 	                if (window.loaded){
31 	                        fn.call(this);
32 	                        return;
33 	                }
34 	                var domReady = function(){
35 	                        if (window.loaded) return;
36 	                        window.loaded = true;
37 	                        window.timer = $clear(window.timer);
38 	                        this.fireEvent('domready');
39 	                }.bind(this);
40 	                if (document.readyState && window.webkit){
41 	                        window.timer = function(){
42 	                                if (['loaded','complete'].contains(document.readyState)) domReady();
43 	                        }.periodical(50);
44 	                } else if (document.readyState && window.ie){
45 	                        if (!$('ie_ready')){
46 	                                var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
47 	                                document.write('<script id="ie_ready" defer src="' + src + '"><\/script>');
48 	                                $('ie_ready').onreadystatechange = function(){
49 	                                        if (this.readyState == 'complete') domReady();
50 	                                };
51 	                        }
52 	                } else {
53 	                        window.addListener("load", domReady);
54 	                        document.addListener("DOMContentLoaded", domReady);
55 	                }
56 	        }
57 	
58 	};
