//--- Ensight Source Code (ESC)
//--- First Created on Friday, January 8 2010 by John Ginsberg (snowed in)
//--- For Ensight 4

//--- Module Name: iloader.js
//--- Contains: v1.0

//--- Modified by:
//--- Modified by:

//--- Description:
//--- Loads other Javascript functions, ensures no duplication

//--- Notice:
//--- This code is copyright (C) 2010, Ensight Ltd. All rights
//--- are reserved. Using this code in any shape or form requires permission
//--- from Ensight Ltd - http://www.ensight.co.uk

//----------------------------------------------------------------

var _jsLibLoaded = new Array ();
var _jsLibDefaultPath = "/live/pagebuilder/components/shared/";

function _jsLibLoader (urls) {
//--- Load one or more external javascript libraries; always pass in an array

	for (i = 0; i < urls.length; i++) {
		if (_jsLibLoaded[urls[i]]) {
			continue; // don't load more than once
		}
		newElement = document.createElement ("script");
		newElement.type = "text/javascript";
		newElement.src = (urls[i].indexOf ('/') == -1 ? _jsLibDefaultPath : '') + urls[i];
		document.getElementsByTagName("head")[0].appendChild (newElement);
		_jsLibLoaded[urls[i]] = true;
	}

}

function _onBodyReady (fPointer) {
//--- Sets the specified function to run when the body is ready (before onload)

	if (document.addEventListener) {
		document.addEventListener ('DOMContentLoaded', fPointer, false);
	}

	(function() {
		/*@cc_on
		try {
			document.body.doScroll ('up');
			return fPointer ();
		} catch(e) {}
		/*@if (false) @*/
		if (/loaded|complete/.test (document.readyState)) return fPointer ();
		/*@end @*/
		if (!fPointer.done) setTimeout (arguments.callee, 30);
	})();

	if (window.addEventListener) {
		window.addEventListener ('load', fPointer, false);
	} else
	if (window.attachEvent) {
		window.attachEvent ('onload', fPointer);
	}

}
