Mys.ListLogCtrl = function(config){
	Mys.ListLogCtrl.superclass.constructor.call(this, config)
}

Ext.extend(Mys.ListLogCtrl, Mys.LogCtrl, {
  start : 0
  ,lastStart : null
  ,LIMIT : 10
  ,SCROLLY : 100
  ,FIRST_LOADING_Y : 200
  ,LOADING_Y : 200
	,categoryId : null
	,contentsId : null
	,bEndOfList : false
	,mode : "NORMAL"  // NORMAL : default , SEARCH : 사이드바검색 , SINGLE : 사이드바 아이템클릭
	,initialize : function(){
    this.containerEl = Ext.get("logBox");

		// item Set
		this.itemSet();

    // category set
    this.categorySet();
    this.addEvents({'modify' : true});

		if(GROUP_FLAG)
		{
				var writeCtrl = new Mys.ChannelWriteCtrl({logCtrl : this, mode : "write", containerName : this.containerName, useUserImg : true, useFix : true});
				writeCtrl.on("changeList", this.onChangeList, this);

				this.categoryIdList = [null, null, null, 101, CONTENTS_CATEGORY.MOVIE, CONTENTS_CATEGORY.VIDEO, CONTENTS_CATEGORY.BOOK, CONTENTS_CATEGORY.SHOP, CONTENTS_CATEGORY.PHOTO, CONTENTS_CATEGORY.LINK, CONTENTS_CATEGORY.MINISHOP_PHOTO];
				this.categoryNameList = ["main", "review", "tag", "text", "movie", "video", "book", "shop", "photo", "link", "minishop_photo"];
		}
		else
		{
    		var writeCtrl = new Mys.LogWriteCtrl({logCtrl : this, mode : "write", containerName : this.containerName, useUserImg : true, useFix : true});
		}

    writeCtrl.on("write", this.onWriteItem, this);

		// 구독하기
		var subscribeBtn = Ext.get("subscribeBtn");
		if(subscribeBtn)
			subscribeBtn.on("click", this.subscribe, this);

		var prevBtnEl = Ext.get("hbn_prev");
		var nextBtnEl = Ext.get("hbn_next");
		var topBtnEl = Ext.get("hbn_top");

		if(prevBtnEl) prevBtnEl.on("click",this.onClickPrev, this);
 		if(nextBtnEl){nextBtnEl.on("click",this.onClickNext, this); if(this.items.length >= 10) nextBtnEl.setStyle("display", "block");}
 		if(topBtnEl) topBtnEl.on("click",this.onClickTop, this);

    window.loadSingleItem = this.loadSingleItem.createDelegate(this);
    window.searchItem = this.startSearch.createDelegate(this);

    this.loadingImgEl = Ext.get("pop_nowloading");
    this.loadingImgElWidth = this.loadingImgEl.getWidth();    

	}

  ,onClickPrev : function()
  {
  	if(this.start-this.LIMIT < 0)
  			return;

    this.start = this.start-this.LIMIT;
    this.bEndOfList = false;

    window.scrollTo(0,this.SCROLLY);

		switch(this.mode)
		{
				case "SEARCH"	:
						this.search();
						break;

				default :
						this.loadItems();
						break;
		}
  }

  ,onClickNext : function()
  {
  	if(this.bEndOfList)
  			return;

    this.start += this.LIMIT;
    window.scrollTo(0,this.SCROLLY);

		switch(this.mode)
		{
				case "SEARCH"	:
						this.search();
						break;

				default :
						this.loadItems();
						break;
		}
  }

  ,onClickTop : function()
  {
    this.mode = "NORMAL";
    this.start = 0;
    this.bEndOfList = false;
    window.scrollTo(0,this.SCROLLY);
    this.loadItems();
  }

	,onChangeList : function(categoryName)
	{
		this.categoryId = this.getCategoryId(categoryName);
		this.pageType = this.getPageType(categoryName);
		this.property = this.getProperty(categoryName);
		this.contentsId = this.getContentsId(categoryName);

		this.mode = "NORMAL";
    this.start = 0;
    this.bEndOfList = false;

		this.loadItems();
	}

	,getCategoryId : function(categoryName)
	{
		var index = this.categoryNameList.indexOf(categoryName);
		if(index == -1)
				return null;

		return this.categoryIdList[index];
	}

	,getContentsId : function(categoryName)
	{
			var contentsId = null;
			if(categoryName == "review")
					contentsId = Global.contentsItem.contents_id;

			return contentsId;
	}

	,getPageType : function(categoryName)
	{
		var pageType = "";
		switch(categoryName)
		{
				case "main" :
						//if(Global.contentsItem)
							pageType = "contents_all";
						break;
						
				case "tag" :
						pageType = "keyword";
						break;
				default :
						break;
		}

		return pageType;
	}

	,getProperty : function(categoryName)
	{
		var property = "";
		switch(categoryName)
		{
				case "review" :
						property = "contents_related";
						break;

				default :
						property = "recent";
						break;
		}

		return property;
	}

	,getLogItem : function(obj)
	{
	  return new Mys.ListLogItem(obj);
	}

  ,loadItems : function()
  {
    this.showLoadingPop();

    Global.modelLogItem.get(this.property, PAGE_USER_ID, null, null, this.start, this.LIMIT+1, 1, this.categoryId, this.pageType, 0, this.contentsId, this.cbLoadItems, this);
  }

  ,loadSingleItem : function(item_id)
  {
    this.mode = "SINGLE";
    this.showLoadingPop();

    Global.modelLogItem.getSingleItem(item_id, function(data){
  		this.hideLoadingPop();
      this.resetData();
      var item = data.response;
      item.replyOn = true;
      this.applyItems(Mys.getSafeArray(item));
    }, this);
  }

  ,startSearch : function(keyword)
  {
    this.keyword = keyword;
    this.start = 0;
    this.bEndOfList = false;
    this.mode = "SEARCH";
    this.pageType = "";
    window.scrollTo(0,this.SCROLLY);
    this.search(keyword);
  }

  ,search : function(keyword)
  {
    if(!keyword) keyword = this.keyword;
    this.showLoadingPop();

    Global.modelLogItem.search("recent", this.start, this.LIMIT+1, 1, keyword, PAGE_USER_ID, this.pageType, this.cbLoadItems, this);
  }

	,cbLoadItems : function (data)
	{
		if (!data || data.response.code != 100){alert(data.response.message); return;}
		this.hideLoadingPop();
    this.resetData();
		var data = Mys.getSafeArray(data.response.item);
		if(data[0])
      this.setTopDateDisplay(data[0].insert_date);
    else
      this.setTopDateDisplay('');

		this.applyItems(data);
	}

  ,setTopDateDisplay : function(date_str)
  {
    if(!date_str){Ext.fly("display_date_top").update(""); return;}
    var date = new Date.parseString(date_str);
    Ext.fly("display_date_top").update(this.getDateDisplayHtml(date.dateFormat("Y.m.d")));
  }

  ,getDateDisplayHtml : function(date_str)
  {
    var html = "";
    for(i=0;i<date_str.length;i++)
      html+='<img class="home_num" src="/home/images/num_'+((date_str.charAt(i)==".")?"dot":date_str.charAt(i))+'.gif"/>';
    return html;
  }

	,setBtnVisible : function()
	{
	  if(this.mode == "SINGLE")
	  {
			Ext.fly("hbn_next").setStyle("display","none");
			Ext.fly("hbn_prev").setStyle("display","none");
			return;
	  }

		if(this.bEndOfList)
			Ext.fly("hbn_next").setStyle("display","none");
		else
  		Ext.fly("hbn_next").setStyle("display","block");

		if(this.start - this.LIMIT < 0)
			Ext.fly("hbn_prev").setStyle("display","none");
		else
  		Ext.fly("hbn_prev").setStyle("display","block");
	}

	// 받아온 데이터를 Item 데이터로.
	,applyItems : function(logItems, contents, action)
	{
    if(action != "ACTION_REMOVE" && action != "ACTION_MODIFY")
    {
  		// 이전, 다음, 컨텐츠, 검색해서 아이템을 가져오는 경우에만 체크. (삭제, 수정의 경우에는 처리하지 않는다)
  		this.bEndOfList = logItems.length > this.LIMIT ? false : true;
  		this.setBtnVisible();
  	}

		if(!logItems || logItems.length < 1)
		{
			(function(){this.containerEl.insertHtml("beforeEnd", "<p id='emptyContents' class='empty'>글이 없습니다</p>", true)}).defer(300, this);
			return;
		};


		var item, data;
		var length = (logItems.length > this.LIMIT) ? this.LIMIT : logItems.length;

		for(var i = 0; i < length; i++)
		{

			data = logItems[i];
			item = this.items.key(data.item_id);

			if(item && data.delete_date) // 삭제
			{
				item.el.slideOut("t", {remove:true, duration:0.3});
				this.items.removeKey(item.data.item_id);

				if(!this.items.length)
					(function(){this.containerEl.insertHtml("beforeEnd", "<p id='emptyContents' class='empty'>글이 없습니다</p>", true)}).defer(300, this);
			}
			else if(item) // 수정
			{
				this.modifyItem(data);
			}
			else // 생성
			{
				if(data.delete_date)
					continue;

				if(!this.items.length){
					var emptyEl = Ext.get("emptyContents");

					if(emptyEl)
						emptyEl.remove();
				}

				this.addItem(data, null);
			}
		}

		this.isLoadingItem = false;
	}



/*	// 아이템 생성
	,addItem : function(data, contents)
	{
		var item, html;
		item = this.getLogItem({contents:contents, data:data, ctrl:this});

		this.items.add(item);
		html = item.getRenderHtml();

		item.el = this.containerEl.insertHtml("afterBegin", html, true);

		item.el.setStyle("display","block");

		// 글만 있을 때와, 사진 있을 때 아이콘이 안맞는 것 수정.
		if(item.hasImage)
			item.el.addClass("image");

		item.set();
		item.on("modify", this.onClickModify, this);

		return item;
	}*/


	// 아이템 생성
	,addItem : function(data, contents){		
		
		var item, html;
		item = this.getLogItem({contents:contents, data:data, ctrl:this, GROUP_FLAG:this.GROUP_FLAG});
		this.items.add(item);

		html = item.getRenderHtml();

		item.el = this.containerEl.insertHtml("beforeEnd", html, true);
		item.el.setStyle("display","block");

		item.set();
		return item;
	}

  ,resetData : function()
  {
    this.items.clear();
    this.containerEl.update("");
  }

  ,showLoadingPop : function()
  {
    if(!this.containerTopEl)
      this.containerTopEl= Ext.get("contents_top");

    var box = this.containerTopEl.getBox();
    if(!this.loadingbgFrameEl)
      this.loadingbgFrameEl = Ext.get("popup_iframe");
    this.loadingbgFrameEl.setWidth(box.width+"px");
    this.loadingbgFrameEl.setHeight(box.height+"px");
    this.loadingbgFrameEl.setStyle("top" , (Ext.isIE ? box.y-2 : box.y) +"px");
    this.loadingbgFrameEl.setStyle("left",(Ext.isIE ? box.x-2 : box.x)+"px");

    if(!this.loadingbgShadowEl)
      this.loadingbgShadowEl = Ext.get("shadow");
    this.loadingbgShadowEl.setWidth(box.width+"px");
    this.loadingbgShadowEl.setHeight(box.height+"px");
    this.loadingbgShadowEl.setStyle("top" , (Ext.isIE ? box.y-2 : box.y) +"px");
    this.loadingbgShadowEl.setStyle("left",(Ext.isIE ? box.x-2 : box.x)+"px");

    if(!this.loadingImgEl)
    {
      this.loadingImgEl = Ext.get("pop_nowloading");
      this.loadingImgElWidth = this.loadingImgEl.getWidth();
      this.loadingImgEl.setStyle("top", (box.y + this.FIRST_LOADING_Y) + "px");
    }
    else
      this.loadingImgEl.setStyle("top", (box.y + this.LOADING_Y) + "px");

    this.loadingImgEl.setStyle("left",Math.ceil((Ext.isIE ? box.x-2 : box.x)+(box.width-this.loadingImgElWidth)/2)+"px");

    this.loadingbgFrameEl.setStyle("display","block");
    this.loadingbgShadowEl.setStyle("display","block");
    this.loadingImgEl.setStyle("display","block");
  }

  ,hideLoadingPop : function()
  {
    this.loadingbgFrameEl.setStyle("display","none");
    this.loadingbgShadowEl.setStyle("display","none");
    this.loadingImgEl.setStyle("display","none");
  }

  ,onWriteItem : function()
  {
    this.mode = "NORMAL";
    this.start = 0;
    this.bEndOfList = false;
		this.loadItems();
  }
});










