/*  init_update.js  -  generic handlers for the onLoad and onUpdate events.
 *  (C) Copyright 2003  Kars Meyboom <kars@kde.nl>
 *
 *  LICENSE:
 *
 *  This code is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This code is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

// --
// -- GLOBALS
// --

// This array holds a list of javascript code snippets to evaluate
// right after the <body> tag.
var preload_snippets = [];

// This array holds a list of javascript code snippets to evaluate on
// the onLoad event.
var init_snippets = [];

// This array holds a list of javascript code snippets to evaluate on
// the onUpdate event.
var update_snippets = [];

// This array holds a list of javascript code snippets to evaluate on
// each timeout event.
var timeout_snippets = [];

// --
// -- FUNCTIONS
// --

// This function adds the snippet to the list of
// snippets to evaluate right after the <body> tag.
function at_preload (snippet) {
	push(preload_snippets, snippet);
}

// This function adds the snippet to the list of
// snippets to evaluate on the onLoad event.
function at_init (snippet) {
	push(init_snippets, snippet);
}

// This function adds the given snippet to the list of
// snippets to evaluate on the onUpdate event.
function at_update (snippet) {
	push(update_snippets, snippet);
}

// This function adds the given snippet to the list
// of snippets to evaluate on each timeout event.
function at_timeout (snippet) {
	push(timeout_snippets, snippet);
}

// Evaluates all the javascript code snippets in the
// preload_snippets array.
function preload_handler () {
	for (var i = 0; i < preload_snippets.length; i++) {
		//alert('Preload: '+preload_snippets[i]);
		eval(preload_snippets[i]);
	}
}

// Evaluates all the javascript code snippets in the
// init_snippets array. This is the handler for the
// onLoad event.
function onload_handler () {
	for (var i = 0; i < init_snippets.length; i++) {
		//alert('Onload: '+init_snippets[i]);
		eval(init_snippets[i]);
	}
}

// Evaluates all the javascript code snippets in the
// update_snippets array. This handler is called on
// the onResize event and several other events that
// affect the page's layout.
function onupdate_handler () {
	for (var i = 0; i < update_snippets.length; i++) {
		//alert('Onupdate: '+update_snippets[i]);
		eval(update_snippets[i]);
	}
}

// Evaluates all the javascript code snippets in the
// timeout_snippets array.
function timeout_handler () {
	for (var i = 0; i < timeout_snippets.length; i++) {
		eval(timeout_snippets[i]);
	}
	setTimeout(timeout_handler, 500);
}

// --
// -- INITIALISATION CODE
// --

at_init('setTimeout(\'timeout_handler()\', 500)');


