// DynObj 2.05, (c) Back2Front 2001
// Contact: paul.vandam@back2front.nl


Array.prototype.push=function(v){this[this.length]=v;}
Array.prototype.last=function(){return this[this.length-1];}


function Browser(){
	var d=document;
	var n=navigator;
	var nua=n.userAgent;

	this.DOM=(d.getElementById&&d.createElement)?true:false;
	this.NS=(n.appName=="Netscape");
	this.NS4=(this.NS&&!this.DOM);
	this.NS6UP=(this.NS&&this.DOM);
	this.NS60=(this.NS6UP&&nua.indexOf("Netscape6/6.0")>-1);
	this.NS61=(this.NS6UP&&nua.indexOf("Netscape6/6.1")>-1);
	this.IE=(d.all)?true:false;
	this.IE4=(this.IE&&!this.DOM);
	this.IE5UP=(this.IE&&this.DOM);
	this.IE50=(this.IE5UP&&nua.indexOf("MSIE 5.0")>-1);
	this.IE55=(this.IE5UP&&nua.indexOf("MSIE 5.5")>-1);
	this.IE60=(this.IE5UP&&nua.indexOf("MSIE 6.0")>-1);
	this.MAC=(n.platform.toLowerCase().indexOf("mac")>-1);
}
var b=new Browser();


function DocProp(){
	this.mX=0; this.mY=0;
	this.pX=0; this.pY=0;
	this.mmFunc="";
}	

DPproto=DocProp.prototype;

DPproto.setMouseMove=function(f){this.mmFunc=f;}
DPproto.setMouseUp=function(f){eval("document.onmouseup="+f);}
DPproto.setMouseDown=function(f){eval("document.onmousedown="+f);}
DPproto.innerWidth=function(){return(b.NS)?window.innerWidth:document.body.clientWidth;}
DPproto.innerHeight=function(){return(b.NS)?window.innerHeight:document.body.clientHeight;}

var doc=new DocProp();


