/*
 * Wordpress Plugin API 4 Javascript
 *
 * Andrés Nieto Porras
 * http://www.anieto2k.com
 *
 * Implementación del API de Wordpress en Javascript
 */

var filters = actions = {};

function do_filter(where, param){
    if (typeof filters == 'undefined') return;
    if (typeof filters[where] == 'undefined') return;
    for (var x=0; x<filters[where].length; x++)
        param = filters[where][x](param);
    return param;
}

function add_filter(where, action) {
   if (typeof filters == 'undefined') return;
   if (typeof filters[where] == 'undefined') filters[where] = new Array();
	filters[where].push(action);
}

function remove_filter(where, action) {
	if (typeof filters[where] == 'undefined') return;
	var j = 0;
	while (j < filters[where].length) {
		if (filters[where][j] == action) { filters[where].splice(j, 1);}
		else { j++; }
		}
}

function add_action(where, action) {
	if (typeof actions[where] == 'undefined') actions[where] = new Array();
	actions[where].push(action);
}

function remove_action(where, action) {
	if (typeof actions[where] == 'undefined') return;
	var j = 0;
	while (j < actions[where].length) {
		if (actions[where][j] == action) { actions[where].splice(j, 1);}
		else { j++; }
		}
}

function do_action(what, param) {
		if (typeof actions == 'undefined') return;
		if (typeof actions[what] == 'undefined') return;
		var param = param || {};
		for (var x=0; x<actions[what].length; x++) actions[what][x](param);
}
