
function CPosObj(id)		// positionable object
{
	if (document.getElementById)	// version 6 browsers
		this.obj = document.getElementById(id);
	else if (document.all)
		this.obj = document.all[id];
	else if (document.layers)	// Netscape, still using layers
	{
		var a = CPosObj.arguments;
		var len = a.length;
		this.obj = document.layers[a[len - 1]];
		for (var i=len-2; i>=0 && this.obj; i--)
			this.obj = this.obj.document.layers[a[i]];
	}

	this.ref = 'CPosObj_' + id;
	eval(this.ref+'=this');

//	if (browser.ie4comp)
//		this.ShiftTo(this.obj.offsetLeft, this.obj.offsetTop);	// make sure the style properties 'pixelLeft' and 'pixelTop' are set
//		this.ShiftTo(this.GetOffsetLeft(), this.GetOffsetTop());	// make sure the style properties 'pixelLeft' and 'pixelTop' are set
}

CPosObj.prototype.IsValid = function() { return (this.obj != null); };
CPosObj.prototype.toString = function() { return ("[CPosObj:    " + (this.IsValid() ? "\"" + this.obj.id + "\"" : "null") + "]"); };

if (document.layers)	// Netscape, still using layers
{
	CPosObj.prototype.SetLeft = function(x) { this.obj.left = x; };
	CPosObj.prototype.GetLeft = function() { return this.obj.left; };
	CPosObj.prototype.GetOffsetLeft = function() { return this.obj.pageX; };

	CPosObj.prototype.SetTop = function(y) { this.obj.top = y; };
	CPosObj.prototype.GetTop = function() { return this.obj.top; };
	CPosObj.prototype.GetOffsetTop = function() { return this.obj.pageY; };

	CPosObj.prototype.SetZIndex = function(z) { this.obj.zIndex = z; };
	CPosObj.prototype.GetZIndex = function() { return this.obj.zIndex; };

	CPosObj.prototype.GetWidth = function() { return this.obj.document.width; };
	CPosObj.prototype.GetHeight = function() { return this.obj.document.height; };

	CPosObj.prototype.ShiftTo = function(x,y) { this.obj.moveTo(x,y); };
	CPosObj.prototype.ShiftBy = function(dx,dy) { this.obj.moveBy(dx, dy); };
	CPosObj.prototype.SetClip = function(left, top, right, bottom) { this.obj.clip.left = left; this.obj.clip.top = top; this.obj.clip.right = right; this.obj.clip.bottom = bottom; };
	CPosObj.prototype.Show = function(bShow) { this.obj.visibility = bShow ? "visible" : "hidden"; };

	CPosObj.prototype.SetBackColor = function(color) { this.obj.bgColor = ((color == "transparent") ? null : color); };
	CPosObj.prototype.GetBackColor = function() { return this.obj.bgColor; };
}
else if (browser.major >= 4)
{
	 if (browser.ns6comp)	// Netscape, after dropping layers
	{
		CPosObj.prototype.SetLeft = function(x) { this.obj.style.left = (x + "px"); };
		CPosObj.prototype.GetLeft = function() { return 1 * this.obj.style.left.slice(0, -2); };

		CPosObj.prototype.SetTop = function(y) { this.obj.style.top = (y + "px"); };
		CPosObj.prototype.GetTop = function() { return 1 * this.obj.style.top.slice(0, -2); };

		CPosObj.prototype.ShiftTo = function(x,y) { this.obj.style.left = (x + "px"); this.obj.style.top = (y + "px"); };
		CPosObj.prototype.ShiftBy = function(dx,dy) { this.ShiftTo(this.GetLeft() + dx, this.GetTop() + dy); };

	}
	else if (browser.ie4comp)
	{
		CPosObj.prototype.SetLeft = function(x) { this.obj.style.pixelLeft = x; };
		CPosObj.prototype.GetLeft = function() { return this.obj.style.pixelLeft; };	// pixelLeft needs to be set one time first by scripting!
//		CPosObj.prototype.GetOffsetLeft = _offsetLeft;

		CPosObj.prototype.SetTop = function(y) { this.obj.style.pixelTop = y; };
		CPosObj.prototype.GetTop = function() { return this.obj.style.pixelTop; };	// pixelTop needs to be set one time first by scripting!
//		CPosObj.prototype.GetOffsetTop = _offsetTop;

		CPosObj.prototype.ShiftTo = function(x,y) { this.obj.style.pixelLeft = x; this.obj.style.pixelTop = y; };
		CPosObj.prototype.ShiftBy = function(dx,dy) { this.obj.style.pixelLeft += dx; this.obj.style.pixelTop += dy; };	// pixelLeft and pixelTop need to be set one time first by scripting!

//		CPosObj.prototype.SetBackColor = function(color) { this.obj.bgColor = ((color == null) ? "transparent" : color); };
	}

	CPosObj.prototype.GetOffsetLeft = function() { return this.obj.offsetLeft; };
	CPosObj.prototype.GetOffsetTop = function() { return this.obj.offsetTop; };
	CPosObj.prototype.SetZIndex = function(z) { this.obj.style.zIndex = z; };
	CPosObj.prototype.GetZIndex = function() { return this.obj.style.zIndex; };	// zIndex needs to be set one time first by scripting! (at least in IE4)
	CPosObj.prototype.GetWidth = function() { return this.obj.offsetWidth; };	// In Netscape 6: the offsetWidth-property of an object gets clipped when it is (partially) outside its parent container!
	CPosObj.prototype.GetHeight = function() { return this.obj.offsetHeight; };

	CPosObj.prototype.SetClip = function(left, top, right, bottom) { this.obj.style.clip = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)"; };
	CPosObj.prototype.Show = function(bShow) { this.obj.style.visibility = bShow ? "visible" : "hidden"; };

	CPosObj.prototype.SetBackColor = function(color) { this.obj.style.backgroundColor = color; };
	CPosObj.prototype.GetBackColor = function() { return this.obj.style.backgroundColor; };
}

