Article = function(){}
Article.prototype = {
	submit : function(fom){
		fom.submit();
	},
	remove : function(a){
		if(confirm("삭제하시겠습니까?\n한 번 삭제하신 글은 복구하실 수 없습니다.")){
			return true;
		}else{
			return false;
		}
		return false;
	},
	excel : function(){
		$("exe").setAttribute("src", "/09/admin/mailing/excel.php");
	}
}

Login = function(){
	this.showbutton = $("b-online");
	this.showcheck = false;
	this.before = $("login-before");
	this.after = $("login-after");
	this.login_id = $("login-id");
	this.login_pw = $("login-password");
	this.login_pwv = $("password-value");
	this.remember = $("rememberid");
	this.remember_form = $("rememberid_check");
	this.cook = document.cookie;
	this.b_util_bt = $$("#business-util a");
	this.b_util_bg = $$("#business-util p")[0];
	login = this;
	this.init();
}
Login.prototype = {
	init : function(){
		if(this.before){
			this.showbutton.observe("click", login.show_action);
			this.login_id.observe("focus", login.form_init);
			this.login_pw.observe("focus", login.form_init);
			this.login_id.observe("keydown", login.form_enter);
			this.login_pw.observe("keydown", login.form_enter);
			this.remember.observe("focus", this.blur);
			if(this.getcookie()){
				login.remember_action();
				login.form_init();
				this.login_id.value = this.getcookie();
				this.remember.observe("click", login.remember_action);
			}else{
				this.remember.observe("click", login.remember_action);
			}
		}
		this.handler = this.businessUtil.bind(this);
		this.b_util_bt.each(function(e,index){
			e._index=index;
			e.observe("mouseover",this.handler);
		}.bind(this))
	},

	businessUtil: function(e){
		var index=e.element()._index;
		this.b_util_bg.setStyle({backgroundPosition:"0 "+(-20*index+6)+"px"});
	},

	getcookie : function(){
		var prefix = "djharch_id=";
		var begin = this.cook.indexOf(prefix);
		if(begin == -1) return false;
		begin = this.cook.indexOf("=", begin)+1;
		var end = this.cook.indexOf(";", begin);
		if(end == -1) end = this.cook.length;
		return unescape(this.cook.substring(begin, end));
	},

	show_action : function(){
		if(login.showcheck){
			login.before.setStyle({visibility:"hidden"});
			login.showcheck = false;
		}else{
			login.before.setStyle({visibility:"visible"});
			login.showcheck = true;
		}
	},

	form_init : function(){
		login.login_id.value = "";
		login.login_pwv.setStyle({display:"none"});
		Event.stopObserving(login.login_id, "focus", login.form_init);
		Event.stopObserving(login.login_pw, "focus", login.form_init);
	},

	form_enter: function(e){
		if(e.keyCode == 13){
			article.submit($('login-form'));
		}
	},

	remember_action : function(){
		if(login.remember_form.value == "false"){
			login.remember.setStyle({backgroundPosition:"0 -18px"});
			login.remember_form.value = "true";
		}else{
			login.remember.setStyle({backgroundPosition:"0 3px"});
			login.remember_form.value = "false";
		}
	}
}

Mail = function(){
	this.fom = $("mailaddress-form");
	this.field = $("mailaddress");
	this.pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
}
Mail.prototype = {
	check : function(){
		if (!this.pattern.test(this.field.value) || this.field.value == ""){
			alert("올바른 이메일주소가 아닙니다.");
			return false;
		}
		this.exe(this.field.value);
		return false;
	},

	exe : function(val){
		new Ajax.Request("/09/library/mail.php?mailaddress="+val, {
			method : "get",
			onSuccess : function(transport){
				alert(transport.responseText);
				mail.field.value = "";
			}
		});
	}
}

