/******************************************\
|******  Thing dhtml API ver. 10.29  ******|
|******  Developed by Oskar Aourell  ******|
\******************************************/

var _d_ = document;
var _b_;
var _n_ = (_d_.layers)? 1 : 0;		// NS 4?
var _a_ = (_d_.all)? 1 : 0;		// IE 4?
var _g_ = (_d_.getElementById)? 1 : 0;	// DOM browser? (IE 5+, NS 5+, FireFox..)
var _o_ = (window.opera)? 1 : 0;	// Opera?
var _u_ = navigator.userAgent.toLowerCase();
var _v_ = navigator.appVersion.toLowerCase();
var _nrDynC_ = 0;
var _loaded_ = false;
var _modPI_ = 180/Math.PI;
var Things = [];
var Dec2Hex = [];
var _hb_ = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
var value = 0;
for (x=0; x<16; x++){
	for (y=0; y<16; y++){
		Dec2Hex[value]= _hb_[x] + _hb_[y];
		value++;
	}
}


function dtr(d){return (d/_modPI_);}
function rtd(r){return (r*_modPI_);}
function rgb2str(r,g,b){return ("#" + Dec2Hex[r] + Dec2Hex[g] + Dec2Hex[b]);}
function radiusX(x,r,de){return x + r*Math.cos(dtr(de));}
function radiusY(y,r,de){return y + r*Math.sin(dtr(de));}
function scrollX(){return _b_.scrollLeft? _b_.scrollLeft : window.pageXOffset? window.pageXOffset : null;}
function scrollY(){return _b_.scrollTop? _b_.scrollTop : window.pageYOffset? window.pageYOffset : null;}
function winW(){if (!_b_) initB(); return _b_.clientWidth? _b_.clientWidth : window.innerWidth? window.innerWidth : null;}
function winH(){if (!_b_) initB(); return _b_.clientHeight? _b_.clientHeight : window.innerHeight? window.innerHeight : null;}
function docW(){if (!_b_) initB(); return _b_.scrollWidth? _b_.scrollWidth : _b_.offsetWidth? _b_.offsetWidth : _b_.style.pixelWidth? parseInt(_b_.style.pixelWidth) : _d_.width? _d_.width : null;}
function docH(){if (!_b_) initB(); return _b_.scrollHeight? _b_.scrollHeight : _b_.offsetHeight? _b_.offsetHeight : _b_.style.pixelHeight? parseInt(_b_.style.pixelHeight) : _d_.height? _d_.height : null;}
function initB(){if (!_b_) _b_ = (_d_.compatMode=="CSS1Compat" && _d_.documentElement)? _d_.documentElement : _d_.body;}
function noClue(f,e){
	var h,b,c;
	if (!e) e = _d_;
	if ((h = f.indexOf("?"))>0 && parent.frames.length){
		e = parent.frames[f.substring(h+1)].document;
		f = f.substring(0,h);
	}
	if (!(c = e[f]) && _a_) c = _d_.all[f];
	for (b=0; !c && b<e.forms.length; b++) c = e.forms[b][f];
	for (b=0; !c && _n_ && b<e.layers.length; b++) c = noClue(f,e.layers[b].document);
	if (!c && _g_) c = _d_.getElementById(f);
	return c;
}
function Thing(e){
	this.id = "Thing_"+_nrDynC_;
	this.nr = _nrDynC_;
	Things[this.nr] = this;
	this.dim = {x:null, y:null, w:null, h:null};
	if (!e) this.content = "";
	else{
		this.name = e;
		this.obj = noClue(e);
		this.style = _n_? this.obj : this.obj.style;
		this.ref = this.obj.document;
		this.dim.x = this.x();
		this.dim.y = this.y();
		this.dim.w = this.w();
		this.dim.h = this.h();
	}
	_nrDynC_++;
	if (!this.obj && e) return null;
	else return this;
}
Thing.prototype.appendToDoc = function(x,y,z,w,h,parent){
	if (_loaded_) this.appendDynLayer(x,y,z,w,h,parent);
	else this.appendStatLayer(x,y,z,w,h);
};
Thing.prototype.appendStatLayer = function(x,y,z,w,h){
	var objString;
	if (this.contentHTML!=null){
		this.contentHTML = this.contentHTML.replace("this.id",this.id);
		objString = this.contentHTML;
	} else objString = _n_? "<layer id='"+this.id+"' name='"+this.id+"'>"+this.content+"</layer>" : "<div id='"+this.id+"' style='position:absolute'>"+this.content+"</div>";
	document.write(objString);
	this.obj = _n_? _d_.layers[this.id] : (_g_ && !_o_)? _d_.getElementById(this.id) : _d_.all[this.id];
	this.style = _n_? this.obj : this.obj.style;
	this.ref = this.obj.document;
	if (_n_) window.location.reload;
	this.dim.x = this.x(x);
	this.dim.y = this.y(y);
	this.dim.w = this.w(w);
	this.dim.h = this.h(h);
	this.z(z);
};
Thing.prototype.appendDynLayer = function(x,y,z,w,h,parent){
	// Halt procedure if Opera 6 or earlier equivalent
	if (_o_ && (_u_.indexOf("opera 4.")>-1 || _u_.indexOf("opera 5.")>-1 || _u_.indexOf("opera 6.")>-1)) return;

	var _done = false;
	var objString, host;
	if (_a_ && !_g_ && _v_.indexOf("4.")>-1){
		// If Internet Explorer 4
		_done = true;
		if (parent!=null) host = _d_.all[parent];
		else host = _b_;
		objString = "<div id='"+this.id+"' style='position:absolute'>"+this.content+"</div>";
		host.insertAdjacentHTML(objString);
		this.parent = host;
		this.obj = _d_.all[this.id];
		this.style = this.obj.style;
		this.ref = this.obj.document;
	} else if (_n_ && !_g_){
		// If Netscape Navigator 4
		_done = true;
		if (w==null) w = 0;	// Netscape needs the width of a new layer set at creation for some reason
		if (parent!=null){
			var host = noClue(parent);
			this.obj = (host.document.layers[this.id] = new Layer(w,host));
		} else this.obj = (_d_.layers[this.id] = new Layer(w));
		this.parent = host;
		this.style = this.obj;
		this.ref = this.obj.document;
		with (this.ref){
			open("text/html");
			write(this.content);
			close();
		}
	} else if (_g_){
		// If DOM browser
		_done = true;
		if (parent!=null) host = _d_.getElementById(parent);
		else host = _b_;
		objString = document.createElement("div");
		objString.id = this.id;
		objString.innerHTML = this.content;
		objString.style.position = "absolute";
		this.parent = host;
		this.obj = host.appendChild(objString);
		this.style = this.obj.style;
		this.ref = this.obj.document;
	}
	if (_done){
		// If the function successfully created a new layer
		this.dynCreated = true;
		this.dim.x = this.x(x);
		this.dim.y = this.y(y);
		this.dim.w = this.w(w);
		this.dim.h = this.h(h);
		this.z(z);
		this.show();
	}
	// All non-supporting browsers will exit the function without actually having done anything, which will have to do
};
Thing.prototype.removeDynLayer = function(){
	if (this.dynCreated){
		if (_a_ && !_g_ && _v_.indexOf("4.")>-1){
			
		} else if (_n_ && !_g_){
			
		} else if (_g_) this.parent.removeChild(this.obj);
		this.dynCreated = null;
	}
	this.name = null;
	this.ref = null;
	this.obj = null;
	this.style = null;
	this.parent = null;
	this.contentHTML = null;
	this.content = "";
};
Thing.prototype.remove = function(){
	this.removeDynLayer();
	this.dim.x = null;
	this.dim.y = null;
	this.dim.w = null;
	this.dim.h = null;
	this.dim = null;
	this.id = null;
	this.nr = null;
	this.content = null;
};
Thing.prototype.x = function(x){
	tx = null;
	if (x!=null){
		this.dim.x = x;
		this.style.left = x;
		tx = x;
	} else{
		if (_n_) tx = this.obj.left;
		else if (this.obj.offsetParent){
			tx = 0;
			var tobj = this.obj.offsetParent;
			while (tobj){
				tx += this.obj.offsetLeft;
				tobj = tobj.offsetParent;
			}
		} else if (_o_ || _g_ && this.style.pixelLeft) tx = this.style.pixelLeft;
		else tx = parseInt(this.style.left);
		this.dim.x = tx;
	}
	return tx;
};
Thing.prototype.y = function(y){
	ty = null;
	if (y!=null){
		this.dim.y = y;
		this.style.top = y;
		ty = y;
	} else{
		if (_n_) ty = this.obj.top;
		else if (this.obj.offsetParent){
			ty = 0;
			var tobj = this.obj;
			while (tobj){
				ty += this.obj.offsetTop;
				tobj = tobj.offsetParent;
			}
		} else if (_o_ || _g_ && this.style.pixelTop) ty = this.style.pixelTop;
		else ty = parseInt(this.style.top);
		this.dim.y = ty;
	}
	return ty;
};
Thing.prototype.w = function(w,noclip){
	tw = null;
	if (w!=null){
		if (w<0) return null;
		this.dim.w = w;
		this.style.width = w;
		this.style.height = this.dim.h || 0;
		tw = w;
		if (!noclip){
			if (_n_){
				this.obj.clip.right = w;
				this.obj.clip.bottom = this.dim.h;
				this.obj.clip.left = 0;
				this.obj.clip.top = 0;
			} else this.style.clip = "rect(0 "+w+" "+this.dim.h+" 0)";
		}
	} else{
		if (_n_) tw = (this.obj.clip.width || this.ref.width);
		else if (this.obj.offsetWidth && (this.style.clip=="")) tw = this.obj.offsetWidth;
		else if (_o_ || _g_ && this.style.pixelWidth) tw = this.style.pixelWidth;
		else tw = parseInt(this.style.width);
		this.dim.w = tw;
	}
	return tw;
};
Thing.prototype.h = function(h,noclip){
	th = null;
	if (h!=null){
		if (h<0) return null;
		this.dim.h = h;
		this.style.width = this.dim.w || 0;
		this.style.height = h;
		th = h;
		if (!noclip){
			if (_n_){
				this.obj.clip.right = this.dim.w;
				this.obj.clip.bottom = h;
				this.obj.clip.left = 0;
				this.obj.clip.top = 0;
			} else this.style.clip = "rect(0 "+this.dim.w+" "+h+" 0)";
		}
	} else{
		if (_n_) th = (this.obj.clip.height || this.ref.height);
		else if (this.obj.offsetHeight && (this.style.clip=="")) th = this.obj.offsetHeight;
		else if (_o_ || _g_ && this.style.pixelHeight) th = this.style.pixelHeight;
		else th = parseInt(this.style.height);
		this.dim.h = th;
	}
	return th;
};
Thing.prototype.z = function(z){
	tz = null;
	if (z!=null){
		this.style.zIndex = z;
		tz = z;
	} else tz = this.style.zIndex;
	return tz;
};
Thing.prototype.addBorder = function(bsize){
	w = this.dim.w + bsize*2;
	h = this.dim.h + bsize*2;

	if (_n_){
		this.obj.clip.right = w;
		this.obj.clip.bottom = h;
		this.obj.clip.left = 0;
		this.obj.clip.top = 0;
	}
	else this.style.clip = "rect(0 "+w+" "+h+" 0)";
};
Thing.prototype.show = function(){this.style.visibility = (_n_ && !_g_)? "show" : "visible";};
Thing.prototype.hide = function(){this.style.visibility = (_n_ && !_g_)? "hide" : "hidden";};
Thing.prototype.bg = function(r,g,b){this.bg(rgb2str(r,g,b));};
Thing.prototype.bg = function(c){
	if (_o_) this.style.background = c;
	else if (_g_ || _a_) this.style.backgroundColor = c;
	else if (_n_) this.obj.bgColor = c;
};
Thing.prototype.fg = function(r,g,b){this.fg(rgb2str(r,g,b));};
Thing.prototype.fg = function(c){
	if (_n_) this.ref.fgColor = c;
	else this.style.color = c;
};
Thing.prototype.radiusMove = function(x,y,r,de,cSw,cSh){	// cS = compensate for size of object
	var tx = radiusX(x,r,de);
	var ty = radiusY(y,r,de);
	if (cSw) tx -= cSw;
	if (cSh) ty -= cSh;

	this.x(tx);
	this.y(ty);
};
Thing.prototype.move = function(x,y){if (x!=null) this.x(x); if (y!=null) this.y(y);};
Thing.prototype.moveplus = function(x,y){if (x!=null) this.x(this.dim.x+x); if (y!=null) this.y(this.dim.y+y);};
Thing.prototype.resize = function(w,h,noclip){if (w!=null) this.w(w,noclip); if (h!=null) this.h(h,noclip);};
Thing.prototype.resizeplus = function(w,h,noclip){if (w!=null) this.w(this.dim.w+w,noclip); if (h!=null) this.h(this.dim.h+h,noclip);};
Thing.prototype.clip = function(x,w,h,y,nomove){
	if (w==null || h==null) return;
	this.dim.w = w - x;
	this.dim.h = h - y;
	this.style.width = w;
	this.style.height = h;
	if (!nomove) this.moveplus(-x,-y);
	if (_n_){
		this.obj.clip.left = x;
		this.obj.clip.right = w;
		this.obj.clip.top = y;
		this.obj.clip.bottom = h;
	} else this.style.clip = "rect("+x+" "+w+" "+h+" "+y+")";
};
Thing.prototype.alterContent = function(text,ap,upd){
	if (ap=="start") text = text+this.content;
	else if (ap=="end") text = this.content+text;
	if (_n_){
		with (this.ref){
			open("text/html");
			write(text);
			close();
		}
	} else this.obj.innerHTML = text;
	if (upd) this.content = text;
};

onload = function(){_BodyLoad(); BodyLoad();};
onunload = function(){BodyUnLoad(); _BodyUnLoad();};

function BodyLoad(){
	return false;
}
function _BodyLoad(){
	_loaded_ = true;
	if (!_b_) initB();
}
function BodyUnLoad(){
	return false;
}
function _BodyUnLoad(){
	for (i=0; i<_nrDynC_; i++){
		if (Things["Ref_Thing_"+i]){
			Things[i].remove();		// call destructor
			delete Things["Ref_Thing_"+i];	// clear pointer
			Things[i] = null;		// set pointer to null for certainty
		}
	}
	Things = null;	// set the array of pointers to null
	_b_ = null;	// set body pointer to null
	_d_ = null;	// set document pointer to null
}
