/********************************************************
 * div
 ********************************************************/
function setDropmenuDiv() {
	if (ie4||ns6) {
		document.write('<div id="dropmenudiv" onMouseover="clearhidemenu()" class="lay" onMouseout="dynamichide(this,event)"></div>');
	}
}

/********************************************************
 * layer design
 ********************************************************/
function getMiniLayerDesign(nick,user) {
    
	var str = '';
		str += '<table width="80" border=0 cellspacing="0" cellpadding="0">';
		str += '<tr height="60" valing="middle"><td style="padding-left:14"><a class="b" href="javascript:profilePop(\''+user+'\')" onMouseOver="window.status=(\'\');return true;" onMouseOut="window.status=(\'\');return true;" onfocus=this.blur()>ÇÁ·ÎÇÊº¸±â</a><br>';
		str += '<a class="b" href="javascript:noteFriend(\''+user+'\')" onMouseOver="window.status=(\'\');return true;" onMouseOut="window.status=(\'\');return true;" onfocus=this.blur()>Ä£±¸ µî·Ï</a><br>';
		str += '<a class="b" href="javascript:notePop(\''+nick+'\',\''+user+'\')" onMouseOver="window.status=(\'\');return true;" onMouseOut="window.status=(\'\');return true;" onfocus=this.blur()>ÂÊÁöº¸³»±â</a></td></tr>';
		str += '</table>';

	return str;
}



////////////////////////////////////////////
// With Ajax
//  General setTimeout Class

function CCallWrapper(aObjectReference, 
                      aDelay,
                      aMethodName, 
                      aArgument0,
                      aArgument1,
                      aArgument2,
                      aArgument3,
                      aArgument4,
                      aArgument5,
                      aArgument6,
                      aArgument7,
                      aArgument8,
                      aArgument9
                      )
{

  this.mId = 'CCallWrapper_' + (CCallWrapper.mCounter++);
  this.mObjectReference = aObjectReference;
  this.mDelay     = aDelay;
  this.mTimerId = 0;
  this.mMethodName = aMethodName;
  this.mArgument0 = aArgument0;
  this.mArgument1 = aArgument1;
  this.mArgument2 = aArgument2;
  this.mArgument3 = aArgument3;
  this.mArgument4 = aArgument4;
  this.mArgument5 = aArgument5;
  this.mArgument6 = aArgument6;
  this.mArgument7 = aArgument7;
  this.mArgument8 = aArgument8;
  this.mArgument9 = aArgument9;
  
  //alert(this.mObjectReference[this.mMethodName]);
      
  CCallWrapper.mPendingCalls[this.mId] = this;
}

