
/*  JSLibrary JavaScript framework, version 0.1.8
 *  Copyright (c) 2005 Mark Kahn <cwolves@cwolves.com>
 *
 *  JSLibrary is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the JSLibrary web site: http://www.jslibrary.org/
 *
 *  Major Function Changes:
 *  -----------------------
 *  0.10
 *    Initial release
 *
 *  0.20
 *    re-structured the ModuleList object: added functions to it and made it global and
 *          removed it's definition from generalNamespace() for usability
 *    rewrote load() - can now load external scripts, and will attempt to load anything
 *    Functionally changed w.load() to use XMLHTTP instead of <script>
 *    mapped gid() to $() per prototype
 *    added the AutoLoad namespace, effectively dropping the requirement to pre-load modules
 *          for modules/functions defined in ModuleList
 *    moved isChildOf, getToParent, getFirstSib, cE, cTN, aC, sA, gA from being prototype of
 *          objects to being stand-alone functions.
 *    per the above, dropped w.addPrototypes
 *    added $A - now required to call functions with an object as first argument:
 *          myfunction({}, $A);
 *    removed the Browser object to it's own .js file and included necessary functionality
 *    Added the JSLibrary object
 *    re-wrote prepArgs function and added some error-handling for the parent function to it
 *    added w.addUnload function to replace addEvent(w, 'unload', );
 *    fixed DOM Leak in w.getXMLHttpObj with help from Drip
 *    w.uD and w.uDN now check n arguments
 *    gid() now checks n arguments and returns an array if >1 argument
 *
 *--------------------------------------------------------------------------*/

/*
to do:

try these
dynamically add styles

IE:
	onload htc:  body {behavior: url(loaded.htc);}
mozilla:
	if (document.addEventListener) {
		 document.addEventListener("DOMContentLoaded", init, null);
	}
other:
	window.onload
*/

/*
General
-------
Some general documentation...

The library should be loaded by including general.js in your page.  The script assumes that all .js files are
located in /JSLibrary/.  If this is not the case, the xLibPath variable must be set -BEFORE- loading general.js:

xLibPath = "/scripts/jslibrary/";

After this is done, modules are loaded with the load() function:

load('imagecache');

Many modules, however, don't need to be loaded before you can use them.  You can simply call functions in those
modules and the module will automatically load when it is needed.  This is accomplished with the autoLoadNamespace
which pre-defines many functions as calls to their .js files and then re-calls to the functions, along with help
from the prepArgs function.  As long as all functions are written with prepArgs, they can be called like this.

random variable and global function stuff:

w           = window
_           = null
b           = body
$A          = helper object for prepArgs
gid or $    = basically a robust, cached document.getElementById function

addEvent    = add an event to an object
removeEvent =
fireEvents  =
cloneEvents =
flushEvents =
addUnload   = equivalent of addEvent(w, 'unload', ...)
*/

/*
Object: JSLibrary
-----------------
missingArgs: Error message to throw when required arguments are not supplied.  {f} = function name.

preload:     Determines if specific modules should be loaded before they are called.
             Can speed things up when executing, but can also unnecessarily load code that you never use.

xLibPath:    Directory where all .js files are stored.  Can be overridden with a global xLibPath variable.
*/

JSLibrary = {
	version     : '0.1.8',
	missingArgs : 'Error in {f}: required arguments not provided.',
	preload     : false,
	xLibPath    : '/JSLibrary/'
};

if(typeof(xLibPath)!='undefined')
	JSLibrary.xLibPath = xLibPath;


window.w = window;
w._      = null;

