/* **************************************************************
	Wiz Javascript - AJAX Utility Library Modal Window
	Version : 1.0
	Developer : wiz (wizys@yahoo.co.kr / http://wiz.pe.kr/)
	Last Updated : 2008.06.11
************************************************************** */
var ibOpen = false;
var ibBD = null;	// body object
var ibBG = null;
var ibIM = null;

function ib_open_img(imgpath)
{
	if(ibOpen==true) { WizModalClose(); }
	if(!ibBD) { ibBD = document.getElementsByTagName('body')[0]; }
	if(!ibBD) { return; }

	// Background Box Set
	if(!ibBG)
	{
		ibBG = document.createElement('div');
		ibBG.setAttribute('id', 'ibBG');
		ibBG.style.position = 'absolute';
		ibBG.style.right = ibBG.style.top = '0px';
		ibBG.style.zIndex = '9998';
		ibBG.style.margin = ibBG.style.padding='0px';
		ibBG.style.backgroundImage=('url('+ibIOV+')');
		ibBG.style.textAlign='center';
		ibBG.style.Align='center';
		if(navigator.appVersion.toLowerCase().indexOf('msie 6.0')!=-1)	{ ibBG.style.filter = 'alpha(opacity=75)'; }
		ibBD.appendChild(ibBG);
		$addHandler(ibBG,'click', ib_Close);
		$addHandler(document.body,'resize', ib_BGResize);
		$addHandler(window,'resize', ib_BGResize);
	}

	// Image Box Set
	if(!ibIM)
	{
		ibIM = document.createElement('img');
		ibIM.setAttribute('id', 'ibIM');
		ibIM.style.position = 'absolute';
		ibIM.style.zIndex = '9999';
		ibIM.style.border= 'solid 5px #666666';
		ibIM.src=ibIBL;
		ibBD.appendChild(ibIM);
		$addHandler(ibIM,'mouseup', ib_Close);
		$addHandler(ibIM,'load', ib_BGShowResize);
		$addHandler(ibIM,'change', ib_BGShowResize);
	}

	ibOpen=true;ibIM.src = imgpath;
	ibBG.style.display='block';
	ib_BGShowResize();
}

/* Close Modal Window */
function ib_Close()
{
  if(ibIM) { ibIM.src=ibIBL; }
	if(ibBG) { ibBG.style.display='none'; }
	if(ibIM) { ibIM.style.display='none'; }
	ibOpen=false;
}

function ib_BGShowResize() {	if(ibOpen) { ibIM.style.display='block';}ib_BGResize(); }
function ib_BGResize()
{
	if(!ibBD) { return; }
	if(!ibBG)	{ ib_Close();return; }

	var bw = GetWinSizeW();  var bh = GetWinSizeH();
	ibIM.style.height='auto';ibIM.style.width='auto';
	if(ibIM.width>bw) { ibIM.style.width=((bw-50)+'px');ibIM.style.Height='auto'; }
  //if(ibIM.height>bh) { ibIM.style.width='auto';ibIM.style.height=((bh-40)+'px'); }
	var pw = ((bw/2)-(ibIM.width/2));	var ph = ((bh/2)-(ibIM.height/2));
	if(pw<15) { pw=15; }	if(ph<15) { ph=15; }

	ibIM.style.top = ((GetPagePosY()+ph)+'px');	ibIM.style.right = ((GetPagePosX()+pw)+'px');
	ibBG.style.width = (bw+'px');	ibBG.style.height = (GetPageSizeH()+'px');
}

/* Common Functions * * * * * * * * * */
function $addHandler(tgobj, ev, fn)
{
	if (tgobj.addEventListener) { tgobj.addEventListener(ev, fn, false); }
	else if (tgobj.attachEvent) { tgobj.attachEvent('on'+ev, fn); }
	else { tgobj['on'+ev] = fn; }
}

/* Get Window Size */
function GetWinSizeW() { return (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth; }
function GetWinSizeH() { return (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight; }

/* Get Page Size */
function GetPageSizeW()
{
	var rtn = (window.innerWidth && window.scrollMaxX) ? window.innerWidth + window.scrollMaxX : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidt;
	var wsz = GetWinSizeW();
	return (rtn<wsz)?wsz:rtn;
}
function GetPageSizeH()
{
	var rtn = (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
	var wsz = GetWinSizeH();
	return (rtn<wsz)?wsz:rtn;
}

/* Get Page Position*/
function GetPagePosX() { return (window.pageXOffset) ? window.pageXOffset : (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : (document.body) ? document.body.scrollLeft : 0; }
function GetPagePosY() { return (window.pageYOffset) ? window.pageYOffset : (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : (document.body) ? document.body.scrollTop : 0; }
