var layout = {
	setProfileSplit:function(){
		$('.infoWrap>.infoSplit>.middle').height($('.infoWrap>.profileCntsWrap').height()-104);
	},
	setCompleteGraph:function(intComplete){
		var pobj = $('.graphBase');
		var sobj = $('.graphShim');
		var idxobj = $('.completeWrap>.graphBox>.indexBox>.middle');
		var intLen = (pobj.width()/100) * intComplete;
		sobj.width(intLen);
		if (intComplete >= 95){
			idxobj.hide();
		}else{
			idxobj.width(intLen);
			idxobj.show();
			idxobj.text(intComplete);
		}
	},
	resizeFullScreen:function(){
		var target = $('.fullScreenFilter');
		target.height($('.body').height() + $(document).scrollTop());
	},
	setFullScreen:function(){
		var target = $('.fullScreenBase');
		var target1 = $('.fullScreenCnts');
		layout.resizeFullScreen();
		target.show();
		target1.show();
	},
	closeFullScreen:function(){
		var target = $('.fullScreenBase');
		var target1 = $('.fullScreenCnts');
		target1.html('');
		target.hide();
		target1.hide();
	}
}
var handleUser = {
	chkFirstOver:null,
	jsCallUserInfo:function(userid,e){
		var target = $('.smallUserMenu');
		var posx = 0; // x 좌표값
		var posy = 0; // y 좌표값
		if (!e) var e = window.event;
		if (e.pageX || e.pageY){posx = e.pageX;posy = e.pageY+10;}
		else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop+10;
		}
		target.css({'top':posy,'left':posx});
		if(handleUser.chkFirstOver != null) window.clearTimeout(handleUser.chkFirstOver);
		var url = "/user/getTargetUserinfoMnuWithView.asp?tid=" + encodeURIComponent(userid);
		$.post(url,function(data){target.html(data)});
		target.show();
		handleUser.chkFirstOver = window.setTimeout('handleUser.closeUserInfo()',2000);
		target.hover(function(){window.clearTimeout(handleUser.chkFirstOver);},function(){handleUser.closeUserInfo();chkFirstOver=null;});
	},
	closeUserInfo:function(){
		var target = $('.smallUserMenu');
		target.hide();
		window.clearTimeout(handleUser.chkFirstOver);
	}
}
var handleProfile = {
	getProfileForm:function(cntsSrl){
		$.post('/view/function/getCntsProfileForm.asp',{'cntssrl':cntsSrl},function(data){
			$('.profileWrap').html(data);
			handleProfile.chgTopCategory(cntsSrl)
		});
	},
	chgTopCategory:function(cntsSrl){
		var val = $('select[name=theme] option:selected').val();
		$.getJSON('/view/function/getProfileSubInfo.asp',{'cntssrl':cntsSrl,'topCtgName':val},function(data){
			var groupList = data.subGroupList;
			var inputList = data.subInputList;
			handleProfile.mkSubGroupInput(groupList);
			handleProfile.mkItemInput(inputList);
		});
	},
	mkSubGroupInput:function(groupList){
		var target = $('.subCtgBox');
		target.empty();
		if($(groupList).size()!=0){
			target.append($('<p/>').attr('class','grouplabel').text('그룹') );
			target.append($('<span/>').attr({'class':'split'}).text(':'));
			var ul = $('<ul/>');
			ul.appendTo(target);
			$.each(groupList, function(key, item){
				var li = $('<li/>');
				var inputobj = $('<input/>').attr({'name':'group','type':'checkbox','value':item.groupname,'class':'checkbox'}).click(handleProfile.chkgroupcnt);
				if(item.checked==1) inputobj.attr('checked','checked'); //IE8정상동작 하위버전은.
				inputobj.appendTo(li).after($('<p/>').attr('class','checklabel').text(item.groupname));
				li.appendTo(ul);
			});
		}
	},
	mkItemInput:function(inputList){
		var target = $('.itemWrap');
		target.empty();
		var ul = $('<ul/>');
		ul.appendTo(target);
		$.each(inputList, function(key, item){
			var li = $('<li/>');
			$('<label/>').attr({'class':'inputlabel'}).text(item.label).appendTo(li);
			$('<span/>').attr({'class':'split'}).text(':').appendTo(li);
			$('<input/>').attr({'type':'text','name':item.label,'value':item.txt}).appendTo(li);
			li.appendTo(ul);
		});
	},
	submit:function(objForm){
		var option = {
			url:'/view/function/modifyProfile.asp',
			type:'POST',
			success:function(responseText){
				handleProfile.getProfile(objForm.cntsSrl.value)
			}
		}
		$(objForm).ajaxSubmit(option);
		return false;
	},
	getProfile:function(cntsSrl){
		var target = $('.profileWrap');
		$.post('/view/function/getProfile.asp',{'cntssrl':cntsSrl},function(data){
			target.html(data);
		});
	},
	getJoinInfo:function(){
		var objForm = $('#transForm');
		var option = {
			url:'/view/function/getJoinInfo.asp',
			type:'POST',
			success:function(data){
				var target = $(".profileWrap > .bottom");
				target.html(data);
			}
		}
		objForm.ajaxSubmit(option);
	},
	chkgroupcnt:function(){
		$('input[name=group]:checked').size()
	}
}
var handleImage = {
	loopcnt:0,
	sObj:null,
	getScreenItems:function(callback){
		var option = {
			url:'/view/function/getScreenItems.asp',
			type:'POST',
			dataType:'json',
			success:callback
		}
		$('#transForm').ajaxSubmit(option);
	},
	setScreenItemsPosition:function(){
		$('.imgWrapIn .imgBox').children(':first-child').each(function(){
			handleImage.setCenter(this);
		});
	},
	setCenter:function(obj){
		/*이미지 미리 로드..
		var pattern = /[\"\'](.*)[\"\']/i;
		var regexp = pattern.exec(txt);
		var tmpImg = new Image();
		tmpImg.src = regexp[regexp.length-1];
		tmpImg.onload = function(){}
		이미지 미리 로드..*/
		var obj = $(obj);
		if(obj.attr('tagName')!='IMG'){
			var target = obj.find('IMG');
		}else{
			var target = obj;
		}
		obj.bind('load',obj, function(evt){
			handleImage.showImg(obj,0);
		});
	},
	showImg:function(obj,cnt){
		var pobj = obj.parent();
		$(obj).ready(function(){
			obj.css({'display':'none'});
			var tWidth =obj.width();
			var tHeight = obj.height();
			var pWidth = pobj.width();
			var pHeight = pobj.height();
			if ((pWidth - tWidth) > 1)obj.css({'left':parseInt((pWidth - tWidth)/2)});
			if ((pHeight - tHeight) > 1) obj.css({'top':parseInt((pHeight - tHeight)/2)});
			obj.show();
		});
		var stateComplete = false;
		if($.browser.msie){
			if (obj.get(0).readyState=="complete") stateComplete = true;
		}else{
			stateComplete = obj.get(0).complete;
		}
		if(stateComplete==false && cnt < 10){
			handleImage.showImg(obj,cnt++);
		}
	},
	reloadScreenSlider:function(){
		handleImage.getScreenItems(handleImage.setScreenSliderItem);
	},
	setScreenSliderItem:function(jsonObj){
		var itemlist = jsonObj.itemlist;
		var nowidx = jsonObj.nowimg;
		var target = $('.screenSliderBox>.lstBox>.sliderWrap');
		target.html('');
		var ul = $('<ul/>').css({'width':'9999px'});
		var strLst = '';
		$.each(itemlist,function(key,item){
			var strImg = item.mainthumb;
			strLst += '<li style="float:left">';
			strLst += '<div class="imgWrapOut"><div class="imgWrapIn"><div class="imgBox">';
			strLst += '<table width="100%" height="100%"><tr><td align="center"><a href="javascript:void(0);" onclick="handleImage.dplScreenViewer(\'' + item.filename + '\');">' + strImg + '</a></td></tr></table>';
			strLst += '</div></div></div>';
			strLst += '</li>';
		});
		ul.append(strLst);
		ul.appendTo(target);
		handleImage.initScreenSlider();
	},
	initScreenSlider:function(){
		var target = $(".screenSliderBox>.lstBox>.sliderWrap")
		if(target.find('ul').html()!=''){
			target.easySlider({
				prevId:'mainscreenPrev',
				prevText:'prev(mainscreen)',
				nextId:'mainscreenNext',
				nextText:'next(mainscreen)',
				viewCnt:4,
				auto:false,
				controlsShow:false,
				speed:100,
				pause:0,
				continuous:false
			});
			handleImage.setScreenItemsPosition();
		}
	},
	dplScreenViewer:function(strFileName){
		layout.setFullScreen();
		var target = $('.fullScreenCnts');
		$.post('/view/function/getTemplateScreenViewer.asp',{'filename':strFileName},function(data){
			target.html(data);
			var objForm = $('#transForm');
			$("#transForm :input[name=filename]").val(strFileName);
			handleImage.getScreenItems(handleImage.setScreenViwer);
			target.children(':first-child').css({'top':$(document).scrollTop()+20});
			layout.setFullScreen();
		});
	},
	setScreenViwer:function(jsonObj){
		if(jsonObj) handleImage.sObj = jsonObj;
		var sObj = handleImage.sObj;
		var itemlist = sObj.itemlist;
		var nowidx = sObj.nowimg;
		var ul, strTag;
		strTag = "";
		$('#screenViewerWrap .imglstWrap').append('<ul/>');
		$.each(itemlist,function(key, item){
			ul = $('#screenViewerWrap .imglstWrap').children('ul');
			var strImg = item.thumb;
			strTag = "<li><div class='imgWrap'><div class='imgBox'>" + strImg + "</div></div></li>"
			ul.append(strTag);
		});
		$('#screenViewerWrap .imglstWrap .imgWrap img').each(function(){
			handleImage.setCenter(this);
			$(this).bind('click',function(){
				var index = $('#screenViewerWrap .imglstWrap .imgWrap img').index(this);
				handleImage.setScreenViewerMain(sObj,index);
				handleImage.scrollScreenViewerThumbnail(index);
			});
		});
		handleImage.scrollScreenViewerThumbnail(nowidx);
	},
	setThumbnailBG:function(index){
//		$('#screenViewerWrap .imglstWrap .imgBox').css({'backgroundColor':'#ffffff'}).eq(index).css({'backgroundColor':'#E7E7E7'});
		$('#screenViewerWrap .imglstWrap .imgBox img').addClass('filter').eq(index).removeClass('filter');
	},
	scrollScreenViewerThumbnail:function(index){
		var sObj = handleImage.sObj;
		var blockCnt = 5;
		var wrap = $('#screenViewerWrap .imglstWrap');
		var objItem = $('#screenViewerWrap li');
		if(index=='' || index < 0) index = 0;
		if(index >= objItem.length) index = objItem.length-1;
		var tpg = ((objItem.length % blockCnt)==0)?parseInt(objItem.length/blockCnt):parseInt(objItem.length/blockCnt)+1;
		var npg = parseInt((index)/blockCnt)+1;
		var intItemWidth = objItem.eq(0).width();
		var target = $('#screenViewerWrap ul');
		var intLeft = (npg-1) * blockCnt * intItemWidth;
		target.animate({marginLeft:-intLeft},800);
		handleImage.setScreenViewerMain(sObj, index);
		var la = $('#screenViewerWrap .prev');
		var ra = $('#screenViewerWrap .next');
		if (parseInt(index) <= 0){
			la.empty();
		}else{
			la.html('<a href="javascript:void(0);" title="이전" onclick="handleImage.scrollScreenViewerThumbnail(' + (index-1) + ');" onfocus="this.blur();"">이전</a>');
		}
		if (parseInt(index+1)==(objItem.length) || parseInt(index+1) > (objItem.length)){
			ra.empty();
		}else{
			ra.html('<a href="javascript:void(0);" title="다음" onclick="handleImage.scrollScreenViewerThumbnail(' + (index+1) + ');" onfocus="this.blur();"">다음</a>');
		}
		var title = contentsTitle + ' (' + (index + 1) + '/' + objItem.length + ')';
		$('#screenViewerWrap .titleBox h1').html(title);
	},
	setScreenViewerMain:function(objData, index){
		var objJson = objData.itemlist[index];
		var txt = objJson.main;
		var target = $("#screenViewerWrap .mainImageBox");
		var obj = target.html(txt).children();
		obj.ready(function(){handleImage.setCenter(obj);});
		handleImage.setThumbnailBG(index);
	},
	dplScreenshotEditor:function(){
		layout.setFullScreen();
		var target = $('.fullScreenCnts');
		$.post('/view/function/getTemplateScreenEditor.asp',function(data){
			target.html(data);
			handleImage.getScreenItems(handleImage.setScreenEditorItem);
			$("#screenfr input[name='contentsid']").val($("#transForm input[name='contentsid']").val());
			$("#screendelfr input[name='contentsid']").val($("#transForm input[name='contentsid']").val());
			$('#screenEditorfile').change(function(target){
				handleImage.uploadScreenshotSubmit(this);
			});
			target.children(':first-child').css({'top':$(document).scrollTop()+40});
			layout.setFullScreen();
		});
	},
	setScreenEditorItem:function(jsonObj){
		var itemlist = jsonObj.itemlist;
		var nowidx = jsonObj.nowimg;
		var target = $('.screenEditorWrap > .middle > .imgsWrap');
		var ul = $('<ul/>');
		if(itemlist.length){
			var strInner = '';
			$(itemlist).each(function(key, item){
				strInner += '<li class="screenEditorItem">';
				strInner += '<div class="imgWrap">';
				strInner += '<div class="outer"><div class="inner">';
				strInner +=  item.thumb;
				strInner += '</div></div>';
				strInner += '</div>';
				strInner += '<p class="btnBox"><a href="javascript:void(0)" onclick="handleImage.delScreenshot(' + item.srl + ');" title="삭제" onfocus=""this.blur();"">삭제</a></p>';
				strInner += '</li>';
			});
			ul.append(strInner);
			target.append(ul);
			$('.screenEditorItem .inner>img').each(function(){
				handleImage.setCenter(this);
			});
		}else{
			var strMsg = "<p class='announce'>등록된 스크린 샷이 없습니다.<br/>이미지 추가 버튼을 눌러 스크린 샷을 등록해 주세요<br/><br/>링뷰는 회원님들이 함께 만들어가는 서비스입니다.</p>";
			target.html(strMsg);
		}
	},
	uploadScreenshotSubmit:function(){
		var objform = $('#screenfr');
		var option = {
			url:'http://pdsup.enppy.com:8080/linview/fileuploadAjaxExec.asp',
			beforeSubmit:function(){
				return handleImage.uploadScreenshotChk(objform)
			},
			success:function(data){
				data = $.parseJSON(data);
				if(data.rtn == 'success'){
					handleImage.dplScreenshotEditor();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		objform.ajaxSubmit(option);
		return false;
	},
	uploadScreenshotChk:function(objform){
		var nowcnt = objform.find(":input[name='imgCnt']").val();
		var limitcnt = 20;
		if(nowcnt == '') {nowcnt= 0};
		if(parseInt(nowcnt) >= limitcnt){
			handleMsg.alert('screenLimitCnt',limitcnt);
			return false;
		}
		var objFname = objform.find(":input[type='file']");
		var fnameVal = $(objFname).val();
		var idx = fnameVal.lastIndexOf('\\');
		if(idx){fnameVal = fnameVal.substring(idx+1);}
		objform.find(":input[name='fname']").val(fnameVal);
	},
	closeScreenEditor:function(){
		layout.closeFullScreen();
		handleImage.reloadScreenSlider();
	},
	delScreenshot:function(srl){
		var objform = $('#screendelfr');
		objform.find(":input[name='DelSrl']").val(srl);
		var option = {
			url:'/view/function/delproxy.asp',
			beforeSubmit:function(){},
			success:function(data){
				data = $.parseJSON(data);
				if(data.rtn == 'success'){
					handleImage.dplScreenshotEditor();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		objform.ajaxSubmit(option);
		return false;
	}
}
var handlePoster= {
	dplPosterArea:function(){
		var objform = $('#transForm');
		var option = {
			url:'/view/function/getPosterArea.asp',
			beforeSubmit:function(){},
			success:function(data){
				var target = $(".posterWrap");
				target.html(data);
			}
		}
		objform.ajaxSubmit(option);
	},
	uploadingPosterChk:function(){
		var objform = $("#posterfr");
		var strname = objform.find(":input[type='file']").val();
		var arrname = strname.split(".");
		var strExt = arrname[arrname.length-1].toLowerCase();
		if(	strExt != "jpg" && strExt != "gif" && strExt!= "bmp" && strExt!= "png" &&strExt!= "jpeg"){
			alert("jpg, gif, png 형식의 이미지만 등록할 수 있습니다.");
			return false;
		}
		var fnameVal = strname;
		var idx = fnameVal.lastIndexOf('\\');
		if(idx){fnameVal = fnameVal.substring(idx+1);}
		objform.find(":input[name='fname']").val(fnameVal);
		handlePoster.uploadPosterSubmit();
	},
	uploadPosterSubmit:function(){
		var objform = $("#posterfr");
		var option = {
			url:'http://pdsup.enppy.com:8080/linview/fileuploadAjaxExec.asp',
			beforeSubmit:function(){},
			success:function(data){
				data = $.parseJSON(data);
				if(data.rtn == 'success'){
					handlePoster.dplPosterArea();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		objform.ajaxSubmit(option);
		return false;
	},
	showPoster:function(strUrl, strWidth, strHeight){
		var nxturl = "/contents/viewPoster.asp?url=" + encodeURIComponent(strUrl) + "&width=" + strWidth + "&height=" + strHeight;
		var intWidth = parseInt(strWidth) + 30;
		var intHeight = strHeight;

		strArgs = "width=" + intWidth + ",height=" + intHeight + ",resizable,status,scrollbars";
		var objWin = window.open(nxturl, "linviewposter",strArgs);
		objWin.focus();
	}
}
var handleSynop = {
	dplSynopEditor:function(){
		target = $('.synopWrap > .subCntsWrap')
		var option = {
			url:'/view/function/getSynopEditor.asp',
			success:function(data){
				target.html(data);
			}
		}
		$('#transForm').ajaxSubmit(option);
	},
	getSynopsis:function(){
		target = $('.synopWrap > .subCntsWrap')
		var option = {
			url:'/view/function/getSynop.asp',
			success:function(data){
				target.html(data);
			}
		}
		$('#transForm').ajaxSubmit(option);
	},
	uptSynopsis:function(){
		target = $('.synopWrap > .subCntsWrap')
		var option = {
			url:'/view/function/modifySynopsis.asp',
			method:'POST',
			success:function(data){
				handleSynop.getSynopsis();
			}
		}
		$('#synopfr').ajaxSubmit(option);
	}
}
var handleFile = {
	getFileLinkItems:function(callback){
		var option = {
			url:'/view/function/getFileLinkItems.asp',
			type:'POST',
			dataType:'json',
			success:callback
		}
		$('#transForm').ajaxSubmit(option);
	},
	dplEditFileLink:function(){
		var target = $('.filelinkWrap > .subCntsWrap');
		$.post('/view/function/getTemplateFileListEditor.asp',{},function(data){
			target.html('');
			target.append(data);
			handleFile.getFileLinkItems(handleFile.setEditFileList);
		});
	},
	dplFileLink:function(){
		handleFile.getFileLinkItems(handleFile.setFileList);
	},
	dplFileLinkAdd:function(){
		var target = $('.fullScreenCnts');
		$.post('/view/function/getTemplateFileLinkAdd.asp',{},function(data){
			target.html(data);
			layout.setFullScreen();
			target.children().css({'top':$(document).scrollTop()+20});
			$("#linksearchfr").find("input:[name='searchtxt']").focus();
			$("#linksearchfr").find("input:[name='cntsSrl']").val($("#transForm input:[name='cntsSrl']").val());
		});
	},
	setFileList:function(jsonObj){
		var target = $('.filelinkWrap > .subCntsWrap');
		var ul = $('<ul/>').attr({'class':'filelist'});
		var itemlist = jsonObj.itemlist;
		target.html('');
		if (itemlist.length){
			var strRtn = "";
			$.each(itemlist,function(key,item){
				var fname = item.fname;
				fname = decodeURIComponent(fname).replace(/\+/g," ")
				strRtn += "<li>";
				strRtn += "<p class=\"title\"><a href=\"javascript:void(0)\" onclick=\"var objwin=window.open('/fileleaf/" + item.srl  + "','enppyfileleaf','width=600,height=600,scrollbars=yes,left=100,top=100');objWin.focus();\" title=\"" + fname + "\">" + fname + "</a></p>";
				strRtn += "<div class=\"rightBox\"><p class=\"filesize\">" + item.fsize + "</p><p class=\"btnDown\"><a href=\"" + item.flink + "\" target=\"_blank\" onfocus=\"this.blur();\">다운로드</a></p></div>";
				strRtn += "<div class=\"clsCntsBottomLine001\"></div>";
				strRtn += "</li>";
			});
			ul.append(strRtn);
			target.append(ul);
			target.append('<p class="btnMore"><a href="javascript:void(0);" onclick="handleFile.toggleMore()" onfocus="this.blur();">더보기</a></p>');
			handleFile.toggleMore();
		}else{
			strRtn = "<p class=\"announce\">편집을 눌러 파일 링크를 추가해 주세요. 링뷰는 회원님들이 함께 만들어가는 서비스 입니다.</p>";
			target.append(strRtn);
		}
	},
	setEditFileList:function(jsonObj){
		var target = $('.filelinkWrap > .subCntsWrap >.listEditor>.itemlist');
		var itemlist = jsonObj.itemlist;
		var ul = $("<ul/>");
		if(itemlist.length){
			var strLst = "";
			$.each(itemlist,function(key,item){
				strLst += "<li>";
				strLst += "<p class='title'>" + decodeURIComponent(item.fname).replace(/\+/g," ") + "</p>";
				strLst += "<div class='rightBox'>";
				strLst += "	<span class='fsize'>" + item.fsize + "</span>";
				strLst += "	<p class='btnDel'><a href='javascript:void(0);' onclick='handleFile.delFileLink(" + item.linksrl + ");' onfocus='this.blur' title='삭제'>삭제</a></p>";
				strLst += "</div>";
				if(key +1 < itemlist.length){
					strLst += "<p class='clsCntsBottomLine001'></p>";
				}
				strLst += "</li>";
			});
			ul.append(strLst);
		}else{
			ul.append('<li>검색을 통해 파일 링크를 추가해 주세요. 링뷰는 회원님들이 함께 만들어가는 서비스 입니다.</li>');
		}
		target.append(ul);
	},
	setSearchFileList:function(jsonObj){
		var target = $('.filelinkAddWrap .cntslist');
		target.html('');
		var itemlist = jsonObj.itemlist;
		var ul = $('<ul/>');
		var strLst = "";
		if(itemlist.length){
			$.each(itemlist,function(key,item){
				strLst += "<li>";
				strLst += "<input type=\"checkbox\" name=\"fsrl\" class=\"chkbox\" value=\"" + item.srl + "\"/>";
				strLst += "<p class=\"title\">" + item.title + "</p>";
				strLst += "<p class=\"size\">" + item.size + "</p>";
				strLst += "<div class=\"tagWrap\">";
				if (item.strtag.length){
					$.each(item.strtag ,function(i, tag){
						strLst += tag
						if (i+1 < item.strtag.length){strLst += ','}
					});
				}else{
					strLst += "&nbsp;";
				}
				strLst += "</div>";
				strLst += "</li>";
			});
			$('.filelinkAddWrap .btnBox').find(".btnAdd, .naviBox").remove();
			$('.filelinkAddWrap .btnBox').find(".btnClose").css({'margin':'0px 15px 0px 0px','float':'right'});
			$('.filelinkAddWrap .btnBox').prepend('<p class="btnAdd"><a href="javascript:void(0);" onclick="handleFile.plusLink();">선택추가</a></p><div class="naviBox"></div>');
			$('.filelinkAddWrap .btnBox').find(".naviBox").append(handleFile.dplSearchFileNavi(jsonObj));
		}else{
			$('.filelinkAddWrap .btnBox').find(".btnAdd, .naviBox").remove();
			$('.filelinkAddWrap .btnBox').find(".btnClose").css({'margin':'0 auto','float':''});
		}
		ul.append(strLst);
		target.append(ul);
	},
	dplSearchFileNavi:function(jsonObj){
		var naviobj = jsonObj.navi;
		var rtn = "";
		var spg = parseInt(naviobj.spg);
		var epg = parseInt(naviobj.epg);
		var nowpg = parseInt(naviobj.nowpg);
		var blocksize = parseInt(naviobj.blocksize);
		var tpg = parseInt(naviobj.tpg);
		if(spg > 1){
			var prepg = spg - blocksize;
			if (prepg < 1){
				rtn = rtn + "<span class='prev'>이전</span>";
			}else{
				rtn = rtn + "<span class='prev'><a href='javascript:void(0);' onclick='handleFile.goSearchFile(" + prepg + ");' onfocus='this.blur();'>이전</a></span>";
			}
		}else{
			rtn = rtn + "<span class='prev'>이전</span>";
		}
		for(i = spg; i <= epg; i++){
			if (i == parseInt(nowpg)){
				rtn = rtn + "<span class='pgnum now'>" + i + "</span>";
			}else{
				rtn = rtn + "<span class='pgnum'><a href='javascript:void(0);' onclick='handleFile.goSearchFile(" + i + ");' onclick='this.blur();'>" + i + "</a></span>";
			}
		}
		if(epg < tpg){
			var nxtpg = epg + 1;
			if(nxtpg <= tpg){
				rtn = rtn + "<span class='next'><a href='javascript:void(0);' onclick='handleFile.goSearchFile(" + nxtpg + ");' onfocus='this.blur();'>이후</a></span>";
			}else{
				rtn = rtn + "<span class='next'>이후</span>";				
			}
		}else{
			rtn = rtn + "<span class='next'>이후</span>";
		}
		return rtn;
	},
	goSearchFile:function(pg){
		var objform = $("#linksearchfr");
		objform.find("input:[name='nowpg']").val(pg);
		handleFile.searchFileLink(pg);
	},
	delFileLink:function(flinkSrl){
		var objform = $("#filelinkfr");
		objform.find("input:[name='cntsSrl']").val($("#transForm input:[name='cntsSrl']").val());
		objform.find("input:[name='EnppyFileSrl']").val(flinkSrl);
		var option = {
			url:'/view/function/delFileLink.asp',
			method:'POST',
			success:function(data){
				data = $.parseJSON(data);
				handleFile.dplEditFileLink();
			}
		}
		objform.ajaxSubmit(option);
	},
	searchFileLink:function(pg){
		var objform = $("#linksearchfr");
		var option = {
			url:'/view/function/getFileListSearch.asp',
			method:'POST',
			dataType:'json',
			beforeSubmit:function(){
				var pgobj = objform.find("input:[name='nowpg']");
				if(pg){pgobj.val(pg);}else{pgobj.val(1)}
				return chkValid.filename(objform.find("input:[name='searchtxt']"))
			},
			success:handleFile.setSearchFileList
		}
		objform.ajaxSubmit(option);
		return false;
	},
	plusLinkChk:function(objform){
		var chkobj = objform.find("input[type='checkbox']:checked'");
		if(chkobj.size() ==0){
			handleMsg.alert('chkUptFilelinkChecked');
			return false;
		}
		return;
	},
	plusLink:function(){
		var objform = $('#linksearchfr');
		var option = {
			url:'/view/function/uptEnppyFilePlusLink.asp',
			beforeSubmit:function(){
				return handleFile.plusLinkChk(objform);
			},
			success:function(data){
				data = $.parseJSON(data);
				if(data.rtn == 'success'){
					objform.find("input:[name='nowpg']").val(1);
					handleFile.searchFileLink();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		objform.ajaxSubmit(option);
	},
	closeFileLinkAdd:function(){
		layout.closeFullScreen();
		handleFile.dplEditFileLink();
	},
	itemlistload:function(){
		handleFile.toggleMore();
	},
	toggleMore:function(){
		var target = $('.filelinkWrap').find('.filelist');
		var cnt = target.find('li').size();
		var height = target.find('li').eq(0).height();
		if(cnt > 4){
			var sheight = 4 * height;
			if($.browser.msie){
				if($.browser.version=='7.0') sheight = sheight + 5;
			}
			if(target.height() > sheight){
				target.css({'height':sheight,'overflow':'hidden'});
				target.next().find('a').text('더보기');
			}else{
				target.css({'height':'','overflow':'auto'});
				target.next().find('a').text('닫기');
			}
		}else{
			$('.filelinkWrap').find('.btnMore').hide();
		}
	},
	runDownloadAll:function(cntsSrl){
		if($.browser.msie){
			var url = 'http://www.enppy.com/getDownloadLink.asp?CntsSrl=' + cntsSrl
			document.getElementById('downloadid').src = url;
		}else{
			handleMsg.alert('checkIE');
		}
	}
}
var handleCmt = {
	regCmt:function(){
		var formobj = $('#cmtfr');
		var option = {
			url:'/view/function/regComment.asp',
			beforeSubmit:function(){
				var target = formobj.find("textarea");
				if(target.val().length==0){
					alert("한줄의견을 입력해 주세요");
					target.focus();
					return false;
				}
			},
			success:function(data){
				data = $.parseJSON(data);
				var target = formobj.find("textarea");
				if(data.rtn=="success"){
					handleCmt.getCommentList(handleCmt.setCommentList);
					handleProfile.getJoinInfo();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		formobj.ajaxSubmit(option);
		return false;
	},
	dplCommentList:function(){
		handleCmt.getCommentList(handleCmt.setCommentList);
	},
	setCommentList:function(jsonObj){
		target = $('.commentWrap .subCntsWrap');
		target.find('div.listWrap').remove();
		var divWrap = $('<DIV>').attr({'class':'listWrap'}).prependTo(target);
		var itemlist = jsonObj.itemlist;
		strLst = "";
		var nowuid = $('#transForm').find("input:[name='userid']").val();
		if(itemlist.length){
			var ul = $('<UL>');
			$.each(itemlist,function(key, item){
				//srl, uid, cnts, loginchk, homepg
				if(item){
					strLst += "<li srl='" + item.srl + "'>"
					if (nowuid != "" && nowuid != item.uid && item.loginchk ==1){
						strLst += "<p class='uname'><a>" + item.uid + "</a></p>"
					}else if(item.loginchk==0 && item.homepg !='http://'){
						strLst += "<p class='uname'><a href='" + item.homepg + "' target='_blank'>" + item.uid + "</a></p>"
					}else{
						strLst += "<p class='uname'>" + item.uid + "</p>"
					}
					var strCnts = decodeURIComponent(item.cnts);
					strCnts = strCnts.replace(/\+/g," ");
					strLst += "<div class='cmttxt'><span class='val'>" + strCnts + "</span>"
					if (nowuid == item.uid){
						strLst += "<span class='btnDel'><a href='javascript:void(0);' onclick='handleCmt.rmvComment(" + item.srl + ");' onfocus='this.blur();'><img src='/md/btn/btn_ss_delete.gif' border='0' onfocus='this.blur();'></a></span>";
					}else if(item.loginchk==0){
						strLst += "<span class='btnDel'><a href='javascript:void(0);' onclick='handleCmt.dplRmvCommentPwd(" + item.srl + ");' onfocus='this.blur();'><img src='/md/btn/btn_ss_delete.gif' border='0' onfocus='this.blur();'></a></span>";
					}
					strLst += "</div>"
					strLst += "<div class='cmtdate'>" + item.date + "</div>"
					strLst += "<p class='clsCntsBottomLine001'></p>"
					strLst += "</li>"
				}
			});
			ul.append(strLst);
			ul.appendTo(divWrap);
			var target = $("#cmtfr").find("textarea");
			target.val('');
		}else{}
	},
	getCommentList:function(callback){
		var formobj = $('#transForm');
		var option = {
			url:'/view/function/getCommentList.asp',
			method:'POST',
			dataType:'json',
			beforeSubmit:function(){},
			success:callback
		}
		formobj.ajaxSubmit(option);
	},
	rmvComment:function(cmtSrl){
		var formobj = $('#transForm');
		formobj.find(":input[name='cmtSrl']").val(cmtSrl);
		var option = {
			url:'/view/function/delComment.asp',
			method:'POST',
			beforeSubmit:function(){
				return confirm('정말 삭제하시겠습니까?');
			},
			success:function(data){
				var data = $.parseJSON(data);
				if(data.rtn == 'success'){
					handleCmt.dplCommentList();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		formobj.ajaxSubmit(option);
	},
	dplRmvCommentPwd:function(cmtSrl){
		$('.dplGetPwdWrap').remove();
		$.post('/view/function/getTemplateDelComment.asp',function(data){
			$(document.body).append(data);
			var target = $(".commentWrap LI[srl=" + cmtSrl + "]");
			var pobj = target.position();
			var obj = $('.dplGetPwdWrap');
			obj.css({'position':'absolute','top':pobj.top+10,'left':pobj.left+20});
			var objform = obj.find('form');
			var tmp = target.find(".uname");
			if(tmp.find('a').size()==0){
				var strtmp = target.find(".uname").text()
			}else{
				var strtmp = target.find(".uname a").text()
			}
			var input = $('<input>').attr({'type':'hidden','name':'cntsSrl'}).val($('#transForm').find("input[name='cntsSrl']").val());
			objform.append(input);
			var input = $('<input>').attr({'type':'hidden','name':'contentsid'}).val($('#transForm').find("input[name='contentsid']").val());
			objform.append(input);
			var input = $('<input>').attr({'type':'hidden','name':'cmtSrl'}).val(cmtSrl);
			objform.append(input);
			var input = $('<input>').attr({'type':'hidden','name':'writer'}).val(strtmp);
			objform.append(input);
			objform.find("input:password").focus();
		});
	},
	closeRmvCommentPwd:function(){
		$('.dplGetPwdWrap').remove();
		handleCmt.dplCommentList();
	},
	rmvCommentNotLogIn:function(){
		var objForm = $('#rmvCmtFr');
		var option = {
			url:'/view/function/delCommentNotLogin.asp',
			method:'POST',
			beforeSubmit:function(){
				if(objForm.find('input:password').val() == ''){
					alert('비밀번호를 입력해 주세요');
					return false;
				}
			},
			success:function(data){
				data = $.parseJSON(data);
				if(data.rtn=='success'){
					handleCmt.closeRmvCommentPwd();
				}else{
					handleMsg.alert(data.rtn);
				}
			}
		}
		objForm.ajaxSubmit(option);
		return false;
	},
	strlenChk:function(obj){
		var target = $(obj)
		var strLen = 1000;
		var str = $(obj).val();
		var byte1count = 0, byte2count = 0;
		var lsLen = 0;
		for( var i = 0; i < str.length; i++ ) {
			 thischar = str.charAt( i );
			if( ((thischar >= '0') && (thischar <= '9')) ||
				((thischar >= 'A') && (thischar <= 'Z')) ||
				((thischar >= 'a') && (thischar <= 'z')) ||
				((thischar == '-') || (thischar == '_')) ){
				 byte1count++;
			}else if( thischar == '(' || thischar == ')' ) {
				byte1count++;
			}else{
				 byte2count++;
			} 	
			if( (byte1count + byte2count * 2)  <= strLen){
				lsLen = i + 1;
			}	
		}
		if((byte1count + byte2count * 2) > strLen){
			alert("한줄의견은 최대 " + strLen + " 자까지 입력할 수 있습니다. 내용을 줄여서 등록해 주세요.");
			target.val(str.substring(0,lsLen));
		}
	}
}
var handleReview = {
	dplReviewWrap:function(ReviewSrl){
		var objForm = $('#transForm');
		var option = {
			url:'/view/function/getReviewWrap.asp',
			method:'POST',
			beforeSubmit:function(){},
			success:function(data){
				var target = $(".reviewWrap");
				target.html(data);
				handleProfile.getJoinInfo();
				if(ReviewSrl){
					handleReview.openMore(ReviewSrl);
				}
			}
		}
		objForm.ajaxSubmit(option);
	},
	openReviewInsert:function(){
		var url = "/review/ReviewInsert.asp";
		var args = "ContentsId=" + $("#transForm input:[name='contentsid']").val() + "&cntssrl=" +  $("#transForm input:[name='cntsSrl']").val();
		var objWin = window.open(url + "?" + args, 'InReview', 'width=550,height=550');
		objWin.focus();
	},
	openReviewModify:function(srl, CntsSrl, CntsID){
		var nxturl = "/review/ReviewModify.asp?srl=" + srl + "&CntsSrl=" + CntsSrl + "&CntsID=" + CntsID;
		window.open(nxturl,'inReview', 'width=550,height=550');
	},
	rmvReview:function(srl, CntsSrl, CntsID){
		var objForm = $("#transForm");
		objForm.find(":input[name='reviewSrl']").val(srl);
		if(confirm("정말 리뷰를 삭제하시겠습니까?")){
			var option = {
				url:'/review/ReviewDeleteExec.asp',
				method:'POST',
				beforeSubmit:function(){					
				},
				success:function(data){
					handleReview.dplReviewWrap();
				}
			}
			objForm.ajaxSubmit(option);
		}
	},
	toggleMore:function(reviewSrl){
		var pobj;
		$(".reviewBox > .reviewContents:[srl=" + reviewSrl + "]").each(function(i){
			if(i==0) pobj = $(this).parents(".reviewBox");
		});
		if (pobj.find(".more").hasClass("active")){
			handleReview.closeMore(reviewSrl);
		}else{
			handleReview.openMore(reviewSrl);
		}
	},
	openMore:function(reviewSrl){
		var pobj;
		$(".reviewBox > .reviewContents:[srl=" + reviewSrl + "]").each(function(i){
			if(i==0) pobj = $(this).parents(".reviewBox");
			if($(this).hasClass('more')){
				$(this).addClass('active')
			}else{
				$(this).removeClass('active');
			}
		});
		pobj.css({'border':'1px solid #DDE8ED'});
	},
	closeMore:function(reviewSrl){
		var pobj;
		$(".reviewBox > .reviewContents:[srl=" + reviewSrl + "]").each(function(i){
			if(i==0) pobj = $(this).parents(".reviewBox");
			if($(this).hasClass('more')){
				$(this).removeClass('active')
			}else{
				$(this).addClass('active');
			}
		});
		pobj.css({'border':'1px solid #FFFFFF'});
	},
	rcmdReview:function(CntsSrl, CntsId, ReviewSrl){
		var url = "/review/rcmdReview.asp"
		var objForm = $("#transForm");
		objForm.find(":input[name='reviewSrl']").val(ReviewSrl);
		var option = {
			url:'/review/rcmdReview.asp',
			method:'POST',
			dataType:'json',
			beforeSubmit:function(){					
			},
			success:function(data){
				handleMsg.alert(data.rtn);
				handleReview.dplReviewWrap(ReviewSrl);
			}
		}
		objForm.ajaxSubmit(option);
	},
	insertComment:function(ReviewSrl){
		var formobj = $("form:[name='reviewcmtfr']");
		var form;
		$.each(formobj,function(i){
			if($(this).attr("srl")==ReviewSrl){form = $(this);return false}
		});
		if(form){
			var formDOM = form.get(0);
			formDOM.cmttxt.value = trim(delTag(formDOM.cmttxt.value));
			if(isNothingMsg(formDOM.cmttxt, "댓글 내용을 넣어주세요.")){
				formDOM.cmttxt.focus();
				return(false);
			}
			var nxturl = "/review/reviewcmtInsertExec.asp";
			var option = {
				url:"/review/reviewcmtInsertExec.asp",
				method:"post",
				dataType:"json",
				beforeSubmit:function(){},
				success:function(data){
					handleReview.dplReviewWrap(ReviewSrl)
				}
			}
			formobj.ajaxSubmit(option);
		};
		return false;
	},
	rmvReviewComment:function(ReviewSrl, ReviewCmtSrl){
		if(confirm("정말 댓글을 삭제 하시겠습니까?")){
			var url = "/review/reviewcmtDeleteExec.asp";
			var option = {'ReviewSrl':ReviewSrl,'ReviewCmtSrl':ReviewCmtSrl}
			$.post(url,option,handleReview.dplReviewWrap(ReviewSrl));
		}
	},
	dplReviewComment:function(ReviewSrl,intPg){
		var url = "/review/getReviewCmt.asp";
		var option = {'ReviewSrl':ReviewSrl,'pg':intPg}
		$.post(url,option,function(data){
			var pObj = $(".reviewContents.more");
			pObj.each(function(i){
				if($(this).attr("srl") == ReviewSrl){
					$(this).show();
					var target = $(this).find(".reviewCommentBox");
					target.html(data);
				}
			});
		});
	}
}
var handleMsg = {
	chkImgMime:function(){return "jpg, gif, png, bmp 형식의 이미지만 등록할 수 있습니다."},
	screenLimitCnt:function(limitcnt){return "스크린 샷은 최대 " + limitcnt + " 개까지 등록할 수 있습니다."},
	uploadFalse:function(){return "정보 입력에 실패했습니다. 다시 시도해 주세요."},
	chkSMIMime:function(){return "smi 형식의 자막 파일만 등록할 수 있습니다."},
	chkImgSize:function(strSize){return "이미지 크기가 1024KB 를 넘습니다. 크기를 줄여 등록해 보세요."},
	chkSMISize:function(strSize){return "크기가 1024KB를 넘습니다. 용량이 작은 다른 자막을 등록해 주세요."},
	chkFileSize:function(strSize){return "파일 크기가 1024KB를 넘습니다. 크기를 줄여 등록해 보세요."},
	delFalse:function(){return "파일을 삭제하지 못하였습니다."},
	chkUptFilelinkChecked:function(){return "추가할 파일 링크를 선택해주세요."},
	delCmtFalse:function(){return "덧글을 삭제하지 못하였습니다."},
	delCmtChkPwd:function(){return "패스워드가 일치하지 않습니다."},
	cntsnotexists:function(){return "컨텐츠 정보를 찾을 수 없습니다."},
	voteduple:function(){return "이미 투표하셨습니다."},
	chkLogin:function(){return "로그인이 필요한 서비스 입니다."},
	rcmdReview:function(){return "추천하였습니다."},
	rcmdReviewAlready:function(){return "이미 추천한 리뷰 입니다."},
	rcmdReviewFalse:function(){return "해당 리뷰가 삭제되었거나, 오류가 발생하였습니다."},
	checkIE:function(){return "인터넷 익스플로어만 지원하는 기능입니다. 불편을 드려 대단히 죄송합니다."},
	alert:function(msgType,msgOpt){
		if($.isFunction(eval('handleMsg.' + msgType))){
			var strMsg = eval('handleMsg.' + msgType + '(' + msgOpt + ');');
			alert(strMsg);
		}else{
			alert('알 수 없는 오류 입니다 : ' + msgType);
		}
		return false;
	},
	alertEditBlock:function(){
		var target = $('.mainWrap > .popMsg');
		var strInner = "<div class=\"popMsgBox\"><p class=\"title\">편집이 제한된 페이지입니다.</p><p class=\"desc\">링뷰 운영자에 의해 편집이 제한된 페이지입니다.<br/>수정해야 할 사항이나 문의사항이 있으면, 상단의 신고 버튼을 눌러 자세한 내용을 적어 보내주세요.</p></div><a href=\"javascript:void(0);\" onclick=\"handleMsg.closeEditBlock()\"><img border=\"0\" src=\"/md/Btn/btn_s_close.gif\"/></a>";
		handleMsg.moveToCenter(target);
		target.html(strInner);
		target.show();
		return false;
	},
	closeEditBlock:function(){
		var target = $('.mainWrap > .popMsg');
		target.html('');
		target.hide();
		return false;
	},
	moveToCenter:function(obj){
		var pobj = obj.parent();
		var left = parseInt((pobj.width() - obj.width())/2);
		var top = document.documentElement.scrollTop-100;
		if (top <= 0 ) top = 10;
		obj.css({'top':top,'left':left});
	}
}
var handleVote = {
	vote:function(intVote){
		if(confirm(intVote + " 점을 선택하셨습니다. 평점은 1번만 선택할 수 있습니다. 적용하시겠습니까?")){
			var nxtLnk = ""
			var objForm = $('#transForm');
			var cntsSrl = objForm.find(":input[name='cntsSrl']").val();
			objForm.find(":input[name='intVote']").val(intVote);
			var option = {
				url:'/view/function/voteExec.asp',
				method:'POST',
				beforeSubmit:function(){
				},
				success:function(data){
					if(data.substring(0,2)!="OK"){
						var msg;
						switch (data){
							case "NK:CONTSNOTEXITS":
								handleMsg.alert("cntsnotexists");
								break;
							case "NK:CHKDUPL":
								handleMsg.alert("voteduple");
								break;
							case "NK:ERRIST":
							default:
								handleMsg.alert();
								break;
						}
						return false;
					}
					handleProfile.getProfile(cntsSrl);
				}
			}
			objForm.ajaxSubmit(option);
		}
		return false;
	},
	toggleStat:function(){
		var target = $('.voteWrap > .voteStatBox');
		target.toggle();
	}
}
var chkValid={
	filename:function(obj){
		return;
	}
}
var handleCommon={
	loginconfirm:function(){
		if(confirm("로그인 후 이용하실 수 있습니다. 로그인 하시겠습니까?")){
			document.location.href = "https://login.enppy.com/login/login.asp?returnurl=" + document.location.href;
		}
		return false;
	}
}
function executePds() {
	var winurl;
	winurl = "http://app.enppy.com/enppy30/run.asp?";
	window.open(winurl,'wnd_' + ap_random(),'width=500,height=500,scrollbars=no,status=yes,menubars=no');
	return false;
}
$(document).ready(function(){
	if($.browser.msie){//not mozillar,safari
		if($.browser.version=='6.0'){try{document.execCommand("BackgroundImageCache", false, true)}catch(e){}} //For IE6 Flicker
	}
	layout.setProfileSplit();
	layout.setCompleteGraph($("#transForm :input[name='intComplete']").val());
	handleImage.initScreenSlider();
	handleFile.itemlistload();
	handleCmt.dplCommentList();
});