function redraw(id) {
	var obj = document.getElementById(id);
	setPos(id);
	fadeIn(obj.bgId, 50, 50);
	fadeIn(id, 100, 100);
}
function setPos(id) {
	var pObj = document.getElementById(id);

	var width = 0;
	var height = 0;
	var scroll = 0;
	if(document.documentElement.clientWidth) {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	} else if(document.body.clientWidth){
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	} else {
		width = window.innerWidth;
		height = window.innerHeight;
	}
	scroll = (document.body.scrollTop || document.documentElement.scrollTop);

	var maxHeight = height;
	if (typeof document.documentElement.style.msInterpolationMode != "undefined") {
		//IE7
		if(document.documentElement.clientHeight && document.documentElement.clientHeight > maxHeight) {
			maxHeight = document.documentElement.clientHeight;
		}
		if(document.body.clientHeight && document.body.clientHeight > maxHeight) {
			maxHeight = document.body.clientHeight;
		}
		if(window.innerWidth && window.innerWidth > maxHeight) {
			maxHeight = window.innerWidth;
		}
		maxHeight -= scroll;
	}

	var bgObj = document.getElementById(pObj.bgId);
	bgObj.style.width=width+'px';
	bgObj.style.height=maxHeight+'px';
	bgObj.style.left = '0px';
	bgObj.style.top = scroll+'px';

	if(pObj.offsetWidth > width) {
		pObj.style.left = '0px';
	} else {
		pObj.style.left = ((width-pObj.offsetWidth)/2)+'px';
	}
	if(pObj.offsetHeight > height) {
		pObj.style.top = '0px';
	} else {
		pObj.style.top = scroll+((height-pObj.offsetHeight)/2)+'px';
	}
}
function onPopup(popupId, imgId) {
	window.onscroll=function() {
		redraw(popupId);
	};
	window.onresize=function() {
		redraw(popupId);
	};

	var pObj = document.getElementById(popupId);
	pObj.style.zIndex = 100;
	pObj.style.position="absolute";
	pObj.style.filter = "alpha(opacity=0)";
	pObj.style.opacity = 0;

	var srcObj = document.getElementById(pObj.srcId);
	srcObj.src = pObj.imgList[imgId].src;
	srcObj.style.width=pObj.imgList[imgId].width+'px';
	srcObj.style.height=pObj.imgList[imgId].height+'px';
	
	//
	var txtObj = document.getElementById(pObj.textId);
	var child = txtObj.firstChild;
	if(child) {
		while(child.nextSibling) {
			txtObj.removeChild(child.nextSibling);
		}
		txtObj.removeChild(child);
	}
	var tmpObj = document.createElement("div");
	tmpObj.innerHTML = pObj.imgList[imgId].text;
	txtObj.appendChild(tmpObj);
	
	var bgObj = document.getElementById(pObj.bgId);
	bgObj.style.zIndex = 50;
	bgObj.style.position="absolute";
	bgObj.style.filter = "alpha(opacity=0)";
	bgObj.style.opacity = 0;
	
	setPos(popupId);

	fadeIn(pObj.bgId, 50, 0);
	fadeIn(popupId, 100, 0);
}
function closePopup(id) {
	window.onscroll=null;
	window.onresize=null;
	var obj = document.getElementById(id);
	fadeOut(id, 0, 100);
	fadeOut(obj.bgId, 0, 50);
	obj.style.zIndex = -100;
	document.getElementById(obj.bgId).style.zIndex = -100;
}
function fadeIn(id, max, now) {
	var obj = document.getElementById(id);
	obj.style.visibility="visible";
	if(max > now) {
		var next = now + (max / 5);
		obj.style.filter = "alpha(opacity=" + next + ")";
		obj.style.opacity = next/100;
		setTimeout("fadeIn('"+id+"',"+max+","+next+")", 100);
	} else {
		obj.style.filter = "alpha(opacity=" + max + ")";
		obj.style.opacity = max/100;
	}
}
function fadeOut(id, min, now) {
	var obj = document.getElementById(id);
	if(min < now) {
		var next = now - ((100-min) / 5);
		obj.style.filter = "alpha(opacity=" + next + ")";
		obj.style.opacity = next/100;
		setTimeout("fadeOut('"+id+"',"+min+","+next+")", 100);
	} else {
		if(min == 0) {
			obj.style.visibility="hidden";
		} else {
			obj.style.filter = "alpha(opacity=" + min + ")";
			obj.style.opacity = min/100;
		}
	}
}
function initImg(idList, imgList) {
	var pObj = document.getElementById(idList[0]);
	pObj.imgList = new Array();
	for(var imgId in imgList) {
		pObj.imgList[imgId] = new Image();
		pObj.imgList[imgId].src = imgList[imgId][0];
		pObj.imgList[imgId].text = imgList[imgId][1];
	}
	pObj.bgId = idList[1];
	pObj.srcId = idList[2];
	pObj.textId = idList[3];
}