// FADE method
if (browser.ie && (browser.major >= 5) && !browser.mac)
{
	CPosObj.prototype.Fade = function(bIn)
	{
		this.obj.style.filter = 'blendTrans(duration=0.9)';
		this.obj.filters.blendTrans.apply();
		this.Show(bIn);
		this.obj.filters.blendTrans.play();
	}
}
//else if (browser.ns6 || (browser.ie4&&!browser.mac))
//{
//	CPosObj.prototype.Fade = function(bIn)
//	{
//		if (this.nTimer)
//			clearTimeout(this.nTimer);
//		this.nTimer = null;
//		this.target = bIn ? 100 : 0;
//		this.op = bIn ? 0 : 100;
//		this.step = bIn ? 7 : 9;
//
//		if (bIn)
//			this.Show(true);
//		this.FadeStep();
//	}
//
//	CPosObj.prototype.FadeStep = function()
//	{
//		if (Math.abs(this.target - this.op) > this.step)
//		{
//			if (this.target > this.op)
//				 this.op += this.step;
//			else
//				this.op -= this.step;
//			this.SetOpacity(this.op);
//			this.nTimer = setTimeout(this.ref + '.FadeStep()', 10);
//		}
//		else
//		{
//			if (this.target == 0)
//			{
//				this.Show(false);
//				this.SetOpacity(100);
//			}
//			else
//				this.SetOpacity(this.target);
//			this.nTimer = "";
//			this.op = "";
//			this.step = "";
//			this.target = "";
//		}
//	}
//}
else
{
	CPosObj.prototype.Fade = function(bIn) { this.Show(bIn); };
}

// setOPACITY method
if (browser.ns6 || (browser.ie && (browser.major >= 4) && !browser.mac))
{
	CPosObj.prototype.SetOpacity= function(perc)
	{
		this.obj.style.filter= 'alpha(opacity=' + perc + ')';
		this.obj.style.MozOpacity = perc/100;
		this.op = perc;
	}
}
else
{
	CPosObj.prototype.SetOpacity = function(perc) {};
}