Mys.ListLogItem = function(config){
	Mys.ListLogItem.superclass.constructor.call(this, config)
}


Ext.extend(Mys.ListLogItem, Mys.LogItem, {
	logTemplate : new Ext.Template('<div class="home_item item">'+ 
                      				    '<div class="h_a1"><a href="{userUrl}"><img width="49" height="49" src="{mylogo}"></a></div>'+
                      				    '<div class="h_a2"><img src="/home/images/memobox_arrow.gif"></div>'+
                      				    '<div class="h_a3">'+
                      				      '<div class="m1"></div>'+
                      				      '<div class="m2">'+
                      				      '{groupHtml}'+
                      				      '<div class="home_memo_folded {foldClass}">'+
	                      				      '{foldHtml}'+
	                                    '<p class="{foldMemoClass}">{text_memo}</p>'+
  				      										'</div>'+
  				      										'<div class="home_memo {memoClass}" style="display:none;">'+
  				      										'{html}'+
  				      										'<p class="itemMemo">{memo}</p>'+
  				      										'</div>'+
                      				        '<ul class="itemNavi">'+
                      				          '<li class="first">{name}</li>'+
                      				          '<li>{c_title}</li>'+
                      				          '{channelText}'+
                      				          '<li class="date {dateClass}">{writtenDate}</li>'+
                      				          '{replyText}'+
                      				          '{isUsedPhoneHtml}'+
                      				          '{agreeBtn}'+
                      				          '<img class="newMark {newClass}" src="/images/icon/icon_new_item.gif">'+
                      				          '{creatorNavi}'+
                      				        '</ul>'+
                      				        '<div class="replyBox"></div>'+
                      				      '</div>'+
                      				      '<div class="m3"></div>'+
                      				    '</div>'+
                      				  '</div>')

  ,getReplyCtrl : function()
  {
    return new Mys.ListLogReplyCtrl({prtEl:this.el, prtData:this.data});
  }

  ,set_overload : function()
  {
    if(this.data.replyOn)
    {
      this.el.child(".home_memo_folded").setStyle("display","none");
      this.el.child(".home_memo").setStyle("display","block");
      this.resizeImage();
  		this.replyCtrl.toggle();
    }
    else
      this.el.child(".m2").on("click", this.onClickItem, this);

    return true;
  }

	,onClickItem : function(e, el)
	{
    if(el.nodeName == "A" || el.nodeName == "INPUT" || el.nodeName == "TEXTAREA" || el.nodeName == "EMBED"
    || el.className.indexOf("home_heart_count")>=0 || el.className=="home_heart_count2" || el.className=="home_hearticon"
    || el.className=="point_img" || el.className=="nofold") return;


    if(this.writeCtrl && this.writeCtrl.writeToggleFlag) return;

		this.toggleFold();
	}

  ,toggleFold : function(e, el)
  {
		// 공개설정 창이 열려있을 경우 닫기.
		if(this.gradeToggle)
			this.hideGradeList();

		if(this.el.child(".home_memo_folded").isVisible())
		{
      this.el.child(".home_memo_folded").setStyle("display","none");
      this.el.child(".home_memo").setStyle("display","block");
  		this.el.child(".newMark") ? this.el.child(".newMark").addClass("none") : null;
    }
    else
    {
      this.el.child(".home_memo").setStyle("display","none");
      this.el.child(".home_memo_folded").setStyle("display","block");
    }
    this.resizeImage();
		this.replyCtrl.toggle();
  }

	,getGradeToggle : function()
	{
			return this.gradeToggle;
	}
//이미지 사이즈 크기를 조절한다. IE에서는 이미지가 display none 되어있을때는 onload시 이미지 사이즈를 가져올수 없기에 클릭시 직접 수정해줌
  ,resizeImage : function()
  {
      this.el.select("img").each(function(el){if(el.dom.width>469) el.dom.width=469;});
  }

	,getRenderHtml : function()
	{
		// this에 추가로 저장하면 비효율적이므로, Ext.apply를 이용하는 것으로 바꿀 것. replyItem도.
		var data = {};

		Ext.apply(data, this.data);
		var dd = Date.parseDate(data.insert_date, "Y-m-d G:i:s");
		var tpl = this.logTemplate;

		if(data.category_id == 101)
		{
				data.c_title = GROUP_FLAG?"토크":"글";
				data.category = CONTENTS_CATEGORY.LOG;
		}
		
		data.name = (data.name.length >= 15)?data.name.ellipsis(15):data.name;
		
		if(!Global.contentsParser)
			Global.contentsParser = new Mys.ParseHomeContents();

		var contents = Global.contentsParser.parse(data);

		data.html = contents.html;
		data.foldHtml = contents.foldHtml;
		if(data.category && data.category != CONTENTS_CATEGORY.LINK && data.category != CONTENTS_CATEGORY.LOG)
		{
				data.memoClass = "movie";
				data.foldMemoClass = "itemMemo info";
				data.foldClass = "movie_fold";
		}
		else
		{
				data.memoClass = "";
				data.foldMemoClass = "fitemMemo";
				data.foldClass = "";
		}

		if(!Global.parser)
			Global.parser = new Mys.ParseItem();
		else
			Global.parser.initialize();

		data.memo = Global.parser.parse(data.memo);
		data.memo += Global.parser.getFileQuery();
		data.text_memo = Global.parser.getText();
		this.data.text_memo = data.text_memo;
		this.hasImage = Global.parser.hasImage();

    data.isUsedPhoneHtml = Global.parser.isUsedPhone ? '<li><img class="home_cellicon" src="/home/images/icon_cell.gif"></li>' : "";

		switch(this.data.grade)
		{
			case "9" :
				var gradeType = "전체공개";
				break;

			case "8" :
				var gradeType = "채널공개";
				break;

			case "1" :
				var gradeType = "친구공개";
				break;

			default :
				var gradeType = "비공개";
				break;
		}

		if(Mys.creatorCheck(data.creator_id))
		{
			data.creatorNavi = '<li class="creatorfirst gradeBtn">'+gradeType+'</li>';
			data.creatorNavi += '<li class="creator"><a href="#" onclick="return false" class="modifyBtn">수정</a></li>';
			data.creatorNavi += '<li class="creator"><a href="#" onclick="return false" class="removeBtn">삭제</a></li>';
		}

		data.writtenDate = dd.dateFormat("G:i");
		data.linkDate = dd.dateFormat("G:i:s");

		data.userUrl = "http://"+data.mydomain+"."+DOMAIN;


    var replyClass = "";
	  if(GROUP_FLAG || Global.isMain)
	  {
  		data.agreeBtn = '';
  		replyClass = "last";//"replyBtn last";

  		data.groupText = "<li>"+data.name+"</li>";
  		if(!data.ref_count)
  			data.dateClass = "last";

      if(data.agree_flag)
      {
      	if(EXT_SESSION.isLog() && !Mys.creatorCheck(this.data.creator_id))
      	   data.groupHtml = '<div class="itemPoint"><a class="agreeBtn" href="#" onclick="return false" onfocus="this.blur();"><span class="home_heart_count2">'+(data.agree_count? data.agree_count : 0)+'</span><img class="point_img" src="/images/channel/icon_heart.gif"></a></div>';
      	else
      		data.groupHtml = '<div class="itemPoint"><span class="home_heart_count2">'+(data.agree_count? data.agree_count : 0)+'</span><img class="point_img" src="/images/channel/icon_heart.gif"></div>';
      }
      else
      {
      	if(EXT_SESSION.isLog() && !Mys.creatorCheck(this.data.creator_id))
        	data.groupHtml = '<div class="itemPoint off"><a class="agreeBtn" href="#" onclick="return false" onfocus="this.blur();"><span class="home_heart_count2">'+(data.agree_count? data.agree_count : 0)+'</span><img class="point_img" src="/images/channel/icon_heart_grey.gif"></a></div>';
       	else
       		data.groupHtml = '<div class="itemPoint off"><span class="home_heart_count2">'+(data.agree_count? data.agree_count : 0)+'</span><img class="point_img" src="/images/channel/icon_heart_grey.gif"></div>';
      }
  	}
  	else
  	{
  		data.group_Html = '';

		  if(Mys.creatorCheck(this.data.creator_id))
	  		data.agreeBtn = '<li class="last"><img class="home_hearticon" src="/home/images/icon_heart'+(data.agree_flag?"_red":"_grey")+'.gif"><span class="home_heart_count'+(data.agree_flag?"":" grey")+'">'+ (data.agree_count? data.agree_count : 0)+'</span></li>';
	    else
		  	data.agreeBtn = '<li class="last"><a class="agreeBtn" href="#" onclick="return false" onfocus="this.blur();"><img class="home_hearticon" src="/home/images/icon_heart'+(data.agree_flag?"_red":"_grey")+'.gif"><span class="home_heart_count'+(data.agree_flag?"":" grey")+'">'+ (data.agree_count? data.agree_count : 0)+'</span></a></li>';
  	}

		if(data.ref_count)
			data.replyText = '<li class="'+replyClass+'">댓글 <span class="replyCount">'+(data.ref_count?data.ref_count:0)+'</span></li>';
		else
			data.replyText = '<li class="'+replyClass+' ">댓글쓰기</li>';

		if(!GROUP_FLAG && data.group_flag)
		{
				var target_name = (data.target_name.length >= 15)?data.target_name.ellipsis(15):data.target_name;
				data.channelText = "<li>"+target_name+"</li>";
		}

    if(!data.mylogo) data.mylogo = "/images/icon/defaultImage.gif";
    data.newClass = (data.read_flag || !EXT_SESSION.isLog()) ? 'none' : '';

		return tpl.apply(data);
	}

	,setAgreeCount : function(agreeCount){
		if(!this.agreeEl){ window.status = '내부오류 528'; return;}

		this.data.agree_count = agreeCount;
		if(GROUP_FLAG || Global.isMain)
		{
  		this.agreeEl.child(".home_heart_count2").update(agreeCount);
  		this.agreeEl.child(".point_img").dom.src = Global.isMain ? "/minilog/images/channel/icon_heart.gif" : "/images/channel/icon_heart.gif";
  		this.agreeEl.parent().removeClass("off");
  	}
  	else
  	{
  		this.agreeEl.child(".home_heart_count").update(agreeCount);
  		this.agreeEl.child(".home_heart_count").removeClass("grey");
  		this.agreeEl.child(".home_hearticon").dom.src =this.agreeEl.child(".home_hearticon").dom.src.replace("_grey","");
  	}
	}

	,setReplyCount : function(replyCount)
	{
		if(!this.replyEl){ window.status = '내부오류 529'; return;}

		if(!replyCount)
				return;

		this.data.ref_count = replyCount;

		var replyText = "댓글 <span>"+replyCount+"</span>";

		this.replyEl.update(replyText);

		if((GROUP_FLAG || Global.isMain) && this.replyEl.hasClass("none"))
		{
			this.el.child(".date").removeClass("last");
			this.replyEl.addClass("last");
			this.replyEl.removeClass("none");
		}
	}

	,setMemo : function(memo, view_type, isReply){

		var parser = new Mys.ParseItem(view_type);
		var foldChildName, childName = ".home_memo .itemMemo";
		this.data.view_type = view_type;
		this.data.memo = memo;

		var memo = parser.parse(memo);
		memo += parser.getFileQuery();
		this.data.text_memo = parser.text_memo;

		if(isReply)
		{
			this.el.child(".replyContents").update(memo);
		}
		else
		{
			if(this.data.category == CONTENTS_CATEGORY.LOG || this.data.category == CONTENTS_CATEGORY.LINK)
					foldChildName = ".fitemMemo";
			else
					foldChildName = ".itemMemo.info";

			this.el.child(foldChildName).update(memo);
			this.el.child(childName).update(memo);
		}
	}

	,onClickModify : function(evt, t)
	{
			this.isModify = true;

			if(!this.el.child(".home_memo_folded").isVisible())
					this.toggleFold();

			if(!this.writeCtrl)
			{
				this.writeCtrl = new Mys.LogWriteCtrl({logCtrl : this.ctrl, containerName : this.el, useModify : true});
				this.writeCtrl.on("write", this.ctrl.applyItems, this.ctrl);
			}

			this.writeCtrl.onClickModify({el: this.el, replyName : ".replyBox", memoName : ".home_memo_folded", naviName : ".itemNavi", data: this.data});
	}
});


