var DomReady = {

    onload : function() {
        if (DomReady.done) { return; }
        DomReady.done = true;
        for(var x = 0, al = DomReady.f.length; x < al; x++) {
            if(typeof DomReady.f[x] === 'function') DomReady.f[x].apply();
            else DomReady.f[x]();
        }
    },

    add : function() {
        var a = arguments;
        for(var x = 0, al = a.length; x < al; x++) {

            if(typeof a[x] === 'function') {
                if (DomReady.done ) {
                    a[x]();
                } else {
                    DomReady.f.push(a[x]);
                }
            }
        }
    },

    listen : function() {
        if (/WebKit|khtml/i.test(navigator.userAgent)) {
            DomReady.timer = setInterval(function() {
                if (/loaded|complete/.test(document.readyState)) {
                    clearInterval(DomReady.timer);
                    delete DomReady.timer;
                    DomReady.onload();
                }}, 10);
        } else if (document.addEventListener) {
            document.addEventListener('DOMContentLoaded', DomReady.onload, false);
        } else if(!DomReady.iew32) {
            if(window.addEventListener) {
                window.addEventListener('load', DomReady.onload, false);
            } else if (window.attachEvent) {
                return window.attachEvent('onload', DomReady.onload);
            }
        }
    },

    f:[],
    done:false,
    timer:null,
    iew32:false   
};

/*@cc_on @*/
/*@if (@_win32)
DomReady.iew32 = true;
document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');
document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { DomReady.onload(); }};
/*@end @*/

DomReady.listen();
