/**
 * FastInit
 *
 * @link http://tetlaw.id.au/view/javascript/fastinit
 * @link http://dean.edwards.name/weblog/2006/03/faster
 * @link http://dean.edwards.name/weblog/2006/06/again/
 * @link http://www.cherny.com/webdev/26/domloaded-object-literal-updated
 */
FastInit = {
    f:     [],
    done:  false,
    timer: null,
    iew32: false,


    /**
     * @access public
     * @static
     */
    onload: function() {
        if ( FastInit.done ) {
            return;
        }

        FastInit.done = true;

        for ( var x = 0, al = FastInit.f.length; x < al; x++ ) {
            FastInit.f[x]();
        }
    },

    /**
     * @access public
     * @static
     */
    addOnLoad: function() {
        var a = arguments;

        for ( var x = 0, al = a.length; x < al; x++ ) {
            if ( typeof a[x] === 'function' ) {
                if ( FastInit.done ) {
                    a[x]();
                } else {
                    FastInit.f.push( a[x] );
                }
            }
        }
    },

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

/*@cc_on @*/
/*@if (@_win32)
FastInit.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' ) {
        FastInit.onload();
    }
};
/*@end @*/

FastInit.listen();