/*
* Item View representation 
*/
function Item(div,params){
  
  /****************************************************************************************/
  /* class inherits*/
	/**************/
  this._extends = view;
  this._extends(new controller());
  
  /****************************************************************************************/
  /* class attributes */
	/****************/
    if(undefined===window.creator){window.creator = "";}
    if(undefined===window.email){window.email = "";}
    if(undefined===window.user){window.user = "";}
    this.id = null;
    this.creat = null;
    this.lastmodif = null;
    this.nom = null;
    this.creator = null;
    this.description = null;
    this.email = null;
    this.link = null;
    this.title = null;
    this.item = [];
    this.keywords = [];

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


  /****************************************************************************************/
  /* class buttons event handler */
  /**************************/
  
  /*
    * contruct the screen GUI representation
    */
  this.construct = function(div, params){
    debug("[ITEM] construct" + params.item);
    this.id = params.id;
    if (IsNumeric(params.creat)) this.creat = params.creat.substr(6,2) + "-" + params.creat.substr(4,2) + "-" + params.creat.substr(0,4) + " " + params.creat.substr(8,2) + ":" + params.creat.substr(10,2);
    else this.creat = params.creat;
    this.lastmodif = params.lastmodif;
    this.nom = params.nom;
    this.creator = params.creator;
    this.description = params.description;
    this.email = params.email;
    this.link = params.link;
    this.title = params.title;
    if (this.title == '') this.title = this.link;
    var data = '<div>' + this.creat + ' <b>';
    if (this.email != '') data += '<a href="mailto:' + this.email + '">' + this.creator + '</a>';
    else data += this.creator
    data += '</b><br/>';
    if (this.link != '') data += '<b><a href="' + this.link + '">' + this.title + '</a></b><br/>';
    else if (this.title != '') data += '<b>' + this.title + '</b><br/>';
    data += this.description ;
    data += '<br/><small><b>embed :</b><input name="embed_code" type="text" value=\'' + this.description + '\' readonly="true"></small></div>';
    data += '<div id=\'divItemButtonEdit' + this.id + '\' class=\'button\'></div>';
    data += '<div id=\'divItemButtonRespond' + this.id + '\' class=\'button\'></div>';
    data += '<div id=\'divItemButtonDelete' + this.id + '\' class=\'button\'></div>';
    div.innerHTML = data;
    if ((user == 'admin') || (creator == this.creator)) {
      this.editer = new Button(getById('divItemButtonEdit' + this.id), {prefix:".:",name:'Editer', event:'EditMsg', params:this, title:'Editer le message'});
      this.editer.controller.addListener(_formulaire);
    }
    this.repondre = new Button(getById('divItemButtonRespond' + this.id), {prefix:".:",name:'R&eacute;pondre', event:'RespondMsg', params:this, title:'Repondre a ' + this.creator});
    this.repondre.controller.addListener(_formulaire);
    if (user == 'admin') {
    this.supprimer = new Button(getById('divItemButtonDelete' + this.id), {prefix:".:",name:'Supprimer', event:'DeleteMsg', params:this, title:'Supprimer le message'});
    this.supprimer.controller.addListener(_formulaire);
    }
  };
  this.construct(div, params);	

  /* class event Handler methods */
	/***************************/
  
}; // end class Items

function Photo(div,params){

  /****************************************************************************************/
  /* class inherits*/
        /**************/
  this._extends = view;
  //this._extends = Item(div,params);
  this._extends(new controller());

  this.onmouseup = function(self){
    return function(){
      debug("[PHOTO] onmouseup");
    self.controller.send('DisplayMedia',self);
    }
  };

  this.construct = function(div, params){
    //debug("[PHOTO] construct" + params.id);
    this.id = params.id;
    this.creat = params.creat;
    this.lastmodif = params.lastmodif;
    this.nom = params.nom;
    this.creator = params.creator;
    this.description = params.description;
    this.email = params.email;
    this.link = params.link;
    this.title = params.title;
    if (!(undefined===this.description.split(/src=\"|SRC=\"/)) && !(undefined===this.description.split(/src=\"|SRC=\"/)[1])) {
      data = this.description.split(/src=\"|SRC=\"/)[1].split(/\"/)[0] ;//+ '</div>';
      div.innerHTML = "<img src='" + data + "' width='100%'/>" ;
    } else {
      debug("[ITEM] PB split" + this.description.split(/src=\"|SRC=\"/)[1]);

    }
    div.onmouseup = this.onmouseup(this,div);
  };
  this.construct(div, params);

}; // end class Items

function User(div,params){

  /****************************************************************************************/
  /* class inherits*/
        /**************/
  this._extends = view;
  //this._extends = Item(div,params);
  this._extends(new controller());

  this.onmouseup = function(self){
    return function(){
      debug("[PHOTO] onmouseup");
    self.controller.send('DisplayMedia',self);
    }
  };

  this.construct = function(div, params){
    //debug("[USER] construct" + params.id);
    this.id = params.id;
    this.creat = params.creat;
    this.lastmodif = params.lastmodif;
    this.nom = params.nom;
    this.creator = params.creator;
    this.description = params.description;
    this.email = params.email;
    this.link = params.link;
    this.title = params.title;
    if (!(undefined===this.description.split(/src=\"|SRC=\"/))) {
      data = this.description.split(/src=\"|SRC=\"/)[1].split(/\"/)[0] ;//+ '</div>';
      div.innerHTML = "<img src='" + data + "' width='100%'/>" ;
    }
    div.onmouseup = this.onmouseup(this,div);
  };
  this.construct(div, params);

}; // end class Items


