// 제작일 : 2007년 2월 17일
// 제작자 : 최영규 (http://hooriza.com/)

if (typeof HBASE != "object" || HBASE.version < 2.0) {
	alert("후리자  포스트 이미지 보기 플러그인을 사용하기 위해서는 Hooriza Plugin Base 2.0 이상이 필요합니다");
}

HBASE.IMG = {
	
	img : null,
	img_visible : false,
	
	initialize : function() {
		
		if (HBASE.IMG.img) return;
		HBASE.IMG.img = jQuery("<img>");
		
		try {
			jQuery(document.body).append(HBASE.IMG.img);
		} catch(e) {
			HBASE.IMG.img = null;
			return;
		}
		
		HBASE.IMG.img.css({
			position : "absolute",
			visibility : "hidden",
			display : "none",
			zIndex : 10000,
			border : "1px solid black",
			cursor : "pointer"
		});
		
		HBASE.IMG.img.bind("load", HBASE.IMG.showImage);
		HBASE.IMG.img.bind("click", HBASE.IMG.hideImage);
	},
	
	openImage : function(src) {
		
		HBASE.showBlind(true);
		
		HBASE.IMG.initialize();
		
		HBASE.IMG.img.css({
			visibility : "hidden",
			left : "-9999px",
			top : "-9999px",
			display : "block"
		});
		
		HBASE.IMG.img.get(0).src = src;
	},
	
	showImage : function() {
		HBASE.moveToCenter(HBASE.IMG.img);
		HBASE.IMG.img.css({ visibility : "visible" });
		HBASE.IMG.img_visible = true;
	},
	
	hideImage : function() {

		HBASE.IMG.img.hide();
		HBASE.IMG.img.get(0).removeAttribute("src");

		HBASE.IMG.img_visible = false;
		
		HBASE.showBlind(false);
	},
	
	move_delay : null,
	
	onScroll : function() {
		if (!HBASE.IMG.img_visible) return;
		
		if (HBASE.IMG.move_delay) {
			window.clearTimeout(HBASE.IMG.move_delay);
			HBASE.IMG.move_delay = null;
		}
		
		HBASE.IMG.move_delay = window.setTimeout(function() {
			HBASE.moveToCenter(HBASE.IMG.img, 200);
			HBASE.IMG.move_delay = null;
		}, 100);
	}

};

$(window).bind("scroll", HBASE.IMG.onScroll);
$(window).bind("resize", HBASE.IMG.onScroll);

function open_img(src) { HBASE.IMG.openImage(src); }
