Mys.main = function(emoti_cate_pri_list, emoti_cate_com_list, recomm_cate_list)
{	
  this.emoti_cate_pri_list = emoti_cate_pri_list;
  this.emoti_cate_com_list = emoti_cate_com_list;
  this.recomm_cate_list = recomm_cate_list;
  this.init();
};

Mys.main.prototype =
{
  recomm_tpl : new Ext.Template('<div class="bb{islast}"><a href="#"><img class="c1" src="{filepath1}"/></a><div class="c2"><a href="#">{title}</a></div></div>')
  ,emoti_tpl : new Ext.Template('<div class="cc{od}"><textarea onfocus="this.blur();" class="d1" cols="16" rows="5">{message}</textarea></div>')

  ,init : function()
  {
    this.recomm_init();
    this.emo_init();
  }

  ,recomm_init: function()
  {
    Ext.fly("recom_more").on("click",function(){location="?m=msg&s=mms&cate="+this.recom_cate.encode();},this);
    this.recom_containerEl = Ext.get("recomm_container");
    Ext.fly("recom_cate_list").select(".dd").on("click",this.recom_onClickMenu, this, "left");
    this.recom_sel_menu = Ext.fly("recom_cate_list").select(".dd").elements[0];

    if(this.recomm_cate_list)
    {
      if(this.recomm_cate_list.length>0)
        this.recomm_getUserMsg(this.recomm_cate_list[0]);
    }
  }

  ,recom_onClickMenu : function(e,el)
  {
    var category = el.className;
    category = category.substring(category.indexOf("_")+1, category.lastIndexOf("_"));
    if(!category) return;
    if(this.recom_sel_menu == el) return;
    Ext.fly(this.recom_sel_menu).removeClass("on");
    this.recom_sel_menu = el;
    Ext.fly(this.recom_sel_menu).addClass("on");

    this.recomm_getUserMsg(category);
  }

	,recomm_getUserMsg : function(category)
	{
		this.recom_cate = category;    	
		
		
		Global.modelSms.getUserMsgByTag( category, null, "m", 0, 3, function(data)
		{
			this.recom_containerEl.update("");
			var items = data.response.message;
			
			if(!items) return;
			if(!items.length) return;
			var el = null;
			for(i=0;i<items.length;i++)
			{
				items[i].islast = i==2?' last':''
				el = this.recom_containerEl.insertHtml("beforeend",this.recomm_tpl.apply(items[i]),true);
				el.on("click",function(e, el, id){location = "/?m=msg&s=mms&tpl="+id+"&cate="+ this.recom_cate;/*items[i].tag[0].tag_name;*/},this, items[i].id);
			}
		}
		, this);
	}


  ,emo_init: function()
  {
    Ext.fly("emo_btn_primore").on("click",function(){location="?m=msg&s=sms&cate="+this.left_cate.encode();},this);
    Ext.fly("emo_btn_commore").on("click",function(){location="?m=msg&s=sms&cate="+this.right_cate.encode();},this);
    this.left_containerEl = Ext.get("l_emo_container");
    this.right_containerEl = Ext.get("r_emo_container");
    if(this.emoti_cate_pri_list)
    {
      if(this.emoti_cate_pri_list.length >0)
        this.emo_getUserMsg(this.emoti_cate_pri_list[0], "left");
    }
    if(this.emoti_cate_com_list)
    {
      if(this.emoti_cate_com_list.length >0)
        this.emo_getUserMsg(this.emoti_cate_com_list[0], "right");
    }

    Ext.fly("l_emo_menu").select(".cc").on("click",this.emo_onClickMenu, this, "left");
    this.emo_l_sel_menu_El =Ext.fly("l_msel").dom;
    Ext.fly("r_emo_menu").select(".cc").on("click",this.emo_onClickMenu, this, "right");
    this.emo_r_sel_menu_El =Ext.fly("r_msel").dom;
  }

  ,emo_onClickMenu : function(e, el, side)
  {
    var category = el.className;
    category = category.substring(category.indexOf("_")+1, category.lastIndexOf("_"));
    if(!category) return;
    if(side == "left")
    {
      if(this.emo_l_sel_menu_El == el) return;
      Ext.fly(this.emo_l_sel_menu_El).removeClass("on");
      this.emo_l_sel_menu_El = el;
      Ext.fly(this.emo_l_sel_menu_El).addClass("on");
    }
    else
    {
      if(this.emo_r_sel_menu_El == el) return;
      Ext.fly(this.emo_r_sel_menu_El).removeClass("on");
      this.emo_r_sel_menu_El = el;
      Ext.fly(this.emo_r_sel_menu_El).addClass("on");
    }

    this.emo_getUserMsg(category, side);
  }

	,emo_getUserMsg : function(category, side)
	{
		if(side == "left")
			this.left_cate = category;
		else
			this.right_cate = category;
		
		//Global.modelSms.getUserMsgByTag( category, null, 0, 3, function(data)        
		
		Global.modelSms.getUserMsgByTag( category, null, "s",0, 4,  /*side=="left"?SUB_CLASSS_PRIVATE : SUB_CLASSS_COMPANY,*/
			side=="left" ? function(data){this.emo_addItemToContainer(this.left_containerEl,data.response.message, this.left_cate)} 
											: function(data){this.emo_addItemToContainer(this.right_containerEl,data.response.message, this.right_cate)}
			, this);
	}

  ,emo_addItemToContainer : function(containerEl, data, tag)
  {
    containerEl.update("");
    if(!data) return;
    if(!data.length) return;
    var el = null;
    for(i=0;i<data.length;i++)
    {
      data[i].od = i%2==1 ? " od" : "";
      el = containerEl.insertHtml("beforeend",this.emoti_tpl.apply(data[i]),true);
      el.child(".d1").on("click",function(e, el, id){location = "/?m=msg&s=sms&tpl="+id+"&cate="+ tag;},this, data[i].id);
    }

  }
};


