// 제작일 : 2007년 3월 18일
// 제작자 : 최영규 (http://hooriza.com/)

if (typeof HBASE != "object" || HBASE.version < 2.0) {
	alert("前台登入/登出插件需要Hooriza Plugin Base 2.0以上");
}

HBASE.LGN = {
	
	wnd : null,
	wnd_visible : false,
	
	logedin : false,
	
	initialize : function(uniq, logedin) {
		
		HBASE.LGN.wnd = jQuery("#" + uniq);
		HBASE.LGN.logedin = logedin;
		
		HBASE.LGN.wnd.css({
			position : "absolute",
			visibility : "hidden",
			display : "none",
			zIndex : 10000
		});
	},
	
	showWindow : function(flag) {
		
		if (flag) {
			
			var form = HBASE.LGN.wnd.get(0);
			form.action = flag.href;
			
			HBASE.showBlind(true);
			
			jQuery(document.body).append(HBASE.LGN.wnd); // for FF
	
			HBASE.LGN.wnd.css({
				visibility : "hidden",
				left : "-9999px",
				top : "-9999px",
				display : "block"
			});
			
			HBASE.moveToCenter(HBASE.LGN.wnd);
			HBASE.LGN.wnd.css({ visibility : "visible" });
			
			if (form.loginid.value.length > 0) {
				form.password.focus();
			} else {
				form.loginid.focus();
			}
			
		} else {
			
			HBASE.LGN.wnd.hide();
			HBASE.showBlind(false);
		}
		
		HBASE.LGN.wnd_visible = flag;
	},
	
	onScroll : function() {
		if (!HBASE.LGN.wnd_visible) return;
		HBASE.moveToCenter(HBASE.LGN.wnd);
	},
	
	onLoad : function() {
		
		// 이미 로그인 되어 있으면 SKIP
		if (HBASE.LGN.logedin) return;
		
		var links = jQuery("a");
		
		links.each(function() {
			
			var href = this.href;

			var pos = href.indexOf("http://");
			if (pos == 0) {
				href = href.substr(pos + 7 /*"http://".length*/);
				
				pos = href.indexOf("/");
				href = href.substr(pos);
			}
			
			// 관리자 화면에 접속하는 거면
			if (href.indexOf("/owner") != -1) {
				
				this.href = HBASE.blogURL + "/login?requestURI=" + encodeURIComponent(href);

				jQuery(this).bind("click", function(e) {
					HBASE.LGN.showWindow(this);
					e.preventDefault();
					e.stopPropagation();
				});

			}
			
		});
		
	}

};

jQuery(window).bind("scroll", HBASE.LGN.onScroll);
jQuery(window).bind("resize", HBASE.LGN.onScroll);

jQuery(HBASE.LGN.onLoad);
