
MTJax.Action = {

  receive: function(Response)
  {
    eval('Response = ' + Response.responseText);
    
    if (Response.Actions) 
    {
      MTJax.Action.execute(Response.Actions);
    }
    
    Behaviour.apply();
  },
  
  execute: function(Actions)
  {
    for (OnAction = 0; OnAction < Actions.length; OnAction++) 
    {
      Action = Actions[OnAction];
      if (!$(Action.OnId) && 'document' != Action.OnId) 
      {
        continue;
      }
      
      var Elem = $(Action.OnId);
      
      switch (Action.Do)
      {
        case 'eval' :
          eval(Action.Value);
          break;
        
        case 'Reload':
          document.location.reload();
          break;
          
        case 'SetValue':
          if (Elem.value) 
          {
            Elem.value = Action.Value;
            if (!Elem.Blinker) 
            {
              Elem.Blinker = new Fx.Tween(Elem, {
                property: 'background-color',
                duration: 500
              });
              Elem.backTo = Elem.getStyle('background-color');
            }
            
            Elem.Blinker;
            
            Elem.Blinker.start('#FF0000').chain(function()
            {
              this.Blinker.start(this.backTo);
            }.bind(Elem));
          }
          break;
          
        case 'SetChecked':
          Elem.checked = Action.Value;
          break;
          
        case 'SetHTML':
          try 
          {
            console.log('Try adding HTML to: ' + Action.OnId);
            console.log(Elem);
            Elem.set('html', Action.Value);
          } 
          catch (e) 
          {
          
          }
          break;
          
        case 'AddHTML':
          Elem.set('html', Elem.get('html') + Action.Value);
          break;
          
        case 'Overlibs':
          try 
          {
            for (Thing in Action.Value.OverLibs) 
            {
              if (Thing == 'IDs') 
              {
                IDs = Action.Value.OverLibs[Thing];
                for (i = 0; i < IDs.length; i++) 
                  Overlibs.Pre.IDs.push(IDs[i]);
              }
              else 
              {
                Overlibs.Pre[Thing] = Action.Value.OverLibs[Thing];
              }
            }
            Overlibs.prepare();
          } 
          catch (e) 
          {
          }
          break;
          
        case 'Glow':
          //                    new fx.TextColorPump(Elem, {Duration: 400});
          //                    new MTJax.Action.Glow(Elem);
          break;
      }
    }
  }
  
};