Mys.ListLogReplyCtrl = function(config){
	Mys.ListLogReplyCtrl.superclass.constructor.call(this, config)
}


Ext.extend(Mys.ListLogReplyCtrl, Mys.LogReplyCtrl, {
	writeBoxTemplate : new Ext.Template("<form class='writeReplyForm' onsubmit='return false'>" +
																			"<div class='iconBox_1'>" +
																				"<a href='{userUrl}' onclick='return false'>" +
																					"<img src='{mylogo}' alt='{name}' />" +
																				"</a>" +
																			"</div>" +
																			"<textarea name='textarea'></textarea>" +
																			"<input type='image' src='./home/images/btn_rewrite.gif' alt='  댓글쓰기'/>" +
																		"</form>")

  ,getLogReplyItem : function(obj)
  {
    return new Mys.ListLogReplyItem(obj);
  }
});




Mys.ListLogReplyItem = function(config){
	Mys.ListLogReplyItem.superclass.constructor.call(this, config)
}


Ext.extend(Mys.ListLogReplyItem, Mys.LogReplyItem, {
	replyTemplate : new Ext.Template('<div class="reply">'+
    																	'<div class="iconBox_2 userIcon">'+
    																		'<a href="{userUrl}" onclick="return false">'+
    																			'<img src="{mylogo}" class="userImage" alt="{userName}"/>'+
    																			'<span class="domain">{logoDomain}</span>'+
    																			'<span class="userId">{logoId}</span>'+
    																			'<span class="refuser">1</span>'+
    																		'</a>'+
    																	'</div>'+
    																	'<p class="replyContents">{memo}</p>'+
            									        '<ul class="replyNavi">'+
            									          '<li class="first">{name}</li>'+
            									          '<li class="date">{insert_date}</li>'+
            									          '{replyBtn}'+
            									          '{agreeBtn}'+
            									          '<img class="newMark {newClass}" src="/images/icon/icon_new_item.gif">'+
    																		'{ownerNavi}' +
            									        '</ul>'+
    																'</div>'),

	reReplyTemplate : new Ext.Template("<div class='reReply'>" +
																	"<div class='iconBox_2 userIcon'>" +
																		"<a href='{userUrl}' onclick='return false'>" +
																			"<img src='{mylogo}'  class='userImage' alt='{userName}'/>" +
																			"<span class='domain'>{logoDomain}</span>" +
																			"<span class='userId'>{logoId}</span>" +
																			"<span class='refuser'>1</span>" +
																		"</a>" +
																	"</div>" +
																	"<p class='replyContents'>{memo}</p>"+
																	"<ul class=replyNavi>" +
																		"<li class='first'>{name}</li>" +
																		"<li>{insert_date}</li>" +
																		"{agreeBtn}" +
																		"<img class='newMark {newClass}' src='/images/icon/icon_new_item.gif'>"+
																		"{ownerNavi}" +
																	"</ul>"+
															"</div>"),

	modifyTemplate : new Ext.Template('<form name="modify_{item_id}" class="{className}">' +
																				'<textarea name="textarea" rows="3">{memo}</textarea>' +
																				'<div class="md_right"><a href="#" onclick="return false" class="saveBtn"><img class="nofold" src="./home/images/btn_save.gif"></a>'+
																				'<a href="#" onclick="return false" class="cancelBtn"><img class="nofold" src="./home/images/btn_cancel.gif"></a></div>'+
																			'</form>')

	,getAgreeHtml : function(agree_count, agree_flag)
	{
    if(agree_flag)
  	  return '<li class="last"><a class="agreeBtn" href="#" onclick="return false" onfocus="this.blur()"><img class="home_hearticon" src="/home/images/icon_heart_red.gif"><span class="home_heart_count">' + (agree_count ? agree_count : 0) + '</span></a></li>';
  	else
  	  return '<li class="last"><a class="agreeBtn" href="#" onclick="return false" onfocus="this.blur()"><img class="home_hearticon" src="/home/images/icon_heart_grey.gif"><span class="home_heart_count grey">' + (agree_count ? agree_count : 0) + '</span></a></li>';
	}

  ,getLogReReplyCtrl : function()
  {
    return new Mys.ListLogReReplyCtrl({prtEl:this.el, prtData:this.data, prtCtrl : this.ctrl});
  }


	,setAgreeCount : function(agreeCount){
		if(!this.agreeEl){ window.status = '내부오류 528'; return;}
		this.data.agree_count = agreeCount;
		this.agreeEl.update('<img class="home_hearticon" src="/home/images/icon_heart_red.gif"><span class="home_heart_count">' + agreeCount + '</span>');
	}
});



