/*************************
  PicmoZ.js  v1
  Feb 20 2005
  Requires dom-drag.js from youngpup.net
  	and dom-resize.js
  Find more scripts at www.iprezo.org
***************************/

var bw=lib_bwcheck();
var myRoot;
var zind=0;

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;

}

function findPosY(obj)
{
	var curtop = 0;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function pic(obj,zim,image,picHeight,picWidth){

	myRoot=zim;
	var zimZe=zim+"Ze";
	var zimkill=zim+"kill";
	var zimResize=zim+"resize";
      var newX = findPosX(obj);
	var newY = findPosY(obj);
	fixtop =newY+"px";
	fixleft= newX+"px";
	if (ob(zim)) {
		fixtop=ob(zim).style.top;
		fixleft=ob(zim).style.left;
		killterm(zim);
	}

	//The Host div (wrapper)
	var DivMaster = document.createElement("div");
	DivMaster.setAttribute("id",zim);
	DivMaster.style.position = "absolute";
	DivMaster.style.top = fixtop ;
	DivMaster.style.left= fixleft ;
	DivMaster.style.zIndex = zind;
	DivMaster.style.borderWidth="0px";
	DivMaster.style.margin="0px";
	DivMaster.style.padding="0px";
	DivMaster.style.fontFamily="verdana, sans-serif";
	DivMaster.style.fontSize="8px"; //it's to bring the resize button nicely to the left
	DivMaster.style.backgroundColor="transparent";
	DivMaster.onmousedown = function(){this.id.replace(zimZe,zim);IncrInd(this)};
	DivMaster.onmouseup=function(){swapVisi(zimResize);swapVisi(zimkill)};
	
	//The picture
	var Zeimg = document.createElement("img");
	Zeimg.setAttribute("id",zimZe);
	Zeimg.setAttribute("src", image);
	Zeimg.style.position="relative";
	if (picHeight) Zeimg.style.height = picHeight+"px";
	if (picWidth)  Zeimg.style.width  = picWidth +"px";
	Zeimg.style.border="1px dashed #000000";
	Zeimg.style.visibility = "visible";
	Zeimg.onload=function(){Resize.init(ob(zimResize),ob(zimZe));};
	DivMaster.appendChild(Zeimg);

	//The close button
	var ZeimgKill = document.createElement("img");
	ZeimgKill.setAttribute("id",zimkill);
	ZeimgKill.setAttribute("src", "box_close.gif");
	ZeimgKill.style.position="absolute";
	ZeimgKill.style.top="0px";
	ZeimgKill.style.left="0px";
	ZeimgKill.style.border="1px dashed #000000";
	ZeimgKill.style.visibility = "hidden";
	ZeimgKill.style.backgroundColor="transparent";
	ZeimgKill.onclick=function(){bill=this.id.replace(zimkill,zim);killterm(bill);};
	DivMaster.appendChild(ZeimgKill);

	//The Resize button
	var ZeimgResize = document.createElement("img");
	ZeimgResize.setAttribute("id",zimResize);
	ZeimgResize.setAttribute("src", "box_size.gif");
	ZeimgResize.style.position = "relative";
	ZeimgResize.style.top = "0px";
	ZeimgResize.style.left= "-15px";
	ZeimgResize.style.border="1px dashed #000000";
	ZeimgResize.style.visibility = "hidden";
	ZeimgResize.style.backgroundColor="transparent";
	DivMaster.appendChild(ZeimgResize);

	bodyRef.appendChild(DivMaster);

	Drag.init(document.getElementById(zimZe),document.getElementById(zim));
}

function swapVisi(id){
	if (ob(id).style.visibility  == "visible")       ob(id).style.visibility="hidden";
   	else if ( ob(id).style.visibility == "hidden")   ob(id).style.visibility="visible";
}

function killterm(myid){
	var boldElm = ob(myid);
	bodyRef.removeChild(boldElm);
}

function IncrInd(e){
	if(e.id==myRoot) return;
	myRoot=e.id;
	zind++;
	ob(e.id).style.zIndex=zind;
}

function ob(id) {
	if (bw.dom) obj =document.getElementById(id);
	else if (bw.ie4) obj = document.all[id];
	else if (bw.ns4) obj = document.anchors[id];
	return obj;
}

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this;
}

