/**
 * ¾Öµå°ü¸®ÀÚ ·¹ÀÌ¾î ÄÁÆ®·Ñ·¯
 * @author ¹Ú³­ÇÏ
 * @date 2008-03-20
 */
function nDrag() {
	this.activeWindow = null;
	this.startEventPos = null;
	this.startPosWindow = null;
	this.cookieName = null;
	this.moveCounter = -1;
	this.evt = null;
	this.setOptions = {
		'targetID': 'nnLayer'
	};
}

nDrag.prototype.init = function(evt, options) {
	Object.extend(this.setOptions, options || '');
	if( document.all ) this.evt = window.event;
	else this.evt = evt;

	this.moveCounter = 0;
	this.activeWindow = document.getElementById(this.setOptions.targetID);
	this.startEventPos = [this.evt.clientX, this.evt.clientY];
	this.startPosWindow = [this.activeWindow.offsetLeft, this.activeWindow.offsetTop];
	this.startMove();

	document.documentElement.onmousemove = this.moveNoticeMain.bindEvent(this);
	document.documentElement.onmouseup = this.mouseUP.bindEvent(this);
	document.documentElement.onselectstart = this.cancelEvent.bindEvent(this);

	disableSelection(document.documentElement);
};
nDrag.prototype.moveNoticeMain = function(e) {
	if( this.moveCounter >= 10 ) {
		this.activeWindow.style.left = this.startPosWindow[0] + e.clientX - this.startEventPos[0]  + 'px';
		this.activeWindow.style.top = this.startPosWindow[1] + e.clientY - this.startEventPos[1]  + 'px';
	}
};
nDrag.prototype.startMove = function() {
	if( this.moveCounter >= 0 && this.moveCounter <= 10 ) {
		this.moveCounter++;
		setTimeout(this.startMove.bindEvent(this), 5);
	}
};
nDrag.prototype.close = function(targetID) {
	var targetID = targetID || this.setOptions.targetID;
	document.getElementById(targetID).style.display = "none";

	var date = new Date;
	date.setDate( date.getDate() + 1 );
	gdate = date.toGMTString();
	document.cookie = cookieName + '=admngPopupCheck;path=/;expires='+gdate;
};
nDrag.prototype.close2 = function(targetID) {
	var targetID = targetID || this.setOptions.targetID;
	document.getElementById(targetID).style.display = "none";
};
nDrag.prototype.mouseUP = function() {
	this.moveCounter = -1;
	document.documentElement.onmousemove = null;
	document.documentElement.onmouseup = null;
	document.documentElement.onselectstart = null;
	document.documentElement.style.MozUserSelect = '';
	document.documentElement.style.KhtmlUserSelect = '';
};
nDrag.prototype.cancelEvent = function() {
	return false;
};

/**
 * ¿ÀºêÁ§Æ® È®Àå
 * @param {Object} destination
 * @param {Object} source
 * @return {Object}
 */
Object.extend = function(destination, source) {
	for(var property in source) {
		destination[property] = source[property];
	}
	return destination;
};

Function.prototype.bindEvent = function() {
	for ( var i = 0, method = this , args = [] , len = arguments.length ; i < len ; i++ ) {
		args.push( arguments[ i ] );
	}
	return function(event) {
		return method.apply( args[0] , [event || window.event].concat(args.slice(1)) );
	}
};

function disableSelection(element) {
	element.onselectstart = function() {
		return false;
	};
	element.unselectable = "on";
	element.style.MozUserSelect = "none";
	element.style.cursor = "default";
}

/**
 * ÆäÀÌÁö ³Êºñ °ª °¡Á®¿À±â
 * quirkmode.com °¨»ç ^^
 * @param {Void}
 * @return {Array}
 */
function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, xScroll, yScroll);
	return arrayPageSize;
}