// window.onload is soooo '90s! - http://www.volkanozcelik.com/cre8/blog/2006/06/windowonload-is-soooo-90s.html

// call the script with a snippet of code like this
//
//        <script type="text/javascript">
//          function init() 
//            { 
//              //function or js code to execute on body load
//            }
//          quickLoad(init);
//        </script>
//

var DomLoadController= {
 index:0,
 sanityLimit:50,
 interval:-1,
 retryMilli:256
}

function executeWhenReady(fnDelegate)
  {
    DomLoadController.index++;
    if(typeof document.getElementsByTagName != 'undefined' &&
      (document.getElementsByTagName('body')[0] != null ||
      document.body != null))
      {
        fnDelegate();
        clearInterval(DomLoadController.interval);
      }

    if(DomLoadController.index >= DomLoadController.sanityLimit)
      {
        clearInterval(DomLoadController.interval);
        //if you exceed the sanity limit, try to load the
        //function using traditional mehtods,
        //attaching an EventHandler to window load.
        //Note that _.chain is a utility method of s@rdalya
        _.chain(window,"load",fnDelegate);
      }
  }

function quickload(fnDelegate)
  {
    DomLoadController.interval = setInterval(
    function() { executeWhenReady(fnDelegate); }
    ,DomLoadController.retryMilli);
  }