Mys.ListLogReReplyCtrl = function(config){
	Mys.ListLogReReplyCtrl.superclass.constructor.call(this, config);
};

Ext.extend(Mys.ListLogReReplyCtrl, Mys.LogReReplyCtrl, {
	writeBoxTemplate : new Ext.Template("<form onsubmit='return false' class='writeReReplyForm'>" +
																			"<div class='iconBox_1'>" +
																				"<a href='{userUrl}' onclick='return false'>" +
																					"<img src='{mylogo}' alt='{name}' />" +
																				"</a>" +
																			"</div>" +
																			"<textarea name='textarea'></textarea>" +
																			"<input type='image' src='./home/images/btn_rewrite.gif' alt='댓글쓰기'/>" +
																		"</form>")
});

Mys.ParseHomeContents = function()
{
	Mys.ParseHomeContents.superclass.constructor.call(this);
};

Ext.extend(Mys.ParseHomeContents, Mys.ParseContents, {
   //movie, shop, book 공통
	commonFoldHtml : '<img class="titleImg" src="{image}" onload="if(this.width >= this.height){ setWideClassName(this.parentNode.parentNode);}else{removeWideClassName(this.parentNode.parentNode);} if(this.height>60) this.height=60">'+
									'<p class="contentMemo"><span class="con_title">{title}</span><strong class="{pointClass}">{pointHtml}</strong>{agreeImg}</p>'

  ,commonHtml : '<a target="new" href="{link}" onfocus="this.blur();"><img class="contentImg" src="{image}"></a><p class="contentMemo"> <span class="con_title"><a target="new" href="{link}" onfocus="this.blur();">{title}</a></span><strong class="{pointClass}">{pointHtml}</strong>{agreeImg}</p><ul class="contentMemo info">'

  ,movieHtml : '{directorHtml}{pubDateHtml}{actorHtml}{reviewHtml}</ul>'
  ,shopHtml : '{lpriceHtml}{hpriceHtml}{reviewHtml}</ul>'
  ,bookHtml : '{authorHtml}{publisherHtml}{pubdateHtml}{reviewHtml}</ul>'

  ,videoFoldHtml : '<img class="titleImg" src="{image}" onload="if(this.width >= this.height){ setWideClassName(this.parentNode.parentNode);}else{removeWideClassName(this.parentNode.parentNode);} if(this.height>60) this.height=60">'
	,videoHtml : '<div class="videoCon"><embed height="350" width="425" wmode="transparent" type="application/x-shockwave-flash" src="http://www.youtube.com/v/{videoId}?f=videos&app=youtube_gdata&autoplay=0" wmode="transparent"/></div>'

	,photoFoldHtml : '<img class="titleImg" src="{image}" onload="if(this.width >= this.height){ setWideClassName(this.parentNode.parentNode);}else{removeWideClassName(this.parentNode.parentNode);} if(this.height>60) this.height=60">'
	,photoHtml : '<img class="imageImg" src="{image}" onload="if(this.width > 469){this.width=469}">'

	,linkFoldHtml : '<p class="fitemMemo"><a class="con_title" target="new" href="{link}">{con_title}</a></p>'
	,linkHtml : null // initialize;

	,initialize : function()
		{
				Mys.ParseHomeContents.superclass.initialize.call(this);

				this.movieHtml = this.commonHtml + this.movieHtml;
				this.shopHtml = this.commonHtml + this.shopHtml;
				this.bookHtml = this.commonHtml + this.bookHtml;
				this.linkHtml = this.linkFoldHtml;
		}

		,parse : function(item)
		{
				if(item == null) return;

				this.setItem(item);
				this.setCategory(item.category);

				if(!this.checkCategory()) return "";

				item = this.getItem();

				this.parseItem(item);

				var html = this.getTemplate().apply(item);
				var foldHtml = this.getFoldTemplate().apply(item);

				return {html : html, foldHtml : foldHtml};
		}

		,parseItem : function(item)
		{
					var category = this.getCategory();

					switch(category)
					{
							case CONTENTS_CATEGORY.MOVIE :
								this.parseMovie(item);
								break;

							case CONTENTS_CATEGORY.BOOK	:
								this.parseBook(item);
								break;

							case CONTENTS_CATEGORY.SHOP	:
								this.parseShop(item);
								break;

							case CONTENTS_CATEGORY.PHOTO :
							case CONTENTS_CATEGORY.MINISHOP_PHOTO :
								this.parsePhoto(item);
								break;

							case CONTENTS_CATEGORY.LINK :
								this.parseLink(item);
								break;
					}
		}

	,parseBook : function(item)
		{
				if(item.author)
					item.authorHtml = '<li><span class="z1">지은이</span><span class="z2">'+item.author+'</span></li>';

				if(item.publisher)
					item.publisherHtml = '<li><span class="z1">출판사</span><span class="z2">'+item.publisher+'</span></li>';

				if(item.pubdate)
					item.pubdateHtml = '<li><span class="z1">출판일</span><span class="z2">'+item.pubdate.substring(0,10)+'</span></li>';

				item.title = item.con_title.length >= 42?item.con_title.ellipsis(42):item.con_title;
				item.pointClass = this.getPointClass(item.point, item.is_wish);
				item.pointHtml = this.getPointHtml(item.is_wish);
				item.agreeImg = this.getAgreeImg(item.agree_type);
				item.reviewHtml = this.getReviewHtml(item.con_group_id, item.con_count, "책");
		}

		,parseMovie : function(item)
		{
				if(item.director)
					item.directorHtml = '<li><span class="z1">감독</span><span class="z2">'+item.director+'</span></li>';

				if(item.pubDate)
					item.pubDateHtml = '<li><span class="z1">년도</span><span class="z2">'+item.pubDate.substring(0,10)+'</span></li>';

				if(item.actor)
					item.actorHtml = '<li><span class="z1">출연</span><span class="z2">'+item.actor+'</span></li>';

				item.title = item.con_title.length >= 42?item.con_title.ellipsis(42):item.con_title;
				item.pointClass = this.getPointClass(item.point, item.is_wish);
				item.pointHtml = this.getPointHtml(item.is_wish);
				item.agreeImg = this.getAgreeImg(item.agree_type);
				item.reviewHtml = this.getReviewHtml(item.con_group_id, item.con_count, "영화");
		}

		,parseShop : function(item)
		{
				if(item.lprice)
					item.lpriceHtml = '<li><span class="z1">최저가</span><span class="z2">'+item.lprice+'</span></li>';

				if(item.hprice)
					item.hpriceHtml = '<li><span class="z1">최고가</span><span class="z2">'+item.hprice+'</span></li>';

				item.title = item.con_title.length >= 42?item.con_title.ellipsis(42):item.con_title;
				item.pointClass = this.getPointClass(item.point, item.is_wish);
				item.pointHtml = this.getPointHtml(item.is_wish);
				item.agreeImg = this.getAgreeImg(item.agree_type);
				item.reviewHtml = this.getReviewHtml(item.con_group_id, item.con_count, "상품");
		}

		,parsePhoto : function(item)
		{
				item.script = 'script = "onload=if(this.width > '+this.imageWidth+'){this.width='+this.imageWidth+'}"';
		}

		,parseLink : function()
		{

		}


		,getTemplate : function()
		{
				var category = this.getCategoryName();

				//exception
				if(category == "music")
						category = "video";
				else if(category == "minishop_photo")
						category = "photo";

				var categoryTemplate = category+"Html";

				if(typeof(this[categoryTemplate]) == "string")
					this[categoryTemplate] = new Ext.Template(this[categoryTemplate]);

				return this[categoryTemplate];
		}

		,getFoldTemplate : function()
		{
				var categoryName;
				var category = this.getCategory();

				// exception
				if(category == CONTENTS_CATEGORY.BOOK || category == CONTENTS_CATEGORY.SHOP || category == CONTENTS_CATEGORY.MOVIE)
					categoryName = "common";
				else if(category == CONTENTS_CATEGORY.MUSIC)
					categoryName = "video";
				else if(category == CONTENTS_CATEGORY.MINISHOP_PHOTO)
					categoryName = "photo";
				else
					categoryName = this.getCategoryName();

				var categoryTemplate = categoryName+"FoldHtml";

				if(typeof(this[categoryTemplate]) == "string")
					this[categoryTemplate] = new Ext.Template(this[categoryTemplate]);

				return this[categoryTemplate];
		}

		,getReviewHtml : function(groupId, count, category)
		{
				if(!groupId || groupId == PAGE_USER_ID || parseInt(count) == 1)
						return "";

				return "<li class='review'>이 "+category+"에 대한 <a href='http://"+groupId+"."+DOMAIN+"' target='_self'>"+(count-1)+"</a>개의 리뷰가 더 있습니다.</li>";
		}
});