/**************************************************
 * dom-resize based on dom-drag.js from www.youngpup.net
 * 18 Feb 2005
 **************************************************/

var Resize = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Resize.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;
		var borderfix=parseInt(o.root.style.borderWidth)*2;
		if (o.hmode  && isNaN(parseInt(o.root.style.width ))) o.root.style.width  = parseInt(o.root.offsetWidth)-borderfix+"px";
		if (o.vmode  && isNaN(parseInt(o.root.style.height))) o.root.style.height = parseInt(o.root.offsetHeight)-borderfix+"px";
		if (!o.hmode && isNaN(parseInt(o.root.style.width ))) o.root.style.width  = parseInt(o.root.offsetWidth)-borderfix+"px";
		if (!o.vmode && isNaN(parseInt(o.root.style.height))) o.root.style.height = parseInt(o.root.offsetHeight)-borderfix+"px";
                
		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onResizeStart	= new Function();
		o.root.onResizeEnd	= new Function();
		o.root.onResize		= new Function();
	},

	start : function(e)
	{
		var o = Resize.obj = this;
		e = Resize.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.height);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.width );
		o.root.onResizeStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Resize.drag;
		document.onmouseup		= Resize.end;

		return false;
	},

	drag : function(e)
	{
		e = Resize.fixE(e);
		var o = Resize.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;

		var y = parseInt(o.vmode ? o.root.style.height : o.root.style.height);
		var x = parseInt(o.hmode ? o.root.style.width : o.root.style.width );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		if (nx<0) nx=0;
		if (ny<0) ny=0;

		Resize.obj.root.style[o.hmode ? "width" : "width"] = nx + "px";
		Resize.obj.root.style[o.vmode ? "height" : "height"] = ny + "px";
		Resize.obj.lastMouseX	= ex;
		Resize.obj.lastMouseY	= ey;

		Resize.obj.root.onResize(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Resize.obj.root.onResizeEnd(
			parseInt(Resize.obj.root.style[Resize.obj.hmode ? "left" : "width"]), 
			parseInt(Resize.obj.root.style[Resize.obj.vmode ? "top" : "height"])
		);
		

		Resize.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(
			parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
			parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])
		);
		

		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};


/*************************
  PicmoZ.js  v1
  Feb 20 2005
  Requires dom-drag.js from youngpup.net
  	and dom-resize.js
  Find more scripts at www.sheep-team.org
***************************/

var bw=lib_bwcheck();
var myRoot;
var zind=0;
var sourisx = 0;
var sourisy = 0;

document.onclick = popmousemove;

function popmousemove(e){
	sourisx=bw.ns4||bw.ns6?e.pageX:event.x; 	
	sourisy=bw.ns4||bw.ns6?e.pageY:event.y;
}

function pic(zim,image,picHeight,picWidth){
   var lex=document.body.scrollLeft;
   var ley=document.body.scrollTop;	 
  
	myRoot=zim;
	var zimZe=zim+"Ze";
	var zimkill=zim+"kill";
	var zimResize=zim+"resize";
	sourisy2=sourisy+ley;
	sourisx2=sourisx+lex;
	fixtop = sourisy2+"px";
	fixleft= sourisx2+"px";
	if (ob(zim)) {
		fixtop=ob(zim).style.top+ley;
		fixleft=ob(zim).style.left+lex;
		killterm(zim);
	}
					//event.clientX+document.body.scrollLeft
	//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.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="14px solid #B3B3B3";
	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;
}