Director = function(){
	this.act = new Array($("director-ko-action"), $("director-en-action"));
	this.tgt = new Array($("director-ko"), $("director-en"));
	this.now = 0;
	director = this;
	this.init();
}
Director.prototype = {
	init : function(){
		this.act[0].observe("click", director.toggle);
		this.act[1].observe("click", director.toggle);
	},

	toggle : function(){
		if(director.now == 0){
			director.act[0].setStyle({backgroundPosition:"0 -14px"});
			director.act[1].setStyle({backgroundPosition:"-44px -14px"});
			director.tgt[0].setStyle({display:"none"});
			director.tgt[1].setStyle({display:"block"});
			director.now = 1;
		}else{
			director.act[0].setStyle({backgroundPosition:"0 1px"});
			director.act[1].setStyle({backgroundPosition:"-44px 1px"});
			director.tgt[0].setStyle({display:"block"});
			director.tgt[1].setStyle({display:"none"});
			director.now = 0;
		}
	}
}

ImageViewer = function(){
	this.box = $("attach-box");
	this.tgt = $("attach-img");
	this.img = $$("#attach-img img");
	this.btn = new Array($("attach-prev"), $("attach-next"));
	this.siz = new Array();
	this.now = 0;
	this.tot = this.img.length-1;
	this.spc = 650;
	viewer = this;
	this.init();
}
ImageViewer.prototype = {
	init : function(){
		this.img.each(function(a){
			this.siz.push(a.getAttribute("height"));
		}.bind(this));

		this.btn[0].observe("click", viewer.prev);
		this.btn[1].observe("click", viewer.next);
		this.btn[0].setStyle({height:viewer.siz[0]+"px"});
		this.btn[1].setStyle({height:viewer.siz[0]+"px"});
	},

	prev : function(){
		viewer.now = (viewer.now == 0) ? viewer.tot : viewer.now-1;
		viewer.tgt.setStyle({marginLeft:-(viewer.now*viewer.spc)+"px"});
		viewer.btn[0].setStyle({height:viewer.siz[viewer.now]+"px"});
		viewer.btn[1].setStyle({height:viewer.siz[viewer.now]+"px"});
		viewer.box.setStyle({height:viewer.siz[viewer.now]+"px"});
	},

	next : function(){
		viewer.now = (viewer.now == viewer.tot) ? 0 : viewer.now+1;
		viewer.tgt.setStyle({marginLeft:-(viewer.now*viewer.spc)+"px"});
		viewer.btn[0].setStyle({height:viewer.siz[viewer.now]+"px"});
		viewer.btn[1].setStyle({height:viewer.siz[viewer.now]+"px"});
		viewer.box.setStyle({height:viewer.siz[viewer.now]+"px"});
	}
}

