var avatarPopup = {
	height : 491,
	getUserno : function(hompyid, hompyid_compare) {
	if ( hompyid_compare == hompyid && hompyid != undefined && hompyid_compare != undefined) {
		this.height = 436;
	}
		
		jQuery.post(
			"/avatar.jjang?cmd=getUserno",
			{
				hompyid : hompyid 
			},				
			function(json, textStatus) {
				if( textStatus == "success" ) {										
					avatarPopup.avaPop(json.userno);
				}
			},
			"json"
		);
	},
	avaPop : function(userno, compare_userno) {
		if ( userno == compare_userno && userno != undefined && compare_userno != undefined ){
			this.height = 436;
		}
		jQuery.post(
			"/avatar.jjang?cmd=getNoSeq",
			{
				userNo : userno
			},
			
			function(json, textStatus) {
				if( textStatus == "success" ) {										
					avatarPopup.avatarPreviewPopup(json.avtNo, json.tag, json.cate);
				}
			},
			"json"
		); 
	},
	
	previewAvatar : function(avtNo, tag, cate, check){
		if ( check == 3 || check == 1 ) {
			this.height = 436;
		}
		var avtNo = avtNo || 0;
		if(avtNo != '0'){
			this.avatarPreviewPopup(avtNo, tag, cate, check);
		}else{
			//아바타가 없을 경우
			alert("기본 아바타가 존재하지 않습니다.");
		}
	},
	
	avatarPreviewPopup: function(avtNo, tag, cate, check) {
		if ( check == 2 ) {
			this.height = 436;
		} else if ( check == 99 ) { //아바타 연동 이벤트
			this.height = 370;
		}
		var self = this;
		// 팝업창 동시에 두 개 띄우는 것 방지!!!
		// 기존에 열려있는 창 닫기
		if(self.varAvatarPreviewPopup){
			self.varAvatarPreviewPopup.close();
			self.varAvatarPreviewPopup = null;
		}

		var scrWidth	= (screen.availWidth / 2 ) - 419/2; 
		var scrHeight	= (screen.availHeight / 2) - 370/2;
		
		var url = "/jjangplaza.jjang?cmd=avatarPreviewPopup&avtNo=" + avtNo + "&title=null&avtContestSeq=0&tag=" + tag + "&category=" + cate + "&check=" + check;
 
		var str =
			"'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no," +
			"width=396,height="+this.height+"',top="+scrHeight+",left="+scrWidth;
		self.varAvatarPreviewPopup = window.open(url, "varAvatarPreviewPopup", str);

	}
};
