/*
	core eNews JavaScript Include file
	written by Michael Murphy - 2007
*/

/*
	eNews NAMESPACE
*/

var eNews = {
	
	Version: "20090922",
	DebugMode: "false",
	jsPath: "js/",
	URL: "http://pic.katyisd.org/",
	domain: ".katyisd.org",
	coreFiles: ["utils.js","cookies.js"],
	
	require: function(scriptName){
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = eNews.jsPath + scriptName;
		document.getElementsByTagName('head')[0].appendChild(script);
	},
	
	load: function() {
		// require Prototype 1.5.0 or greater
		if ((typeof Prototype=='undefined')||(typeof Element == 'undefined')||(typeof Element.Methods=='undefined')||parseFloat(Prototype.Version.split(".")[0]+"."+Prototype.Version.split(".")[1]) < 1.5)
		{
    	throw("eNews requires the Prototype JavaScript framework >= 1.5.0");
		}
		
		// add a debug div to the bottom of any page using the eNews library
		if (($('eNewsDebug') === null)&&(eNews.DebugMode == 'true')) {
			new Insertion.Bottom(document.getElementsByTagName("body")[0], "<div id='eNewsDebug'>DEBUGGER:</div>");
		}
		
		// change the version to change by the second if in debug mode to force script reloads in Firefox
		if (eNews.DebugMode == 'true'){
			eNews.Version = new Date().getTime().toString();
		} 
		
		// load the core files
		eNews.coreFiles.each( function(file){
			eNews.require(file + "?" + eNews.Version);	
		});
		// dynamicly load any specified includes
	    $A(document.getElementsByTagName("script")).findAll( function(s) {
	      return (s.src && s.src.match(/eNews\.js(\?.*)?$/));
	    }).each( function(s) {
			var includes = s.src.match(/\?.*load=([a-z,]*)/);
	      includes[1].split(',').each(
	       function(include) { eNews.require(include+'.js?'+eNews.Version); });
	    });
	},
	
	debug: function(msg){
		if (eNews.DebugMode != 'true'){ return; }
		var d = $("eNewsDebug");
		var htm = d.innerHTML;
		htm += "<br>" + msg;
		d.innerHTML = htm;
	}
};

// lock and load
window.onload = eNews.load;