/*
Object: Module List
-------------------
List of modules that can be loaded.  Modify this if adding code!

functions:  list of functions to be "pre-loaded".  Note that none of these functions are actually loaded,
            but they can still be called just as if they were.  The javascript file containing the function
			   is called on the first call to that function.

extensions: list of javascript files that provide necessary code to it's parent.  Only one of these is loaded.
            Used for things like seperate databases

files:      If the parent "file" is actually a folder (for organization), files should contain a list of the
            actual files in the directory, with nested functions, extensions, files, etc.
*/
var moduleList  = {
	animation : {
		functions : {
			queueAnimation: _
		}
	},
	autocomplete: _,
	array       : _,
	colorpicker : {
		functions : {
			addColorPicker: _
		}
	},
	cookies : {
		functions : {
			writeCookie: _,
			readCookie : _,
			eraseCookie: _
		}
	},
	datatable : {
		extensions : {
			mssql : 'mssqlnode',
			mysql : 'mysqlnode'
		}
	},
	domhelpers : {
		functions : {
			cE                     : _,
			cTN                    : _,
			getToParent            : _,
			getFirstSib            : _,
			isChildOf              : _,
			removeAllChildren      : _,
			aC                     : _,
			sA                     : _,
			gA                     : _,
			getElementsByClassName : _
		}
	},
	drag : {
		functions : {
			newDrag: _
		}
	},
	filesystem   : _,
	firefox      : _,
	formvalidate : {
		functions : {
			loadFromQueryString : _,
			addDefault          : _,
			addRequired         : _,
			addValidation       : _,
			addSelectAll        : _,
			addStartVal         : _,
			addSubmit           : _,
			setValue            : _,
			getValue            : _
		}
	},
	geocode : {
		functions:{
			getGeoCodePoint: _
		}
	},
	googlemaps : {
		files : {
			gbound              : _,
			googlemaps          : _,
			googlemapsapi1      : _,
			googlemapsapi2      : _,
			gpoint              : _,
			gpolylinewrapper    : _,
			xarrowcontroller    : _,
			xarrow              : _,
			xarrowshape         : _,
			xdebug              : _,
			xdistanceangle      : _,
			xicon               : _,
			xiconshape          : _,
			ximagefactory       : _,
			xmaps               : _,
			xmarker             : _,
			xmodel              : _,
			xpatterncontroller  : _,
			xpngimagefactory    : _,
			xpolygon            : _,
			xpolyline           : _,
			xpolylinecontroller : _,
			xsegmentedpolylinecontroller : _,
			xtextcontroller     : _,
			xuseragent          : _
		}
	},
	hex : {
		functions : {
			hex : _
		}
	},
	imagerollovers  : {
		functions : {
			addRollover : _
		}
	},
	images : {
		functions : {
			newImage : _
		}
	},
	keyboard : {
		functions : {
			keyCode : _
		}
	},
	mask : {
		functions : {
			onlyUpperCase : _,
			onlyLowerCase : _,
			addMask       : _
		}
	},
	mouse : {
		functions : {
			mouseCoords : _
		}
	},
	multiselectbox : {
		functions : {
			addMultiSelectBox : _
		}
	},
	number : _,
	positioning : {
		functions : {
			getPos      : _,
			getViewSize : _
		}
	},
	querystring : {
		functions : {
			queryString  : _,
			queryStrings : _
		}
	},
	quicksort : {
		functions : {
			quickSort : _
		}
	},
	resize : {
		functions : {
			addResize : _
		}
	},
	screenposition : {
		functions : {
			adjustScreenPosition : _
		}
	},
	scrollbars : {
		functions : {
			newScrollBar : _
		}
	},
	starlight : _,
	string    : _,
	styles    : {
		functions : {
			sFloat           : _,
			importStyleSheet : _
		}
	},
	tooltip : {
		functions : {
			setTooltipTimeout : _,
			setTooltipMode    : _,
			addTooltip        : _
		}
	},
	xml : {
		functions : {
			newXMLDocument : _
		}
	},
	xmlformvalidate : {
		functions : {
			XMLAddValidation : _,
			XMLLoadSelect    : _,
			XMLLoadFields    : _
		}
	}
};

w.d      = document;
d.w      = d.write;
w.pb     = d.documentElement;
w.b      = d.documentElement;
w.$A     = {};	// helper object.  Simply exists to check (===) against it.

Browser = {
	moz: (document.implementation && document.implementation.createDocument)?true:false
}

__=function stringNamespace(){
	String.prototype.supplant=function(o){
		var s=this;
		for(i in o) s=s.replace(new RegExp('{'+i+'}','gi'), o[i]);
		return s;
	}
}();