if (browser.major >= 4)
{
	CPosObj.prototype.ScrollVTo = function(yEnd, delay)
	{
		if (this.bSliding)
			return;
		if (this.GetOffsetTop() != yEnd)
		{
			this.yEnd = yEnd;
			this.bSliding = true;
			if (delay > 0)
				this.nTimer = setTimeout(this.ref + ".DoScrollStepV()", delay);
			else
				this.DoScrollStepV();
		}
	}

	CPosObj.prototype.DoScrollStepV = function()
	{
		var yCurr = this.GetOffsetTop();
		if (yCurr != this.yEnd)
		{
			var dy = Math.ceil((this.yEnd - yCurr) / 4) + ((yCurr < this.yEnd) ? 1 : -1);
			this.SetTop(yCurr + dy);
			this.nTimer = setTimeout(this.ref + ".DoScrollStepV()", 40);
		}
		else
		{
			this.bSliding = "";
			this.yEnd = "";
			this.nTimer = "";
		}
	}

	CPosObj.prototype.ScrollHTo = function(xEnd, delay)
	{
		if (this.bSliding)
			return;
		if (this.GetOffsetLeft() != xEnd)
		{
			this.xEnd = xEnd;
			this.bSliding = true;
			if (delay > 0)
				this.nTimer = setTimeout(this.ref + ".DoScrollStepH()", delay);
			else
				this.DoScrollStepH();
		}
	}

	CPosObj.prototype.DoScrollStepH = function()
	{
		var xCurr = this.GetOffsetLeft();
		if (xCurr != this.xEnd)
		{
			var dx = Math.ceil((this.xEnd - xCurr) / 4) + ((xCurr < this.xEnd) ? 1 : -1);
			this.SetLeft(xCurr + dx);
			this.nTimer = setTimeout(this.ref + ".DoScrollStepH()", 40);
		}
		else
		{
			this.bSliding = "";
			this.xEnd = "";
			this.nTimer = "";
		}
	}

	CPosObj.prototype.KillTimer = function()
	{
		if (this.nTimer)
		{
			clearTimeout(this.nTimer);
			this.nTimer = "";
		}
	}

}


/********************************************************************************************************/
// function for use during development

CPosObj.prototype.ShowInfo = function() { alert("CPosObj" + (this.IsValid() ? ("\n    id: " + this.obj.id + (this.obj.name ? ("\t(name: " + this.obj.name + ")\n\nx: ") : "\n\nx: ") + this.GetLeft() + "\tdx: " + this.GetWidth() + "\ny: " + this.GetTop() + "\tdy: " + this.GetHeight() + "\nz: " + this.GetZIndex() + "\n\noffset:\t(" + this.GetOffsetLeft() + ", " + this.GetOffsetTop() + ")") : "\tnull") + "\nbkgrnd:\t" + this.GetBackColor()); };
CPosObj.prototype.ShowStyleProperty = function(prop) { alert("CPosObj\t" + (this.IsValid() ? ("\id: " + this.obj.id) : "null") + "\n    " + prop + ":\t" + (this.IsValid() ? ("\"" + this.obj.style[prop] + "\"") : "n.v.t.")); };


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetClientWidth()
{
	if (browser.ie4comp)
		return document.body.clientWidth;		// needs to be loaded!
	if (browser.ns4comp || browser.ns6comp)
	    return window.innerWidth;
	return 0;
}

function GetClientHeight()
{
	if (browser.ie4comp)
		return document.body.clientHeight;		// needs to be loaded!
	if (browser.ns4comp || browser.ns6comp)
	    return window.innerHeight;
	return 0;
}

function GetScrollTop()
{
	if (browser.ie4comp)
		return document.body.scrollTop;		// needs to be loaded!
	if (browser.ns4comp || browser.ns6comp)
		return window.pageYOffset;
	return 0;
}

function GetScrollLeft()
{
	if (browser.ie4comp)
		return document.body.scrollLeft;		// needs to be loaded!
	if (browser.ns4comp || browser.ns6comp)
		return window.pageXOffset;
	return 0;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function _offsetLeft()
{
	var x = this.obj.offsetLeft;
	for (var parent = this.obj.offsetParent; parent != null; parent = parent.offsetParent)
		x += parent.offsetLeft;
	return x;
}

function _offsetTop()
{
	var y = this.obj.offsetTop;
	for (var parent = this.obj.offsetParent; parent != null; parent = parent.offsetParent)
		y += parent.offsetTop;
	return y;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if (browser.ns4comp)	// Netscape, before version 6.0
{
	function HandleResizeBug()
	{
		location.reload();
		return false;
	}

	window.captureEvents(Event.RESIZE);
	window.onresize = HandleResizeBug;
}