if(b.NS4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=doMouseMove;

function doMouseMove(e){
	doc.pX=doc.mX; doc.pY=doc.mY;
	doc.mX=(b.IE)?event.x-2:e.pageX;
	doc.mY=(b.IE)?event.y-2:e.pageY;
	if(doc.mmFunc!=""){eval("var tmp="+doc.mmFunc+"()"); return tmp;}
}


function findObj(id,d){
	for(var i=0;i<d.layers.length;i++){
		var obj=d.layers[i];
		if(obj.name==id) return obj;
		if(obj.document.layers.length>0){	
			obj=findObj(id,obj.document);
			if(obj!=null) return obj;
		}
	}return null;
}

function getObj(id){
	if(b.DOM){return document.getElementById(id);}
	else if(b.IE){return document.all[id];}
	else if(b.NS){return findObj(id,document);}
}

function createObj(name,parent){
	var style="position:absolute;left:0px;top:0px;visibility:inherit;overflow:hidden;";
	if(b.IE){
		var html="<div id='"+name+"' style='"+style+"'></div>";
		if(!parent)parent=document.body;
		parent.insertAdjacentHTML("beforeEnd",html);
		return getObj(name);
	}else if(b.DOM){
		var newEle=document.createElement("div");
		newEle.id=name;
		newEle.setAttribute("style",style);
		if(!parent)parent=document.body;
		parent.appendChild(newEle);
		return newEle;
	}else if(b.NS){
		var tmp=(!parent)?new Layer(300):new Layer(300,parent);
		tmp.visibility="inherit";
		return tmp;
	}
}


document.dynobj=new Array();

function DynObj(name,parent){		
	if(getObj(name)!=null||(document.dynobj[name]!=null && b.NS==false)){ // JLS 240903 extra NS check toegevoegd. Oude code: (getObj(name)!=null||document.dynobj[name]!=null)
		alert("DynObj Error:\n\nAn object with the name '"+name+"' already exists!");
	}else{
		this.name=name;
		this.parent=null;
		this.children=new Array();
		if(parent){
			this.parent=parent;
			this.parent.children.push(this);
			this.parent.children[name]=this;
		}

		document.dynobj.push(this);
		document.dynobj[name]=this;

		this.obj=(parent)?createObj(name,parent.obj):createObj(name); 
		this.id=this.obj.id;

		if(b.NS4)this.obj.style=this.obj;
		this.style=this.obj.style;
	}

	this.visible=false;
	if(!parent)this.setVisible(false);
	this.html="";
	this.nsw=-1;
	this.nsh=-1;
	this.keepInParent=false;
}	

DOproto=DynObj.prototype;

DOproto.setVisible=function(mode){
  if(!b.NS4) // JLS 240903 !b.NS4 was voorheen b.IE
	  this.style.visibility=(mode)?"visible":"hidden";
	else
	  this.visible=mode;
}

DOproto.setHTML=function(html){
	if(this.children.length==0){
		this.html=html;
		if(b.NS4) with(this.obj.document){write(html);close();}
		else{
			var n=(b.MAC&&b.IE)?"\n":"";
			this.obj.innerHTML=n+html+n;
		}
	}
}

DOproto.addHTML=function(html){
	if(this.children.length==0){
		this.html+=html;
		if(b.NS4) with(this.obj.document){write(this.html);close();}
		else{
			var n=(b.MAC&&b.IE)?"\n":"";
			this.obj.innerHTML+=n+html+n;
		}
	}
}

DOproto.getWidth=function(){
	if(b.NS4) return (this.nsw<0)?this.obj.document.width:this.nsw;
	else return this.obj.offsetWidth;
}

DOproto.getHeight=function(){
	if(b.NS4) return (this.nsh<0)?this.obj.document.height:this.nsh;
	else return this.obj.offsetHeight;
}

DOproto.setWidth=function(w){
	if(b.NS4){this.obj.clip.width=w; this.nsw=w;}
	else this.style.width=w;
}

DOproto.setHeight=function(h){
	if(b.NS4){this.obj.clip.height=h; this.nsh=h;}
	else this.style.height=h;
}

DOproto.setSize=function(w,h){
	if(b.NS4){this.obj.resizeTo(w,h);this.nsw=w; this.nsh=h;}
	else this.style.width=w; this.style.height=h;
}

DOproto.getClip=function(i){
	if(b.NS4){clipv=new Array('top','right','bottom','left');return eval("this.obj.clip."+clipv[i]);}
	else{clipv=this.style.clip.split("rect(")[1].split(")")[0].split("px");return clipv[i];}
}

DOproto.setClip=function(t,w,h,l){
	if(b.NS4) with(this.obj.clip){top=t;right=w;bottom=h;left=l;}
	else this.style.clip="rect("+t+","+w+","+h+","+l+")";
}

DOproto.setZ=function(z){this.style.zIndex=z;}

DOproto.setDim=function(x,y,w,h){
	this.moveTo(x,y);
	this.setSize(w,h);
	this.setClip(0,w,h,0);
}

DOproto.getLeft=function(){return parseInt(this.style.left);}
DOproto.getTop=function(){return parseInt(this.style.top);}
DOproto.getRight=function(){return this.getLeft()+this.getWidth();}
DOproto.getBottom=function(){return this.getTop()+this.getHeight();}

DOproto.getAbsPos=function(){
	var x=this.getLeft();
	var y=this.getTop();
	if(this.parent){
		var tmp=this.parent.getAbsPos();
		x+=tmp[0];
		y+=tmp[1];
	}
	return [x,y];
}

DOproto.getAbsLeft=function(){return this.getAbsPos()[0];}
DOproto.getAbsTop=function(){return this.getAbsPos()[1];}

DOproto.moveTo=function(x,y){
	if(this.keepInParent&&this.parent&&this.getWidth()<=this.parent.getWidth()&&this.getHeight()<=this.parent.getHeight()){
		if(x<0) x=0; if(x+this.getWidth()>this.parent.getWidth()) x=this.parent.getWidth()-this.getWidth();
		if(y<0) y=0; if(y+this.getHeight()>this.parent.getHeight()) y=this.parent.getHeight()-this.getHeight();
	}
	this.style.left=x;
	this.style.top=y;
}

DOproto.moveBy=function(x,y){
	if(this.keepInParent&&this.parent&&this.getWidth()<=this.parent.getWidth()&&this.getHeight()<=this.parent.getHeight()){
		if(this.getLeft()+x<0) x=0; if(this.getRight()+x>this.parent.getWidth()) x=0;
		if(this.getTop()+y<0) y=0; if(this.getBottom()+y>this.parent.getHeight()) y=0;
	}
	if(x!=0)this.style.left=this.getLeft()+x;
	if(y!=0)this.style.top=this.getTop()+y;
}

DOproto.setBackGround=function(str){
	if(str.indexOf(".")>-1){
		if(b.NS4)this.obj.background.src=str;
		else this.style.backgroundImage="url("+str+")";
	}else{
		if(b.NS4)this.obj.bgColor=str;
		else this.style.backgroundColor=str;
	}
}

DOproto.setBgColor=function(col){this.setBackGround(col);}
DOproto.setBgImage=function(img){this.setBackGround(img);}

DOproto.setMouseOver=function(f){eval("this.obj.onmouseover="+f);}
DOproto.setMouseOut=function(f){eval("this.obj.onmouseout="+f);}
DOproto.setMouseDown=function(f){eval("this.obj."+((b.NS4)?"document.":"")+"onmousedown="+f);}
DOproto.setMouseUp=function(f){eval("this.obj."+((b.NS4)?"document.":"")+"onmouseup="+f);}

DynObj.getDynObj=function(obj){
	for(var i=0;i<document.dynobj.length;i++){
		var tmpObj=document.dynobj[i].obj;
		if(b.NS4&&!obj.document) tmpObj=tmpObj.document;		
		if(tmpObj==obj)return document.dynobj[i];
	}
}

DynObj.destroyAll=function(){
	for(var i=0;i<document.dynobj.length;i++){
		document.dynobj[i]=null;
	}
}
if(b.MAC&&b.IE)onunload=DynObj.destroyAll;