/*
Namespace: types
------------------------------
adds isType functions.  They do exactly what they sould like:

w.isAlien
w.isArray
w.isBool
w.isEmpty
w.isFunction
w.isNull
w.isNumber
w.isObject
w.isString
w.isUndefined
------------------------------
*/
__=function typesNamespace(){
	w.isAlien = function(a){
		return isObject(a) && typeof a.constructor!='function';
	}
	w.isArray = function(a){
		return isObject(a) && a.constructor==Array;
	}
	w.isBool = function(a){
		return typeof a=='boolean';
	}
	w.isEmpty = function(o){
		if(isObject(o)){
			for(var i in o){
				var v=o[i];
				if(isUndefined(v) && isFunction(v)){
					return false;
				}
			}
		}
		return true;
	}
	w.isFunction = function(a){
		return typeof a=='function';
	}
	w.isNull = function(a){
		return typeof a=='object' && !a;
	}
	w.isNumber = function(a){
		return typeof a=='number' && isFinite(a);
	}
	w.isObject = function(a){
		return (a && typeof a=='object') || isFunction(a);
	}
	w.isString = function(a){
		return typeof a=='string';
	}
	w.isUndefined = function(a){
		return typeof a=='undefined';
	}
}();

/*
Namespace: necessary functions
------------------------------
functions that need to be defined before -anything- else simply because they're used everywhere.
------------------------------
*/
__=function necessaryNamespace(){  // great name, no?
	var setBody = false;

	/*
	Function: undefined [w.uD]
	--------------------------
	returns true if object(s) are undefined
	--------------------------
	*/
	function uD(){
		for(var i=arguments.length-1; i>=0; i--)
			if(typeof(arguments[i])=='undefined')
				return true;
		return false;
	}

	/*
	Function: undefined or null [w.uDN]
	-----------------------------------
	returns true if object(s) are undefined or null
	-----------------------------------
	*/
	function uDN(){
		for(var i=arguments.length-1; i>=0; i--)
			if(uD(arguments[i])||(arguments[i]==_))
				return true;
		return false;
	}

	function sB(){
		if(setBody||!document.body) return;
		w.b     = document.body;
		setBody = true;
	}

	/*
	Function: prepare arguments [w.prepArgs]
	----------------------------------------
	internal function that prepares function arguments
	----------------------------------------
	 0  : arguments
	 1  : array of argument names
	[2] : arguments that need to be arrays
	[3] : name of calling function
	[4] : arguments that are required
	*/
	function pA(){
		sB(); // set the b=body (if it hasn't already been done) before doing anything!

		var result   = {};

		var args     = arguments[0];
		var names    = arguments[1];
		var arrays   = arguments[2];
		var caller   = arguments[3];
		var required = arguments[4];

		if(args[0] && args[0].callee) args=args[0];

		if((args.length>0) && (args[1]===$A)){
			for(n in args[0])
				result[n] = args[0][n];
		} else if(isArray(names)) {
			for(var i=0; i<names.length; i++)
				result[names[i]] = args[i];
		} else {
			result = [];
			for(var i=0; i<args.length; i++)
				result[i] = args[i];
		}
		if(!uDN(required))
			for(var i=0; i<required.length; i++)
				if(uD(result[required[i]])){
					if(!uDN(caller)) throwError(JSLibrary.missingArgs.supplant({f: caller}));
					return false;
				}
		if(!uDN(arrays))
			for(var i=0; i<arrays.length; i++)
				if(!isArray(result[arrays[i]]))
					result[arrays[i]] = uD(result[arrays[i]])?[]:[result[arrays[i]]];

		return result;
	}

	w.prepArgs = pA;
	w.uD       = uD;
	w.uDN      = uDN;
}();

