var HDAListeners = {

  /**
   * onConnect is called when the player is connected to the server
   */
  onConnect: function() {
  	appendLog("onconnect");
  },

  /**
   * onDisconnect is called when the player is disconnected from the server
   */
  onDisconnect: function() {
  	appendLog("ondisconnect");
  },

  /**
   * onException is called when an error occurs
   */
  onException: function(exception) {
    appendLog("exception  " + exception);
  },

  /**
   * onFallback is called when an event occurs and no listener has been
   * registered for it
   */
  onFallback: function(event) {
    appendLog("fallback  " + event);
  },

  /**
   * onNodeReceived is called when the client receives a node from Brain
   *
   * It has a single parameter with the received node with the following
   * properties:
   *
   * node = {
   *   id: the node id
   *   flv: the name of this node's movie
   *   txt: the text to be shown together with the movie
   *   alt: the alternate text to be shown when the movie isn't displayed
   *   acts: a list of actions for this node
   * }
   *
   * While the node here already contains all the actions, clients should not
   * execute them in the NodeReceived event, as the various actions listeners
   * will be called by the video player at the correct point in time.
   */
	// Modifier pour afficher les menu au moment de la lecture de la video.
  	// récupére à partir de node.acts la liste des menus à afficher.
  	onNodeReceived: function(node) {
    	appendLog("nodereceived  " + node.id + ": " + node.flv);
    	HDAChrome.setupMenu();
    	HDAChrome.hasReceivedNode = true;
    	//aggiunta visualizzazione menu
    	if(node.acts!=null){
      		if(node.acts[0]!=null){
      			if(node.acts[0].menu!=null){
            		var menuAction=node.acts[0].menu;
            		var s = [];
            		for (var i = 0; i < menuAction.length; i++) {
              			s.push(menuAction[i].titl);
            		}
            		appendLog("displaymenu  [" + s.join(', ') + "]");
            		HDAChrome.setupMenu(menuAction)
      			}
      		}
		}
   	},

  /**
   * onDisplayMenu is called when a menu has to be displayed
   *
   * menuAction = [{
   *       // menu item 1
   *       titl: the menu item caption
   *       node: the id of the node to load
   *       rule: the id of the rule to load
   *       url: the url to load, see object structure in the onLoadUrl listener
   *     }, {
   *       // menu item 2
   *     }
   *   ]
   *
   */
   // Modifier pour afficher les menu au moment de la lecture de la video.
   // Prmet d'afficher le menu dans le cas ou il y'a que le boutton Continuer.

  	onDisplayMenu: function(menuAction) {
    	if(menuAction!=null){
        	if(menuAction.length==1){
            	if(menuAction[0].titl=="Continue"){
                	HDAChrome.setupMenu(menuAction);
            	}
        	}
    	}
	},


  /**
   * onLoadUrl is called when an url has to be opened
   *
   * urlAction = {
   *   kind: the action type, always "url"
   *   url: {
   *     url: the actual address to open
   *     target: the url target, can be any valid html target.
   *         a special value of "popup" means the url should be opened in a
   *         popup window
   *     popup: {
   *       width: the popup window width
   *       height: the popup window height
   *     }
   *   }
   * }
   */
  onLoadUrl: function(urlAction) {
    HDAChrome.openURL(urlAction.url)
    appendLog("loadurl ");
  },

  /**
   * onStart is called when the player starts playing the video
   */
  onStart: function() {
    HDAChrome.setupControlsOnVideoStart()
    appendLog("start");
  },

  /**
   * onStop is called when the player has finished playing the video
   */
  onStop: function() {
    HDAChrome.setupControlsOnVideoStop()
    appendLog("stop");
  },

  /**
   * onToggleVideo is called when the video is turned on or off
   *
   * videoOn: true if the video is now on, false otherwise
   */
  onToggleVideo: function(videoOn) {
    appendLog("togglevideo " + videoOn);
  }

}

function appendLog(m) {
	if (top.frames[0])
    var mainDoc = top.frames[1].document
  else
    var mainDoc = document
  var logger = mainDoc.getElementById('logWindow');


  if (!logger)
    return
  var li=mainDoc.createElement("LI")
  li.innerHTML=m
  logger.appendChild(li)
}