CCallWrapper.prototype.execute = function()
{
    
  this.mObjectReference[this.mMethodName](this.mArgument0,
                                          this.mArgument1,
                                          this.mArgument2,
                                          this.mArgument3,
                                          this.mArgument4,
                                          this.mArgument5,
                                          this.mArgument6,
                                          this.mArgument7,
                                          this.mArgument8,
                                          this.mArgument9
                                          );
  
  delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.prototype.cancel = function()
{
  clearTimeout(this.mTimerId);
  delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.asyncExecute = function (/* CCallWrapper */ callwrapper)
{
  
  CCallWrapper.mPendingCalls[callwrapper.mId].mTimerId = setTimeout('CCallWrapper.mPendingCalls["' + callwrapper.mId + '"].execute()', callwrapper.mDelay);
  
};

CCallWrapper.mCounter = 0;
CCallWrapper.mPendingCalls = {};


////////////////////////////////////////////
// CPopup



function CPopup(triggerobj, etype, popupid, contents, xorigin, yorigin, xoffset, yoffset, checkedge)
{
    
	this.triggerobj = triggerobj;
	this.etype = etype;
	this.contents = contents;
	this.popupid = popupid;
	this.xorigin = xorigin;
	this.yorigin = yorigin;
	this.xoffset = xoffset;
	this.yoffset = yoffset;
	this.checkedge = checkedge;
	this.popupobj= document.getElementById(popupid)
	
}

CPopup.prototype.hide = function()
{
	if (ie4||ns6)
		this.popupobj.style.visibility="hidden"
}

CPopup.prototype.show = function()
{
    
	if (ie4||ns6)
	{		
	    
		var pos = YAHOO.util.Dom.getXY(this.triggerobj)
		this.popupobj.x=pos[0]
		this.popupobj.y=pos[1]

		// remove origin
		if( this.xorigin == "right" ) this.popupobj.x += this.triggerobj.offsetWidth
		if( this.yorigin == "top" ) this.popupobj.y -= this.triggerobj.offsetHeight

		// add offset
		this.popupobj.x += this.xoffset
		this.popupobj.y += this.yoffset

		if(ie4) {
			this.popupobj.style.left=this.popupobj.x-((this.checkedge==true)? this.clearbrowseredge("rightedge"):0)-5+"px"
		} else if(ns6) {
			this.popupobj.style.left=this.popupobj.x-((this.checkedge==true)? this.clearbrowseredge("rightedge")-9:0)-5+"px"
		}
		this.popupobj.style.top=this.popupobj.y-((this.checkedge==true)? this.clearbrowseredge("bottomedge")+7:0)+this.triggerobj.offsetHeight-10+"px"

        this.popupobj.style.position = 'absolute';
		this.popupobj.innerHTML=this.contents;
		this.showhide(this.popupobj)

	}

	if (ie4||ns6)
		return false
	else
		return true
}

CPopup.prototype.isshow = function()
{

	if (ie4||ns6)
		if( this.popupobj.style.visibility =="visible" )
			return true
		else
			return false

}

CPopup.prototype.getid = function()
{
	return this.popupid;
}

CPopup.prototype.showhide = function(obj)
{
    
	if (! (ie4||ns6) )
		obj.style.left=obj.style.top="-500px"

	if (this.etype=="click" && ( obj.style.visibility=="hidden" || obj.style.visibility=="" ) || this.etype=="mouseover")
		obj.style.visibility="visible"
	else if (this.etype=="click")
		obj.style.visibility="hidden"
		
	return true;
}

CPopup.prototype.clearbrowseredge = function(whichedge)
{
	var edgeoffset=0
	if (whichedge=="rightedge")
	{
		var windowedge=ie4 && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		this.popupobj.contentmeasure=this.popupobj.offsetWidth
		if (windowedge-this.popupobj.x < this.popupobj.contentmeasure)
			edgeoffset=this.popupobj.contentmeasure-this.triggerobj.offsetWidth
	}
	else
	{
		var topedge=ie4 && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		this.popupobj.contentmeasure=this.popupobj.offsetHeight

		if (windowedge-this.popupobj.y < this.popupobj.contentmeasure)
		{
			//move up?
			edgeoffset=this.popupobj.contentmeasure+this.triggerobj.offsetHeight
			if ((this.popupobj.y-topedge)<this.popupobj.contentmeasure) //up no good either?
			edgeoffset=this.popupobj.y+this.triggerobj.offsetHeight-topedge
		}
	}
	return edgeoffset
}

CPopup.prototype.iecompattest = function()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


////////////////////////////////////////////
// Global Fuction

var g_ShowCall = null;
var g_HideCall = null;
var g_popup = null;

function dropdownmenu(triggerobj, e, contents, popupid, xorigin, yorigin, xoffset, yoffset, checkedge)
{
	delaytime = 100;
	
	if (window.event)
		event.cancelBubble=true
	else if (e.stopPropagation) 
		e.stopPropagation()

	var popup = new CPopup( triggerobj, e.type, popupid, contents, xorigin, yorigin, xoffset, yoffset, checkedge );
	var callwrapper = new CCallWrapper(popup, delaytime, 'show');
	CCallWrapper.asyncExecute(callwrapper);
	g_ShowCall = callwrapper;
	g_popup = popup;
	
}

function delayhidemenu(objid)
{
	if( g_popup )
	{
		if( g_popup.isshow() )
		{
			g_HideCall = new CCallWrapper(g_popup, 200, 'hide');
			CCallWrapper.asyncExecute(g_HideCall);
		}
		
		if( g_ShowCall )
		{
			g_ShowCall.cancel();
			delete g_ShowCall;
			g_ShowCall = null;
		}
	}
}

function dynamichide(obj, e)
{
	// call by popup. if mouse pointer is out of popup, hide window
	
	if (ie4&&!obj.contains(e.toElement))
		delayhidemenu(obj.id)
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu(obj.id)	
}

function contains_ns6(a, b)
{
	while (b.parentNode)
	if ((b = b.parentNode) == a)
		return true;

	return false;
}

function clearhidemenu()
{
	if( g_HideCall )
	{
		g_HideCall.cancel()
		delete g_HideCall;
		g_HideCall = null
	}
}

function clickreturnvalue()
{
	if (ie4||ns6)
		return false
	else
		return true
}






















// withOut Ajax


var returnDrop = false;
function SideView(curObj, nick, user)
{

	var oSideViewLayer = document.getElementById('dropmenudiv');

	if (oSideViewLayer.style.display=="none")
	{
		oSideViewLayer.style.display=""
		if (getAbsoluteTop(curObj) +curObj.offsetHeight + oSideViewLayer.scrollHeight + 5 > document.body.scrollHeight)
			oSideViewLayer.style.top = getAbsoluteTop(curObj) - oSideViewLayer.scrollHeight - 35;
		else
			oSideViewLayer.style.top = getAbsoluteTop(curObj) + curObj.offsetHeight - 18;

		oSideViewLayer.style.left = getAbsoluteLeft(curObj) - curObj.offsetWidth + 65;

		var str = '';
		str += '<table width="70" border=0 cellspacing="1" cellpadding="0" bgcolor="#333333">';
		str += '<tr height="42"><td bgcolor="#FFFFFF" style="padding-left:4" onmouseout="clickreturnvalue(\'hidden\')"><a class="b" href="javascript:profilePop(\''+user+'\')">ÇÁ·ÎÇÊº¸±â</a><br>';
		str += '<a class="b" href="javascript:noteFriend(\''+nick+'\',\''+user+'\')">Ä£±¸µî·Ï</a>';
		str += '<a class="b" href="javascript:notePop(\''+nick+'\',\''+user+'\')">ÂÊÁöº¸³»±â</a></td></tr>';
		str += '</table>'

		oSideViewLayer.innerHTML = str;
		returnDrop = true;
	}
	else
	{
		oSideViewLayer.style.display="none";
	}
}

	function getAbsoluteTop(oNode)
	{
		var oCurrentNode=oNode;
		var iTop=0;

		while(oCurrentNode.tagName!="BODY") {
			iTop+=oCurrentNode.offsetTop - oCurrentNode.scrollTop;
			oCurrentNode=oCurrentNode.offsetParent;
		}
		return iTop;
	}


    function getAbsoluteLeft(oNode)
    {
        var oCurrentNode=oNode;
        var iLeft=0;
        iLeft+=oCurrentNode.offsetWidth;
        while(oCurrentNode.tagName!="BODY") {
			iLeft+=oCurrentNode.offsetLeft;
			oCurrentNode=oCurrentNode.offsetParent;
        }

        return iLeft;
    }


function hideDropLayer()
{
	var oSideViewLayer = document.getElementById('dropmenudiv');
	if (oSideViewLayer)
	{
		oSideViewLayer.style.display="none";
	}
}

function clickreturnvalue(layermode)
{
	var oSideViewLayer = document.getElementById('dropmenudiv');
	
//	if (layermode=="show")
//	{
//		oSideViewLayer.style.display="";
//	}
//	else
//	{
//		oSideViewLayer.style.display="none";
//	}

}