/*
Namespace: event cache
----------------------
caches events so that more than one event per action can be added, and events can be removed.
Also, all events on an object can be fired by command and cloned.

will be re-written soon!
----------------------
*/
__=function eventCacheNamespace(){
	/*
	Function: add event [w.addEvent]
	--------------------------------
	add an event to an object
	--------------------------------
	 0 o  : object
	 1 e  : event
	 2 f  : function
	[3 c] : clear previous o.e events
	*/
	function aE(){
		var A = prepArgs(arguments, ['o', 'e', 'f', 'c']);
		if(uDN(A.o)){ return; }

		if(!isArray(A.e))A.e=[A.e];

		for(var i=0; i<A.e.length; i++){
			if(eventCache.eE(A.o, A.e[i], A.f)) return;
			if(A.c) eventCache.flush(A.o, A.e[i]);
			if(A.o.attachEvent){
				A.o.attachEvent("on"+A.e[i], A.f);
			}else if(A.o.addEventListener){
				A.o.addEventListener(A.e[i], A.f, true);
			}else if(typeof A.o[A.e[i]]=="function"){
				var pfn  = A.o[A.e];
				A.o[A.e[i]] = function(e){
					pfn(e);
					A.f(e);
				}
			}else{
				A.o[A.e[i]]=A.f;
			}
			eventCache.add(A.o, A.e[i], A.f, true);
		}
	}

	function aU(f){
		aE(w, 'unload', f);
	}

	/*
	Function: remove event [w.removeEvent]
	--------------------------------------
	remove an event from an object
	--------------------------------------
	0 o :
	1 e :
	2 f :
	*/
	function rE(o,e,f){
		if(o.detachEvent){
			o.detachEvent("on"+e,f);
		}else if(o.removeEventListener){
			o.removeEventListener(e, f, true);
		}else if(typeof o[e]=="function"){
			o[e]=null;
		}
	}

	/*
	Object: event cache
	-------------------
	-------------------
	*/
	var eventCache = function(){
		var listEvents = [];

		return {
			listEvents:listEvents,

			/*
			Function: add event [not exposed]
			---------------------------------
			0 node
			1 sEventName
			2 fHandler
			3 bCapture
			*/
			add:function(){
				listEvents.push(arguments);
			},

			/*
			Function: event exists [not exposed]
			------------------------------------
			*/

			eE:function(o,e,f){
				if(uD(o)||uD(e)||uD(f)) return false;
				for(var i=0; i<listEvents.length; i++){
					var item = listEvents[i];
					if((item[0]==o)&&(item[1]==e)&&(item[2]==f)) return true;
				}
				return false;
			},

			/*
			Function: fire events [w.fireEvents]
			------------------------------------
			executes any events attached to an object->event.
			------------------------------------
			0 o : object
			1 e : event
			*/
			fE:function(o,e){
				for(var i=0; i<listEvents.length; i++){
					var item = listEvents[i];
					if(!uD(o)&&!uD(e)&&item[0]!=o||item[1]!=e) continue;

					item[2]();
				}
			},

			/*
			Function: clone events [w.cloneEvents]
			--------------------------------------
			copies events from one object to another
			--------------------------------------
			0 s : source
			1 t : target
			*/
			clE:function(s,t){
				for(var i=0; i<listEvents.length; i++){
					var item = listEvents[i];
					if(uD(s)||uD(t)||item[0]!=s) continue;
					aE(t, item[1], item[2]);
				}
			},

			/*
			Function: flush events [w.flushEvents]
			--------------------------------------
			removes events from an object
			--------------------------------------
			 0 o  : source object
			[1 e] : event name
			*/
			flush:function(o,e){
				var i, item;
				for(i = listEvents.length - 1; i >= 0; i--){
					item = listEvents[i];
					if(!uD(o)&&!uD(e)&&item[0]!=o||item[1]!=e) continue;

					if(item[0].removeEventListener){item[0].removeEventListener(item[1], item[2], item[3]);};
					if(item[1].substring(0, 2) != "on") item[1] = "on" + item[1];
					if(item[0].detachEvent) item[0].detachEvent(item[1], item[2]);

					item[0][item[1]] = _;
				}
			}
		};
	}();

	aU(function(){ eventCache.flush(); });

	w.fireEvents     = eventCache.fE;
	w.cloneEvents    = eventCache.clE;
	w.addEvent       = aE;
	w.addUnload      = aU;
	w.removeEvent    = rE;
	w.flushEvents    = eventCache.flush;
}();

