  
  // things that should happen when everything is loaded
  Event.observe(window, 'load', function (e)
	{
    addActionlinkEventHandlers();
	});

  var addActionlinkEventHandlers = function()
  {
		// get all useraction links
		allNodes = document.getElementsByClassName("useraction",$('useractions'));

    // add event handlers 
    for(i = 0; i < allNodes.length; i++) 
    {
    	var link = allNodes[i];
    	
    	Event.observe(link, 'click', function (e)
    	{
		    // do ajax request
		    new Ajax.Request(Event.element(e).href, 
		    { 
		    	method: 'GET',
		      asynchronous: true,
		      parameters: 'mode=ajax',
		    	onSuccess: function(request,json)
		      {
	     
	          // show messagetext
		        try 
		        {
	            displayMessageInMessageBar(json.messagetext);
	          } catch(e) {}

            // update all items in the page as told by the PHP script
						for (var key in json.updatefields) 
							$(key).innerHTML = json.updatefields[key];

            // remove friendblock when we removed a friend
            if (json.action=="remove")
            {
	            try 
	            {
                Effect.Squish('friend_'+json.id, {duration:0.3});
	            } catch(e) {}
	          }

            // re-attach eventhandlers for the links
            addActionlinkEventHandlers();
		      }
		    });
		    Event.stop(e)
		  })
    }  	
  }  