var PopupImage = Class.create({
	initialize: function(opener, target, option){
		this.opener = $(opener);
		this.target = target;
		this.option = option;
		this.opener.observe('click', this.viewimg.bind(this));
		this.js_url ="<script language='JavaScript1.2'> \n"; 
		this.js_url += "<!-- \n"; 
		this.js_url += "var ie=document.all; \n"; 
		this.js_url += "var nn6=document.getElementById&&!document.all; \n"; 
		this.js_url += "var isdrag=false; \n"; 
		this.js_url += "var x,y; \n"; 
		this.js_url += "var dobj; \n"; 
		this.js_url += "function movemouse(e) \n"; 
		this.js_url += "{ \n"; 
		this.js_url += "  if (isdrag) \n"; 
		this.js_url += "  { \n"; 
		this.js_url += "    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; \n"; 
		this.js_url += "    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y; \n"; 
		this.js_url += "    return false; \n"; 
		this.js_url += "  } \n"; 
		this.js_url += "} \n"; 
		this.js_url += "function selectmouse(e) \n"; 
		this.js_url += "{ \n"; 
		this.js_url += "  var fobj      = nn6 ? e.target : event.srcElement; \n"; 
		this.js_url += "  var topelement = nn6 ? 'HTML' : 'BODY'; \n"; 
		this.js_url += "  while (fobj.tagName != topelement && fobj.className != 'dragme') \n"; 
		this.js_url += "  { \n"; 
		this.js_url += "    fobj = nn6 ? fobj.parentNode : fobj.parentElement; \n"; 
		this.js_url += "  } \n"; 
		this.js_url += "  if (fobj.className=='dragme') \n"; 
		this.js_url += "  { \n"; 
		this.js_url += "    isdrag = true; \n"; 
		this.js_url += "    dobj = fobj; \n"; 
		this.js_url += "    tx = parseInt(dobj.style.left+0); \n"; 
		this.js_url += "    ty = parseInt(dobj.style.top+0); \n"; 
		this.js_url += "    x = nn6 ? e.clientX : event.clientX; \n"; 
		this.js_url += "    y = nn6 ? e.clientY : event.clientY; \n"; 
		this.js_url += "    document.onmousemove=movemouse; \n"; 
		this.js_url += "    return false; \n"; 
		this.js_url += "  } \n"; 
		this.js_url += "} \n"; 
		this.js_url += "document.onmousedown=selectmouse; \n"; 
		this.js_url += "document.onmouseup=new Function('isdrag=false'); \n"; 
		this.js_url += "//--> \n"; 
		this.js_url += "</"+"script> \n";
	},
	viewimg: function(){
		this.win = window.open("","image_window","width="+this.option.width+",height="+this.option.height+",noresize,scrollbars=no"); 
		this.win.document.open(); 
		this.win.document.write ("<html><head> \n<meta http-equiv='imagetoolbar' CONTENT='no'> \n<meta http-equiv='content-type' content='text/html; charset=utf-8'>\n"); 
		var size = "이미지 사이즈 : "+this.option.width+" x "+this.option.height;
		this.win.document.write ("<title>"+size+"</title> \n"); 
		if(this.option.width >= screen.width || this.option.height >= screen.height) { 
			this.win.document.write (this.js_url); 
			var click = "ondblclick='window.close();' style='cursor:move' title=' "+size+" \n\n 이미지 사이즈가 화면보다 큽니다. \n 왼쪽 버튼을 클릭한 후 마우스를 움직여서 보세요. \n\n 더블 클릭하면 닫혀요. '"; 
		} 
		else 
		var click = "onclick='window.close();' style='cursor:pointer' title=' "+size+" \n\n 클릭하면 닫혀요. '"; 
		this.win.document.write ("<style>.dragme{position:relative;}</style> \n"); 
		this.win.document.write ("</head> \n\n"); 
		this.win.document.write ("<body leftmargin=0 topmargin=0 bgcolor=#dddddd style='cursor:arrow;'> \n"); 
		this.win.document.write ("<table width=100% height=100% cellpadding=0 cellspacing=0><tr><td align=center valign=middle><img src='"+this.target+"' width='"+this.option.width+"' height='"+this.option.height+"' border=0 class='dragme' "+click+"></td></tr></table>");
		this.win.document.write ("</body></html>"); 
		this.win.document.close(); 
	}
});

function focuskill(){
	var linkLen = document.links.length; 
    for (var i = 0; i < linkLen; i++) document.links[i].onfocus = function () { this.blur(); }; 
}


function getCookie(key){
	var nameOfCookie = key + "=";
	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 "";
}

var login = null;
var article = null;
var save = null;
var mail = null;
var director = null;
function loadAction(){
	if($("login-before") || $("login-after")){
		login = new Login();
	}
	if($("director-ko-action")){
		director = new Director();
	}
/*
	if($('djh-home')){
		if(getCookie('Gallery') != 'no'){
		var popup = window.open('/gallery/200909_NEWSTOP/popup.php','home','width=340,height=253,noresize,scrollbars=no,left=0,top=0');
		}
	}
*/
	if($('company-staff')){
		new PopupImage('staff-photo','/09/images/company/staffo.jpg',{width:1000,height:529});
	}
	article = new Article();
	mail = new Mail();

	focuskill();
}
Event.observe(document, "dom:loaded", loadAction);



try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


// 팝업스크립트
// opt = 0 일 경우에는 팝업이 안 뜸, 1일 경우에는 팝업이 뜸
var opt = 0;