/*레이어팝업 */
var docPopup;
if (docPopup == undefined) {
	docPopup = function (settings) {


		this.init(settings);
	};
}
docPopup.prototype.createWindow = function(settings){

	var this_s = this;
	this.settings = settings;
	//alert(settings);
	

	//지정된 객체가 없을경우
	if(this.settings.obj!=undefined){
		
		this.winWrap = $(this.settings.obj);
		this.bodyPannel = $(".popWinBody",this.winWrap);
		this.backPannel = $(".popDocBg",this.winWrap);

	}else{
		//윈도우 프레임 생성
		var windowWrap = document.createElement("div");
		windowWrap.className="popWindowDoc";
		$("body").prepend(windowWrap);
		
		//배경 패널 생성
		var windowPan = document.createElement("div");
		windowPan.className = "popDocBg";
		$(windowWrap).append(windowPan);
		
		//내용 패널 생성
		var winBody = document.createElement("div");
		winBody.className="popWinBody";
		$(windowPan).append(winBody);
		
		
		this.bodyPannel = $(winBody);
		this.backPannel = $(windowPan);
		this.winWrap = $(windowWrap);

	}
	
	//배경클릭시 창닫기
	this.backPannel.click(function(){			this_s.hideWindow();	});

	//닫기버튼 창닫기 
	this.setCloseBtns();
	
	//전체 프레임 크기	
	this.winDocSize = {"width":this.winWrap.width(),"height":this.winWrap.height()};

	this.initBody();
	$(this.winWrap).hide();

}
docPopup.prototype.showWindow =function(){
	var this_s = this;
	this.backPannel.css({"opacity":0});
	this.winWrap.show();
	
	this.backPannel.animate({"opacity":0.8},1000,function(){
		this_s.initBody();
		//this_s.setBodySize();
		this_s.showContents();
		//setTimeout(function(){this_s.showContents()},1000);
	});

}
docPopup.prototype.hideWindow = function(){
	var this_s = this;

	this.backPannel.animate({"opacity":0},500,function(){
		
		if(this_s.settings.remove)		this_s.winWrap.remove();
		else	{
			//this_s.setSize(50,50);
			
			this_s.winWrap.hide();
		}

	});
	clearTimeout(this_s.timer);

	if(this_s.settings.remove){}else{
			this_s.setSize(50,50);

	}


	
}
docPopup.prototype.initBody = function(){

	clearTimeout(this.timer);
	$(this.bodyPannel).css({"overflow":"hidden","position":"relative","border":"0px solid red"});//
	$(">div:first-child",this.bodyPannel).hide();
	$(this.bodyPannel).width("1000");
	$(this.bodyPannel).height("650");
	//this.setPosition();
	var initPos = getCenterPos({"offsetWidth":this.winDocSize.width,"offsetHeight":this.winDocSize.height},{"offsetWidth":1000,"offsetHeight":650});
	$(this.bodyPannel).offset({"left":initPos.left,"top":initPos.top});

	//this.setSize(this.settings.w,this.settings.h);
}
docPopup.prototype.setBodySize = function(){
	this.setSize(this.settings.w,this.settings.h);
}
docPopup.prototype.setPosition = function(){
	var w = $(this.bodyPannel).width();
	var h = $(this.bodyPannel).height();
	var toPos = getCenterPos({"offsetWidth":this.winDocSize.width,"offsetHeight":this.winDocSize.height},{"offsetWidth":w,"offsetHeight":h});
	$(this.bodyPannel).offset({"left":toPos.left,"top":toPos.top})
}
docPopup.prototype.setSize= function(toSizeW,toSizeH){
	var this_s = this;
	var w = $(this.bodyPannel).width();
	var h = $(this.bodyPannel).height();

	
	////오차범위가 3내외
	var gapW = toSizeW - w;
	var gapH = toSizeH - h;
	var chkW = false;
	var chkH = false;
	if(Math.abs(gapW)>3) {
		var reSizeW =  w + (gapW/5);
		$(this.bodyPannel).width(reSizeW);
	}else{
		chkW = true;
		$(this.bodyPannel).width( toSizeW);
	}
	if(Math.abs(gapH)>3) {
		var reSizeH =  h + (gapH/5);
		$(this.bodyPannel).height(reSizeH);
	}else{
		chkH = true;
		$(this.bodyPannel).height( toSizeH);
	}
	
	if(!chkW || !chkH) 	this.timer = setTimeout(function(){this_s.setSize(toSizeW,toSizeH)},1);
	//this.setPosition();

}
docPopup.prototype.showContents = function () {
	if(this.settings.contShow){
		this.settings.contShow();
		//eval(this.settings.contShow);
	}
}
docPopup.prototype.init = function (settings) {
	var this_s = this;
	
	this.createWindow(settings);
	if(settings.show) this.showWindow();
	
	return;
	
	
	
	//$(msg_body).draggable({ handle: 'div.pop_winTop',scroll: true,helper: 'original'});
	//$("div").disableSelection();

	if(settings.w!=undefined) msg_body.style.width =settings.w ;
	if(settings.h!=undefined) msg_body.style.height =settings.h ;
	
	$(msg_wrap).append(msg_body);
	setCenterPos(msg_wrap,msg_body);
	this.title = "";

	if(settings.title)  this.title = settings.title;
	if(settings.setStyle){

		var winDocWrap = document.createElement("div");
		var winDocTop = document.createElement("div");

		$(winDocWrap).addClass("pop_winWrap");
		$(winDocTop).addClass("pop_winTop");
		$(winDocTop).css("cursor","move");
		$(winDocTop).append("<span class='pop_title'>"+this.title+"</span>");

		var winCloseBtn = document.createElement("span");
		$(winCloseBtn).addClass("pop_close");
		$(winCloseBtn).css("cursor","pointer");
		$(winCloseBtn).html("<img src='http://web.cs21.com/_Img/Common/sbtn_close.gif'http://web.cs21.com/>");
		$(winCloseBtn).click(function(){this_s.close();	});
		$(winDocTop).append(winCloseBtn);

		$(winDocWrap).append(winDocTop);
		$(winDocWrap).append("<div class='pop_winBody'><div class='pop_body'></div></div>");
		//$(winDocWrap).append("<div class='pop_body'></div>");

		$(winDocWrap).append("<div class='pop_winFoot'></div>");

		$(msg_body).append($(winDocWrap));
		this.bodyPannel = $(".pop_winBody ",$(winDocWrap));
		//this.bodyPannel = $(".pop_body ",$(winDocWrap));
		
		var tmpTopH =$(winDocWrap).height() -  ($(winDocTop).height() + $(".pop_winFoot",winDocWrap).height());
		var tmpTopW =$(winDocWrap).width() -  20;
		$(".pop_winBody ",$(winDocWrap)).height(tmpTopH-10);
		//$(".pop_body ",$(winDocWrap)).height(tmpTopH-10);
		//
		//$($(this.bodyPannel)).width($(".pop_winBody").width()-20);
		//this.bodyPannel.height(tmpTopH-10);
		
	}else{
		this.bodyPannel = msg_body;
	}

	$(this.bodyPannel).append(settings.msgWinDoc);

	if(settings.closeBtns){
		for(var i=0; i<settings.closeBtns.length;i++){
			$(settings.closeBtns[i]).click(function(){this_s.close();	});
		}
	}
	this.settings = settings;
	this.obj = msg_wrap;
	this.setShow();
}

docPopup.prototype.setContents = function(html){	$(this.bodyPannel).html(html); this.setCloseBtns();}
docPopup.prototype.setContSize =  function(){$(".contents",this.bodyPannel).width($(this.bodyPannel).width()-20)}
docPopup.prototype.addContents = function(html){	$(this.bodyPannel).append(html); this.setCloseBtns();}
docPopup.prototype.setTitle = function(str){	this.title = str; $(".pop_title",$(this.obj)).html(str);}
docPopup.prototype.setShow = function(){	$(this.obj).show();}
//docPopup.prototype.setHide = function(){	$(this.obj).hide();}
docPopup.prototype.close = function(){	
	this.hideWindow();
	//if(this.settings
}
docPopup.prototype.setCloseBtns = function(){
	var this_s = this;
	if(this.settings.closeBtns){
		for(var i=0; i<this.settings.closeBtns.length;i++){
			$(this.settings.closeBtns[i]).click(function(){this_s.close();	return false;	});
		}
	}
	$(".closeBtn",this_s.bodyPannel).click(function(){this_s.close();	return false;});
	//this.setContSize();
}
