/*
 * handlers for page-wide events
 * this is so that components/modules/etc can add their own handlers and get stuff run at page-wide handler time!!
 * without conflicting with each other and clobbering each other's handlers like the default Mozilla/IE model does....
 *
 * a template should include this file first, then all the modules/components (or the template itself) below can use them
 *
 */

// define arrays (append to these to get your own handlers run)
// don't muck with the array other than to append your own handler(s)
// it's also NOT designed to be easily added to and removed from at will
// only added to once at initial document load time only
// so if you need conditional handlers, just wrap your code inside your handler in an "if" statement
// note: your handlers MUST return true to indicate following handlers may run, or false if you consume this event
onload_handlers      = new Array(onload_init);
onresize_handlers    = new Array();
onscroll_handlers    = new Array();
onmouseup_handlers   = new Array();
onmousedown_handlers = new Array();
onmousemove_handlers = new Array();

// initialize all the handlers so they run
// note: all the non-onload ones are not initialized until our own first onload handler runs!
// note: IE needs some of these to be window and others document... not sure why...
window.onload = onload_run;
function onload_init(e) {
	window.onresize      = onresize_run;
	document.onmouseup   = onmouseup_run;
	document.onmousedown = onmousedown_run;
	document.onmousemove = onmousemove_run;
	return true;
}

// routines to run all handlers in arrays
function onload_run(e)     {for (var i = 0; i < onload_handlers.length;     i++) if(!(onload_handlers[i])(e))      return false; return true;}
function onresize_run(e)   {for (var i = 0; i < onresize_handlers.length;   i++) if(!(onresize_handlers[i])(e))    return false; return true;}
function onmouseup_run(e)  {for (var i = 0; i < onmouseup_handlers.length;  i++) if(!(onmouseup_handlers[i])(e))   return false; return true;}
function onmousedown_run(e){for (var i = 0; i < onmousedown_handlers.length;i++) if(!(onmousedown_handlers[i])(e)) return false; return true;}
function onmousemove_run(e){for (var i = 0; i < onmousemove_handlers.length;i++) if(!(onmousemove_handlers[i])(e)) return false; return true;}

