// from the 1k DOM API - http://timmorgan.info/1k/
d=document; var agt=navigator.userAgent.toLowerCase();
function gE(e){return d.getElementById(e)}; 
function cE(t){return d.createElement(t||'div')};
function aC(e,p){return (p||d.body).appendChild(e)};
function sE(e){e.style.visibility='visible'};
function hE(e){e.style.visibility='hidden'};
//end of 1k functions

function gEs(t,p){return (p||d).getElementsByTagName(t)};

function divHeight(o){ 	return o.offsetHeight|| o.style.pixelHeight || o.height|| 0; }
function divWidth(o){ 	return o.offsetWidth|| o.style.pixelWidth || o.width|| 0 ;}
function centerDiv(id) {
	var obj = gE(id);
	if (!obj ) return ;
	var os = obj.style ? obj.style : obj ;
	os.top = "0px"; os.left = "0px";
	var wi = divWidth(obj);
	var he = divHeight(obj);
	if(d.body) { yc=Math.round((d.body.clientHeight/2)-(he/2));xc=Math.round((d.body.clientWidth/2)-(wi/2)); }
	else if(w.innerHeight) {yc=Math.round((w.innerHeight/2)-(he/2));xc=Math.round((w.innerWidth/2)-(wi/2));}
	xc = xc < 0 ? 0 : xc ;
	yc = yc < 0 ? 0 : yc ;
	if(d.getElementById){ os.top = yc + "px"; os.left = xc + "px";} 
}

d.write("<link rel=\"stylesheet\" href=\"picviewer.css\" type=\"text/css\">");

enlargeMessage=" (click to enlarge)";
closeMessage="click to close";

	function imageInsert(i,pv){
		img = gE("image");
		img.src = i.src;
		sE(pv.parentNode);
		centerDiv("container"); 
		onresize = function () { centerDiv("container");  } 
	}

	function setImgViewing(){
		if(!d.getElementById)return;
		pv = cE();		
		pv.alt = "click to close";
		pv.title = "click to close";
		pv.id = "picViewer";
		pv.onclick = function(){hE(pv.parentNode); onresize = null; };
		pv.onmouseout = pv.onclick ;
		d.onmousedown = pv.onclick ;
		div = cE();
		div.id = "container";	
		hE(div);
		aC(pv,div);
		aC(div);
		
		var imgs =  gEs("img");
		for(i=0 ; i < imgs.length; i++){
			if (imgs[i].no || imgs[i].getAttribute("ma") == "no" ) continue;
			imgs[i].alt += enlargeMessage;
			imgs[i].title = imgs[i].alt ;
			imgs[i].onclick = function(){imageInsert(this,pv)};
			imgs[i].id = "magn";
		}

		img = cE("img");
		img.alt = closeMessage;
		img.title = img.alt ;
		img.id = "image";
		aC(img,pv);
	}