/*
Namespace: general
------------------------------
general functions that are widely used by other modules

As of v0.1.8 and until this comment is removed, it's very possible that there is un-used code in here
due to the fact that a lot of this function has been re-written.
------------------------------
*/
__=function GeneralNamespace(){
	var l  = {};
	var dl = {};

	/*
	Function: done loading [w.doneLoading]
	--------------------------------------
	internal function that declares a javascript file is finished loading
	--------------------------------------
	*/
	function dL(s){
		dl[s.toLowerCase()] = 1;
		for(n in l) if(uD(dl[n])) return;
		fireEvents (w, 'scriptload');
		flushEvents(w, 'scriptload');
	}
	addEvent(w, 'load', function(){
		fireEvents (w, 'scriptload');
	});

	/*
	Function: load [w.load]
	-----------------------
	loads a specified module
	-----------------------
	 0 s  : string of module to load
	[1 e] : extension to load
	[2 r] : root
	[3 p] : path
	-----------------------
	load('module');
	load('path/path/module');
	load('module', 'extension');
	*/
	var ixx=0;
	function L(){
		var A=prepArgs(arguments, ['s', 'e', 'r', 'p', 'x'], _, _, ['s']);if(!A) return;

		A.r=A.r||moduleList;
		A.s=A.s.toLowerCase();
		A.e=(A.e||'').toLowerCase();
		A.p=(A.p||'').toLowerCase();
//if(!uDN(l[A.s])) window.status += l[A.s] + ' ' + A.s + ', ';


		if(!uDN(l[A.s])){
			return;
		}

		if(/^[fh]ttps?:\/\//.test(A.s)){	// load external script

		}

		while(A.s.indexOf('/')>=0){		// parse path out of string
			var ix = A.s.indexOf('/');
			var p  = A.s.substr(0, ix);
			if(uD(A.r[p])) break;
			A.r    = A.r[p].files||A.r[p];
			A.p   += p+'/';

			A.s    = A.s.substr(ix+1);
		}
		if(uD(A.r[A.s])){						// module doesn't exist where specified, so try and find it
			if(A.s.indexOf('/')>=0) A.s=A.s.substr(A.s.lastIndexOf('/')+1);

			var t = fM(A.s);
			if(t==-1) return; // module does not exist
			A.p=t.p;
			A.r=t.r;
		}
		if(!uDN(A.r[A.s])&&!uD(A.r[A.s].files)){
			var t = fM(A.s, A.r[A.s].files, A.p);
			A.p += A.s+'/'+t.p;
			A.r  = t.r;
		}

		lES(JSLibrary.xLibPath+A.p+(isString(A.r[A.s])?A.r[A.s]:A.s)+'.js?r='+Math.random(), A.x);

		l[A.s]=A.s;
	}

	/*
	Function: load and execute script [not exposed]
	-----------------------------------------------
	-----------------------------------------------
	0 : script path
	*/
	function lES(p, x){
		if(x){
			fetchXML(p, eS, false);
		} else {
			var scr     = cE('SCRIPT');
			d.getElementsByTagName('HEAD')[0].appendChild(scr);
			scr.src     = p;
		}
	}

	/*
	Function: execute script [not exposed]
	--------------------------------------
	--------------------------------------
	0 : XML
	*/
	function eS(x){
		eval(x.responseText);
	}

	/*
	Function: find module [not exposed]
	-----------------------------------
	-----------------------------------
	0 n : module name
	*/
	function fM(){
		var A=prepArgs(arguments, ['n', 'r', 'p'], _, _, ['n']);if(!A) return;

		A.r=A.r||moduleList;
		A.p=A.p||'';
		for(n in A.r){
			if(n==A.n) return {p:A.p, r:A.r};
			if(A.r[n]==_) continue;
			if(!uD(A.r[n].files)){
				var t = fM(A.n, A.r[n].files, A.p+n+'/');
				if(t!=-1) return t;
			}
		}
		return -1;
	}

	/*
	Function: write loaded [w.writeLoaded]
	--------------------------------------
	opens a dialog that shows all loaded modules
	--------------------------------------
	*/
	function wL(){
		throwError('general');
		for(n in l) throwError(l[n]);
	}

	/*
	Function: check loaded [w.loaded]
	---------------------------------
	checks if a specific module has been loaded
	---------------------------------
	*/
	function cL(s){
		return !uD(dl[s.toLowerCase()]);
	}

	/*
	Object: err
	-----------
	error handling object
	-----------
	*/
	var err = function(){
		var aDiv, bDiv, tNode, btn;
		/*
		Function: throw error [w.throwError]
		------------------------------------
		throw an error message
		------------------------------------
		 0 t  : error text
		[1 e] : element to put error text in
		[2 s] :
		*/
		function e(){
			var A=prepArgs(arguments, ['t', 'e', 's'], _, _, ['t']);if(!A) return;

			// changed && to || in if().  Not really sure why A.s is even here!  I think I added it for the USCellular project.  In any case, this change defaults A.e to true rather than false
			if(!uDN(A.s)||A.s){
				if(!uDN(A.e)){
					var eD=A.e.getAttribute('errortext');
					if(eD!=_)A.e=gid(eD);
					if(A.e.nodeName=='DIV'||A.e.nodeName=='SPAN'){
						A.e.innerText=t;
						return;
					}
				}
				return;
			}
			var s=d.getElementsByTagName('SELECT');
			if(uD(aDiv)){
				aDiv     = b.appendChild(cE('DIV'));
				bDiv     = b.appendChild(cE('DIV'));
				btn      = cE('button');
				w.errBtn = btn;
				addEvent(btn, 'click', function(){
					aDiv.style.display = bDiv.style.display = 'none';
					for(var i=aDiv.childNodes.length-1; i>=0; i--) if(aDiv.childNodes[i].nodeName=='DIV') aDiv.removeChild(aDiv.childNodes[i]);
					for(var i=0; i<s.length; i++){ s[i].style.visibility=gA(s[i], 'visibility'); sA(s[i], 'visibility', _); }

					fireEvents(w, 'reload');
				});
				aDiv.appendChild(btn);
				btn.appendChild(cTN('Continue'));
				btn.style.cssText  = 'border:1px solid #000;float:right;';
				bDiv.style.cssText = 'position:absolute;top:0px;left:0px;background-color:#000;opacity:0.5;moz-opacity:0.5;filter:alpha(opacity=50);';
				aDiv.style.cssText = 'height:auto;overflow:auto;width:50%;font-family:verdana,tahoma,sans-serif;color:#C00;font-size:11px;padding:5px;z-index:10;position:absolute;border:2px solid #444;background-color:#fff;';
			}
			btn.style.display = 'block';
			var vS = getViewSize();

			for(var i=0; i<s.length; i++){ s[i]; if(gA(s[i], 'visibility')!=_) continue; sA(s[i], 'visibility', s[i].style.visibility); s[i].style.visibility='hidden'; }
			var cTxt = document.createElement('DIV');
			var txt  = isString(A.t)?document.createTextNode(A.t):A.t;

			cTxt.style.cssText = 'float:left;width:100%;padding-bottom:5px;';
			aDiv.style.display = bDiv.style.display = 'block';
			aC(cTxt, txt);
			aC(aDiv, cTxt);
			aC(aDiv, btn);

			aDiv.style.top   =b.scrollTop +(vS.h-aDiv.scrollHeight)/2+'px';
			aDiv.style.left  =b.scrollLeft+(vS.w-aDiv.scrollWidth) /2+'px';
			bDiv.style.height=b.scrollHeight<vS.h?vS.h:pb.scrollHeight+'px';
			bDiv.style.width =b.scrollWidth<vS.h?vS.h:pb.scrollWidth+'px';

			btn.focus();
		}
		/*
		Function: clear error [w.clearError]
		------------------------------------
		clears the errors for an object
		------------------------------------
		*/
		function c(f){
			if(!uD(aDiv)) for(var i=aDiv.childNodes.length-1; i>=0; i--) if(aDiv.childNodes[i].nodeName=='DIV') aDiv.removeChild(aDiv.childNodes[i]);
			if(!uD(gA(f, 'errorText'))) gid(gA(f, 'errorText')).innerText='';
		}

		return {tE:e, cE:c};
	}();
	/*
	Function: get element by id [w.gid, w.$]
	-----------------------------------
	returns a reference to an item by it's id name.  Results are cached
	-----------------------------------
	*/
	var gid = function(){
		var cache={};
		addUnload(function(){ cache=_; }); // clean up!

		function e(e){
			if(typeof(e)!='string') return e;
			if(!uD(cache[e])) return cache[e];
			if(d.getElementById){
				ret = d.getElementById(e);
			}else if(d.all){
				ret=d.all[e];
			}else if(d.layers){
				ret=d.layers[e];
			}else{
				ret=null;
			}
			if(ret!=null){
				cache[e]=ret;
			}
			return ret;
		}
		function f(){
			if(arguments.length==0){
				return _;
			}else if(arguments.length==1){
				return e(arguments[0]);
			}else{
				var r=[];
				for(var i=0; i<arguments.length; i++)
					r[i] = e(arguments[i]);
				return r;
			}
		}
		return f;
	}();

	w.load        = L;
	w.loaded      = cL;
	w.gid         = gid;
	w.$           = gid;
	w.doneLoading = dL;
	w.writeLoaded = wL;
	w.throwError  = err.tE;
	w.clearError  = err.cE;
}();

