var IdMenu = function() {
	this.isMenuOver = false;
	this.menuOverColor = "#e4ff75";
	this.menuOutColor = "#ffffff";
}

// 메뉴, 이벤트 핸들러 설정
IdMenu.prototype.init = function(menuId, onMouseDown) {
	this.menuId = menuId;
	document.onclick = onMouseDown;
}

// 메뉴에 마우스 올렸을때 이벤트 핸들러
IdMenu.prototype.menuOver = function(e, targetObj, targetId) {
	var event = e || window.event;
	this.isMenuOver = true;
	this.changeColor(targetObj);
}

// 메뉴에 마우스 빠졌을때 이벤트 핸들러
IdMenu.prototype.menuOut = function(targetObj) {
	this.isMenuOver = false;
	this.changeColor(targetObj);
}

// 메뉴색 변경
IdMenu.prototype.changeColor = function(targetObj) {
	if (typeof targetObj.isPainted == 'undefined') {
		targetObj.isPainted = false;
	}
	targetObj.style.backgroundColor = targetObj.isPainted? this.menuOutColor : this.menuOverColor;
	targetObj.isPainted = !targetObj.isPainted;
	
}

IdMenu.prototype.hide = function(){
 		idMenuDiv.style.display='none';
}
 

var idMenu = new IdMenu();


var idMenuLayer = '<div id="idMenuDiv" style="position:absolute;display:none;left:10;top:10;z-index:2;" >                                                                                                                         \n'
idMenuLayer += '<table width="100" border="0" cellspacing="1" cellpadding="0" bgcolor="#B6B6B6" >                                                                                                                                       \n'
idMenuLayer += '	<tr>                                                                                                                                                                                                                   \n'
idMenuLayer += '		<td>                                                                                                                                                                                                                 \n'
idMenuLayer += '			<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#FFFFFF">                                                                                                                                  \n'
idMenuLayer += '				<tr>                                                                                                                                                                                                             \n'
idMenuLayer += '					<td style="padding:3px 0 0 10px" height="23" onmouseout="idMenu.menuOut(this);" onmouseover="idMenu.menuOver(event, this, \'none\');" onclick="profile.validate(\'blog\');"><span>Блог</span></td>       \n'
idMenuLayer += '					</tr><tr>                                                                                                                                                                                                      \n'
idMenuLayer += '					<td background="fx_images/common/dot.gif" height="1"></td>                                                                                                                                                     \n'
idMenuLayer += '					</tr><tr>                                                                                                                                                                                                      \n'
idMenuLayer += '					<td style="padding:2px 0 0 10px" height="22" onmouseout="idMenu.menuOut(this);" onmouseover="idMenu.menuOver(event, this, \'none\');" onclick="profile.validate(\'msg\');"><span>Зурвас Илгээх</span></td>        \n'
idMenuLayer += '					</tr><tr>                                                                                                                                                                                                      \n'
idMenuLayer += '					<td background="fx_images/common/dot.gif" height="1"></td>                                                                                                                                                     \n'
idMenuLayer += '					</tr><tr>                                                                                                                                                                                                      \n'
idMenuLayer += '					<td style="padding:2px 0 0 10px" height="22" onmouseout="idMenu.menuOut(this);" onmouseover="idMenu.menuOver(event, this, \'none\');" onclick="profile.validate(\'buddy\');"><span>Найзаар Нэмэх</span></td>        \n'
idMenuLayer += '				</tr>                                                                                                                                                                                                            \n'
idMenuLayer += '			</table>                                                                                                                                                                                                           \n'
idMenuLayer += '		</td>                                                                                                                                                                                                                \n'
idMenuLayer += '	</tr>                                                                                                                                                                                                                  \n'
idMenuLayer += '</table>                                                                                                                                                                                                                \n'
idMenuLayer += '</div>                                                                                                                                                                                                                  \n';


var idMenuLayer2 = '<div id="idMenuDiv" style="position:absolute;display:none;left:10;top:10;z-index:2;" >                                                                                                                         \n'
idMenuLayer2 += '<table width="100" border="0" cellspacing="1" cellpadding="0" bgcolor="#B6B6B6" >                                                                                                                                       \n'
idMenuLayer2 += '	<tr>                                                                                                                                                                                                                   \n'
idMenuLayer2 += '		<td>                                                                                                                                                                                                                 \n'
idMenuLayer2 += '			<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#FFFFFF">                                                                                                                                  \n'
idMenuLayer2 += '				<tr>                                                                                                                                                                                                             \n'
idMenuLayer2 += '					<td style="padding:3px 0 0 10px" height="23" onmouseout="idMenu.menuOut(this);" onmouseover="idMenu.menuOver(event, this, \'none\');" onclick="profile.validate(\'blog\');"><span>Блог</span></td>       \n'
idMenuLayer2 += '				</tr>                                                                                                                                                                                                            \n'
idMenuLayer2 += '			</table>                                                                                                                                                                                                           \n'
idMenuLayer2 += '		</td>                                                                                                                                                                                                                \n'
idMenuLayer2 += '	</tr>                                                                                                                                                                                                                  \n'
idMenuLayer2 += '</table>                                                                                                                                                                                                                \n'
idMenuLayer2 += '</div>                                                                                                                                                                                                                  \n';
//
var Profile = function() {
	this.userId;
	this.targetId;
	this.openType;
}

// 메뉴 팝업, 클릭시 설정 초기화
Profile.prototype.popMenu = function(userId, targetId, openType) {
	this.userId = userId;
	this.targetId = targetId;
	this.openType = openType;
}


// 메뉴 클릭시 이벤트 핸들러
Profile.prototype.onMouseDown = function(e) {
	var event = e || window.event;
	var eventTarget = event.target || event.srcElement;
	var event_check = false;
	
	if (!this.isMenuOver) {
		idMenu.hide();
	}
	
	try {
		event_check = (eventTarget.href.indexOf("javascript:profile.popMenu(") > -1);
	} catch(e) { }
	
	
	if (event_check) {
		var xPos = event.pageX || event.clientX;
		var yPos = event.pageY || event.clientY;
	
		yPos += document.body.scrollTop;
		
	  idMenuDiv.style.pixelLeft = xPos; //콘텍스트 메뉴의 가로위치
	  idMenuDiv.style.pixelTop = yPos; //콘텍스트 메뉴의 세로위치를 지정한후
	  idMenuDiv.style.display=''; //콘텍스트 메뉴를 보인다.
	}
}

Profile.prototype.validate = function(key) {
	switch(key) {
		case "blog" :
			document.location.href = 'blog.do?blogId='+ this.targetId;
			break;
			
		case "msg" :
			window.open("/msg_form.do?targetMemberId=" + this.targetId + "&popup=Y","popMsgForm","width=400,height=300,status=no,scrollbars=no");	
			break;
			
		case "buddy" :
			window.open("/blog_buddy_form.do?blogId=" + this.targetId,"popBuddyForm","width=400,height=300,status=no,scrollbars=no");	
			break;
	}
}

var profile = new Profile();

