function pi_broadcast(params){
  pageId=getPageId();
  params.page_id=pageId;
  //get listening events probably from ajax, then do them one at a time..
  if (params.action_event=='tag_cloud_link'){
    new Ajax.Request( '/core/event/update_tag_filter/'+params['action_id'], 
		      {method:"post", parameters:params, onSuccess:tag_filter_complete});
  }
  new Ajax.Request('/core/event/get_listening_widgets', 
	{method:"post", parameters:params, onSuccess:pi_broadcast_complete}); 
}

function pi_broadcast_complete(transport)
{
	$('header').scrollTo();	// Scroll to the top of the page so that the filter section will be in view...
	updateListeningWidgets(transport);	// ...then go and update the widgets (in the background)
}

function tag_filter_complete(transport)
{
  document.getElementById('tag_filter').innerHTML = transport.responseText;
  
}

function updateListeningWidgets(transport){
  listeningWidgets = transport.responseText.evalJSON();
  listeningWidgets.each(updateAWidget);
}

//update a widget in same way as update self
function updateAWidget(w){
  var ajax_options =  ( typeof( w.ajax_options ) == "undefined" ) ? new Object : w.ajax_options;
  ajax_options.parameters = new Object;
  ajax_options.parameters.target_params =  Object.toJSON(w.target_params);
  new Ajax.Updater(w.target_div, w.target_url, ajax_options);
}

function getPageId(){
  classAtt=$('content').className;
  re=/page_id_(\d+)/;
  result=classAtt.match(re);
  page_id=0;
  if (result!=null){
    page_id=result[1];
  }
  return page_id;

}

