$('#presentation').on('click', 'input', function (e) {
  var action = new ROSLIB.ActionClient({
    ros: ros,
    serverName: 'action_server/task',
    actionName: 'action_server_msgs/TaskAction',
  });

  var lang = e.currentTarget.value;
  switch (lang) {
    case 'English':
      lang = 'en';
      break;
    case 'Dutch':
      lang = 'nl';
      break;
    default:
      console.error('Unknown language');
  }

  var recipe = {
    actions: [{
      action: 'demo-presentation',
      language: lang,
    }]
  }

  var goal = new ROSLIB.Goal({
    actionClient: action,
    goalMessage: {
      recipe: JSON.stringify(recipe)
    }
  });

  goal.send();
});
function handleActionlib(skill_command) {
  var actionlib = new ROSLIB.ActionClient({
    ros : ros,
    serverName: 'execute_command',
    actionName: 'amigo_skill_server/ExecuteAction'
  });

  var goal = new ROSLIB.Goal({
    actionClient : actionlib,
    goalMessage : {
      command : skill_command
    }
  });

  goal.send();
}
function handleAmigoGripperCommand(device,argument) {
  var action = new ROSLIB.ActionClient({
    ros: ros,
    serverName: device + '/action',
    actionName: 'tue_manipulation_msgs/GripperCommandAction',
    timeout: 10,
  });


  var goal = new ROSLIB.Goal({
    actionClient: action,
    goalMessage: {
      command: {
        direction : parseInt(argument, 10),
        max_torque : 50
      }
    }
  });

  goal.send();
}
function handleJointState(device,name_arguments,position_arguments) {

  /* parse argument array */
  position_arguments = position_arguments.split(',');
  for (var i=0; i<position_arguments.length; i++) {
    position_arguments[i] = parseFloat(position_arguments[i]);
  }

  /* Joint names */
  name_arguments = name_arguments.split(',');


  console.log('device: ', device);
  console.log('name_arguments: ', name_arguments);
  console.log('position_arguments: ', position_arguments);

  var action = new ROSLIB.ActionClient({
    ros: ros,
    serverName: 'body/joint_trajectory_action',
    actionName: 'control_msgs/FollowJointTrajectoryAction',
    timeout: 10,
  });

  var goal = new ROSLIB.Goal({
    actionClient: action,
    goalMessage: {
      trajectory: {
        joint_names: name_arguments,
        points: [{
          positions: position_arguments
        }]
      }
    }
  });

  goal.send();
}
function handleHeadRef(argument) {
  var action = new ROSLIB.ActionClient({
    ros: ros,
    serverName: 'head_ref/action_server',
    actionName: 'head_ref/HeadReferenceAction',
    timeout: 10,
  });

  argument = argument.split(',');
  for (var i=0; i<argument.length; i++) {
    argument[i] = parseFloat(argument[i]);
  }

  var goal = new ROSLIB.Goal({
    actionClient: action,
    goalMessage: {
      goal_type: 1,
      pan: argument[0],
      tilt: argument[1],
    }
  });

  goal.send();
}