// div popupÃ¢ ¶ç¿ì±â(·¹ÀÌ¾îÇü½Ä)
function getCookie( name ){
        var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie.length )
        {
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie.length;
                        return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }
        return "";
}



isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;
isLayerPopup = false;
maxZIndex = 10;
ddEnabled=false;

function ddInit(e){
  topDog="HTML";
  whichDog=null;
  hotDog=isIE ? event.srcElement : e.target;

  if (isLayerPopup) {


	  while (hotDog.id!="layerTitleBar"&&hotDog.tagName!=topDog){

		hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
	  }
	  if (hotDog.id=="layerTitleBar"){
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;

		whichDog = hotDog;

		// ÆË¾÷ DIV °´Ã¼ Ã£±â
		while (whichDog.id.indexOf("theLayer") != 0 && whichDog.tagName!=topDog){
			whichDog=isIE ? whichDog.parentElement : whichDog.parentNode;
		}

		if (whichDog) {

			whichDog.style.zIndex = ++maxZIndex;
			nowX=parseInt(whichDog.style.left);
			nowY=parseInt(whichDog.style.top);
			ddEnabled=true;

			//·¹ÀÌ¾î ¹øÈ£¸¦ ±¸ÇÑ´Ù.
			var idx = whichDog.id.substr(8);
			var whichDogWidth = parseInt(whichDog.style.width);
			var whichDogHeight = parseInt(whichDog.style.height);

			coverDog = isIE ? eval("document.all.coverLayer" + idx) : document.getElementById("coverLayer" + idx);
			coverDog.style.width = whichDogWidth * 2;
			coverDog.style.height = whichDogHeight * 2;
			coverDog.style.top = whichDogHeight / -2;
			coverDog.style.left = whichDogWidth / -2;

			showMe(coverDog.id);

			document.onmousemove=dd;
		}
	  }
  }
}


function dd(e){

  if (!ddEnabled) {
	  return;
  }
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;

  return false;
}

function ddFree(e) {

	if (!ddEnabled) {
		return
	}
	ddEnabled = false;

	coverDog.style.width = 0;
	coverDog.style.height = 0;
	coverDog.style.top = 0;
	coverDog.style.left = 0;
	hideMe(coverDog.id);

}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
	N4.captureEvents(Event.MOUSEMOVE);
	N4x=e.x;
	N4y=e.y;
  }
  N4.onmousemove=function(e){
	if (isHot){
	  N4.moveBy(e.x-N4x,e.y-N4y);
	  return false;
	}
  }
  N4.onmouseup=function(){
	N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function layerClose(frameNm) {

	if (frameNm) {
		hideMe("theLayer" + frameNm.substr(11))
	}
}

function hideMe(layerNm){
  var layer = isIE ? eval('document.all.' + layerNm) : document.getElementById(layerNm);
  if (isIE||isNN) layer.style.visibility="hidden";
  else if (isN4) layer.visibility="hide";
  layer.style.display="block";
}


function showMe(layerNm){

  var layer = isIE ? eval('document.all.' + layerNm) : document.getElementById(layerNm);
  if (isIE||isNN) layer.style.visibility="visible";
  else if (isN4) layer.visibility="show";
}

document.onmousedown=ddInit;
document.onmouseup=ddFree;