/*
Namespace: xml http
-------------------
wrapper for the xmlhttp object
-------------------
*/
__=function xmlHTTPNamespace(){
	var xBr, gM=_;
	addUnload(function(){ xBr=gM=_; }); // clean up!

	/*
	Function: get xml http object [w.w.getXMLHttpObj]
	-------------------------------------------------
	returns a modified xml http object

	modified functions or properties listed below.  functions that are simply passed through are not documented.
	Usage is identical to a normal xmlhttp object except for the modified functions listed.
	-------------------------------------------------
	*/
	function gXO(){
		var XL=_, axO=['Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP'], i;
		addUnload(function(){ XL=axO=i=_; });
		try{	// XMLHttpRequest comes first for Firefox and IE7 (hopefully)
			if(!uD(XMLHttpRequest))
				XL=new XMLHttpRequest();
		}catch(e){}
		if(gM!=_)	// the proper object is already cached
			XL=new ActiveXObject(gM);
		if(XL==_)	// try all the ActiveX objects in axO
			for(i=0;i<axO.length;i++)
				if(XL==_)
				try{
					XL=new ActiveXObject(axO[i]);
					gM=axO[i];
				}catch(e){
					XL=_;
				}

		return {
			open:                  function(){
				var A = prepArgs(arguments, ['a', 'b', 'c', 'd', 'e']);
				if(uDN(A.a, A.b)){ throwError(JSLibrary.missingArgs.supplant({f: 'XMLHTTP: open'})); return; }

				XL.open(A.a, uD(xBr)||(!this.useBridge)?A.b:xBr+escape(A.b), A.c, A.d, A.e);
			},
			send:                  function(){
				var A = prepArgs(arguments, ['a']);

				var T=this;
				/*
				Function: onreadystatechange [modified, not exposed]
				----------------------------------------------------
				the onreadystate change function is already applied.  if desired, you can still apply your own, however.  primarily, the new function catches all errors and throws a timeout error for 408 and 504 error codes and a generic error for all other error codes.  it will use the default throwError function unless you have provided an onerror function.
				----------------------------------------------------
				*/
				function onReadyStateChange(){
					if(arguments.callee.called) return;

					T.readyState=XL.readyState;
					if(isFunction(T.onreadystatechange)) T.onreadystatechange();

					if(XL.readyState==4){
						arguments.callee.called=true;
						function tError(a, b){
							if(isFunction(T.onerror)){
								T.onerror(a, b);
							} else {
								throwError(a, b);
							}
						}
						switch (XL.status){
							case 200: // good
								break;
							case 408: case 504: // timeout
								tError('A problem occured talking to the server.  Please try again.');
								return;
								break;
							default:
								alert(XL.responseText);
								tError('A problem occured talking to the server.  Please try again later.');
								return;
								break;
						}
						T.responseText = XL.responseText;
						T.responseXML  = XL.responseXML;
						T.status       = XL.status;
						T.statusText   = XL.statusText;
						if(isFunction(T.oncomplete)) T.oncomplete();
						fireEvents(T, 'complete');
						XL=axO=i=_;	// clean up!
					}
				};
				XL.onreadystatechange=function(){onReadyStateChange();};
				XL.send(A.a||'');
				onReadyStateChange();
//				T=_;
			},
			setRequestHeader:      function(a, b){ XL.setRequestHeader(a, b); },
			abort:                 function(){     XL.abort(); },
			responseText:          _,
			responseXML:           _,
			readyState:            _,
			getAllResponseHeaders: function(){  return XL.getAllResponseHeaders(); },
			getResponseHeader:     function(a){ return XL.getResponseHeader(a); },
			status:                _,
			statusText:            _,
			onreadystatechange:    _,
			/*
			Property: oncomplete [w.getXMLHttpObj.oncomplete]
			-------------------------------------------------
			requires a function.  this can be used instead of the onreadystatechange function and checking for readyState==4.
			-------------------------------------------------
			*/
			oncomplete:            _,
			/*
			Property: onerror [w.getXMLHttpObj.onerror]
			-------------------------------------------
			requires a function that takes one argument(string) that contains the error code
			-------------------------------------------
			*/
			onerror:               _,
			/*
			Property: useBridge
			-------------------
			set to true or false (default true).  If set AND a bridge is set, the object will use whatever
			XMLHTTP Bridge you have set.
			-------------------
			*/
			useBridge:             true
		};

		return XL;
	}

	/*
	Function: fetch xml [w.fetchXML]
	--------------------------------
	a one line interface to fetch an xml document and run code on it's completion.  ASync.
	--------------------------------
	 0 u  : url to load
	 1 f  : function to run upon document load
	[2 a] : run asynchrounously.  default = true
	[3 e] : function to run on error
	[4 p] : post variables [will run as get if blank]
	*/
	function fX(){
		var A = prepArgs(arguments, ['u', 'f', 'a', 'e', 'p']);
		if(uDN(A.u, A.f)){ throwError(JSLibrary.missingArgs.supplant({f: 'fetchXML'})); return; }
		if(uDN(A.a)) A.a=true;

		var x = gXO();
		x.open(A.p?'POST':'GET', A.u, A.a);
		x.oncomplete = function(){ A.f(x); };
		if(isFunction(A.e)) x.onerror = A.e;
		if(A.p) x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
		x.send(A.p);
//		x=A=_;
	}

	w.getXMLHttpObj    = gXO;

	/*
	Function: set xml http bridge [w.setXMLHttpBridge]
	--------------------------------------------------
	javascript is denied access to any pages not on it's own server.  this can be bypassed by setting an
	http bridge (effectively a proxy server).  the bridge should be a server-side script that simply takes
	a url, downloads the content and returns the html of the document.

	if a bridge is set for an xml http object, -every- requested document will go through the bridge.  if
	this effect is undesired for files not needing a bridge (local files or files on the same server), you
	must create a seperate object for accessing these files.
	--------------------------------------------------
	0 s : url string for the bridge
	*/
	w.setXMLHttpBridge = function(s){ xBr=s; }
	w.fetchXML         = fX;
}();

/*
Namespace: auto load
--------------------
"magically" removes the requirement of loading a module before calling it's functions
--------------------
*/
__=function autoLoadNamespace(){
	function l(){
		var A=prepArgs(arguments, ['r'], _, _, ['r']);if(!A) return;
		var f;

		for(ns in A.r){
			var cNS = A.r[ns];
			if(uDN(cNS)) continue;
			if(!uDN(cNS['functions']))
				for(f in cNS['functions'])
					if(uD(w[f]))
						w[f] = new Function('', 'load("'+ns+'", _, _, _, true);return w["'+f+'"](arguments);');
			if(!uDN(cNS['children']))
				for(f in cNS['children'])
					l(cNS['children'][f]);
			if(!uDN(cNS['extensions']))
				for(f in cNS['extensions'])
					l(cNS['extensions'][f]);
		}
	}
	l(moduleList);
}();

load('domhelpers');
load('array');
load('positioning');
if(Browser.moz) load('firefox');