/*
* Basic MVC framework
*/

/*****************************************************************************/
/* 
* Controller class 
*/
/*****************************************************************************/

function controller(){  

	/* class attributes */
	/****************/

	/*
	* List of listeners
	*/
  this.listeners   = new Array();

	/* class methods */
	/***************/

  /*
	* Add a listener to controller listeners list
	*/
  this.addListener = function(listener){ 
		this.listeners.push(listener); 
	};

  /*
	* Send to all controller listeners the event named by
	* name with optional object params 
	*/
  this.send        = function(name,params){ 
		debug('[controller] send name='+name+' params='+params);
		//for(x in this.listeners) this.listeners[x].receive(name,params);
		this.listeners.each( 
                  function(listener){ 
                    listener.receive(name,params)
                  }
                );
  };

};//end class controller

/*****************************************************************************/
/* 
* View class, had a controller to prevent (if necessary) other component
* of his modification 
*/
/*****************************************************************************/

function view(controller){

	/* class attributes */
	/****************/

	/* his own controller*/
  this.controller = controller;

	/* class methods */
	/*****************/

  /*
	* View can receive a event named by name with optional object named by params
	* If implemented, it activate the method ("on"+__eventname__) 
	* corresponding to received event;
	*/  
  this.receive = function(name,params){
      var func = "on"+name;
      if(this[func]) this[func](params);      
  };    

};//end class controller

