/*
	ay_addLoadEvent(): adds the callback 'func' to the load event
	of the window object. Will fire 'func' after any previously
	existing callbacks have been fired.
	
	ARGUMENTS:
	func: Can be a function which will then be called, or a
	string which will be evaluated as JavaScript. If null,
	does nothing. Any other type throws an error.
*/
function ay_addLoadEvent(func) {
	if (func == null) {
		/* If it's null, it doesn't do anything. */
		return;
	}

	if (typeof func == 'string') {
		/* It's a string. We'll need to evaluate it later, but it's valid input. */
		if (func.length < 1) {
			/* If it's 0-length, it doesn't do anything. */
			return;
		}

		/* Wrap in a function to pass along. Doing this here simplifies things later. */
		var fString = func;
		func = function() { eval(fString); };
	} else if (typeof func != 'function') {
		/* It's not a string or a function, so we can't use it! */
		throw "AYInvalidTypeException";
	}

	var oldOnload = window.onload;
	if (typeof oldOnload == 'string') {
		/* The old event handler was a string, so we'll need to evaluate it later. */
		window.onload = function() {
			eval(oldOnload);
			func();
		}
	} else if (typeof oldOnload == 'function') {
		/* The old event handler was a function, so we can just call it, then 'func'. */
		window.onload = function() {
			oldOnload();
			func();
		}
	} else {
		/* No previous valid onload. */
		window.onload = func;
	}
}
