// SimpleBox v0.2
// Core code from - Lightbox http://www.huddletogether.com/projects/lightbox/
// Modified by atan - http://www.atan.cn 
// Last modified: 2007-7-18
function $(id){return document.getElementById(id);}
function $n(nid){return document.getElementsByTagName(nid);}
function getPageSize(){
	var $bo=document.body;
	var $de=document.documentElement;
	maxWidth=Math.max($bo.scrollWidth,$bo.offsetWidth,$de.clientWidth,$bo.clientWidth);
	maxHeight=Math.max($bo.scrollHeight,$bo.offsetHeight,$de.clientHeight,$bo.clientHeight);
	var arrayPageSize = new Array(maxWidth,maxHeight,$de.scrollTop,$de.clientHeight);
	return arrayPageSize;
}
function showsimplebox(objLink){
	selects = $n("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility="hidden";
	}
	var ps = getPageSize();
	$("overlay").style.width= (ps[0] + 'px');
	$("overlay").style.height=(ps[1] + 'px');
	$("overlay").style.display="block";
	imgPreload = new Image();
	imgPreload.onload=function(){
		$("simplebox").src=objLink.href;
		return false;
	}
	imgPreload.src=objLink.href;
	$("simplebox").style.top=ps[2]+((ps[3]-imgPreload.height)*0.382)+"px";
	$("simplebox").style.left=(ps[0]-imgPreload.width)*0.5+"px";
	$("simplebox").style.display="block";
}
function hidesimplebox(){
	$("simplebox").style.display="none";
	$("simplebox").removeAttribute("src");
	$("overlay").style.display="none";
	selects = $n("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility="visible";
	}
}
function initsimplebox(){
	var anchors = $n("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "simplebox")){
			anchor.onclick = function () {showsimplebox(this); return false;}
		}
	}
	var objBody = $n("body").item(0);
	var oOvl = document.createElement("div");
	oOvl.setAttribute('id','overlay');
	oOvl.setAttribute('style','position:absolute;top:0;left:0;z-index:500;background:#000;-moz-opacity: 0.75;opacity: 0.75;display:none');
	oOvl.style.position="absolute";
	oOvl.style.background="#000";
	oOvl.style.top=0;
	oOvl.style.left=0;
	oOvl.style.zIndex="500";
	oOvl.style.filter="Alpha(Opacity=75)";
	oOvl.style.display="none";
	oOvl.onclick = function () {hidesimplebox(); return false;}
	objBody.insertBefore(oOvl, objBody.firstChild);
	var oSbx = document.createElement("img");
	oSbx.setAttribute('id','simplebox');
	oSbx.setAttribute('style','position: absolute;z-index:600;border:6px solid #FFF;display:none;');
	oSbx.style.position="absolute";
	oSbx.style.zIndex="600";
	oSbx.style.border="6px solid #FFF";
	oSbx.style.display="none";
	oSbx.onclick = function () {hidesimplebox(); return false;}
	objBody.insertBefore(oSbx, oOvl.nextSibling);
}
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}
addLoadEvent(initsimplebox);