// owner: Rob

self.idThumbTimer = null;
self.idThumbMouseoverNr = null;

function StopThumbChange()
{
	if (self.idThumbTimer)
	{
		clearTimeout(self.idThumbTimer);
		self.idThumbTimer = null;
	}
}

function OnThumbChange(idNr, idMinNr, idMaxNr, nLeft)
{
	if (self.idThumbTimer)
		clearTimeout(self.idThumbTimer);
	self.idThumbTimer = setTimeout("DoThumbChange(" + idNr + ", " + idMinNr + ", " + idMaxNr + ", " + nLeft + ")", 100);
}

function DoThumbChange(idNr, idMinNr, idMaxNr, nLeft)
{
	var obj = document.getElementById("idThumbArrow" + idMinNr);
	if (!obj || !obj.style)
		return;
	obj.style.left = nLeft + "px";
	obj.style.visibility = "visible";	// necessary for sliding thumbs!

	for (var i=idMinNr; i<=idMaxNr; i++)
	{
		var oContentDiv = document.getElementById("idMouseoverContent_" + i);
		var oThumbcell = document.getElementById("idThumbcell" + i);
		
		oContentDiv.style.display = ((i == idNr) ? "" : "none");
		oThumbcell.className = ((i == idNr) ? "thumbmouseovercellactive" : "thumbmouseovercell");
	}
}

function LoopToNextThumb(idNr, idMinNr, idMaxNr, nFirstLeft, nDeltaLeft)
{
	var nLeft = nFirstLeft + (idNr - idMinNr) * nDeltaLeft;
	DoThumbChange(idNr, idMinNr, idMaxNr, nLeft);
	if (++idNr > idMaxNr)
//		idNr = idMinNr;
		self.idThumbTimer = setTimeout("DoThumbChange(" + idMinNr + ", " + idMinNr + ", " + idMaxNr + ", " + nFirstLeft + ")", 3000);
	else
		self.idThumbTimer = setTimeout("LoopToNextThumb(" + idNr + ", " + idMinNr + ", " + idMaxNr + ", " + nFirstLeft + ", " + nDeltaLeft + ")", 3000);
}

function OnThumbVChange(idNr, idMinNr, idMaxNr, nTop)
{
	if (self.idThumbTimer)
		clearTimeout(self.idThumbTimer);
	self.idThumbTimer = setTimeout("DoThumbVChange(" + idNr + ", " + idMinNr + ", " + idMaxNr + ", " + nTop + ")", 100);
	
}

function DoThumbVChange(idNr, idMinNr, idMaxNr, nTop)
{
	var obj = document.getElementById("idThumb2Arrow" + idMinNr);
//alert(obj);
	if (!obj || !obj.style)
		return;
	obj.style.top = nTop + "px";
	obj.style.visibility = "visible";	// necessary for sliding thumbs!

	for (var i=1; i<=idMaxNr; i++)
	{
		var oContentDiv = document.getElementById("idMouseoverContent_" + i);
		var oThumbcell = document.getElementById("idThumbcell" + i);
		
		oContentDiv.style.display = ((i == idNr) ? "" : "none");
		oThumbcell.className = ((i == idNr) ? "thumbmouseover2cellactive" : "thumbmouseover2cell");
	}
}

function OnThumb2Change(idNr, idMaxNr, sSrc, nTop)
{
	if (self.idThumbTimer)
		clearTimeout(self.idThumbTimer);
	self.idThumbTimer = setTimeout("DoThumb2Change(" + idNr + ", " + idMaxNr + ", '" + sSrc + "', " + nTop + ")", 1000);
}

function DoThumb2Change(idNr, idMaxNr, sSrc, nTop)
{
	var obj = document.getElementById("idThumb2Arrow");
	if (!obj || !obj.style)
		return;
	obj.style.top = nTop + "px";
	obj.style.visibility = "visible";	// necessary for sliding thumbs!
	document.photodisplay.src = sSrc;

	for (var i=1; i<=idMaxNr; i++)
	{
		var oThumbcell = document.getElementById("idThumbcell" + i);
		oThumbcell.className = ((i == idNr) ? "photonavthumbactive" : "photonavthumb");
	}
}




function _CSlidingThumbsBase()
{
	this.obj = null;
	this.objIndicator = null;
	this.objSlider = null;
	this.nIndicatorStartPos = 0;
	this.nVisibleLength = 0;
	this.nStepLength = 0;
	this.nTotalLength = 0;
	this.nCrossLength = 0;
	this.nPosMax = 0;
	this.nPos = 0;
	this.nSliderStep = 0;
	this.bKeepInside = false;
	this.nMinIdNr = 0;
	this.nMaxIdNr = 0;
}
_CSlidingThumbsBase.prototype._Construct = function(nIdNr, nIndicatorStartPos, nVisibleLength, nStepLength, nTotalLength, nCrossLength, bKeepInside)
{
	var nThumbCount = nStepLength ? Math.round(nTotalLength / nStepLength) : 0;
	this.obj = document.getElementById("idThumbDiv" + nIdNr);
	this.objSlider = document.getElementById("idThumbSlider" + nIdNr);
	this.nIndicatorStartPos = nIndicatorStartPos;
	this.nVisibleLength = nVisibleLength;
	this.nStepLength = nStepLength;
	this.nTotalLength = nTotalLength;
	this.nCrossLength = nCrossLength;
	this.nPosMax = nTotalLength - nVisibleLength;
	if (nStepLength)
		this.nPosMax = nStepLength * Math.round(this.nPosMax / nStepLength);
	if (nTotalLength)
		this.nSliderStep = Math.round(nStepLength * nVisibleLength / nTotalLength);
	if (bKeepInside)
		this.bKeepInside = true;
	this.nMinIdNr = nIdNr;
	this.nMaxIdNr = nIdNr + nThumbCount - 1;
}
_CSlidingThumbsBase.prototype.OnThumbChange = function(idNr, nPos)
{
	// call the handler of the simple (no sliding) thumbmouseover with one little change
	OnThumbChange(idNr, this.nMinIdNr, this.nMaxIdNr, nPos - this.nPos);
}
_CSlidingThumbsBase.prototype.OnThumb2Change = function(idNr, nPos, sSrc)
{
	// call the handler of the simple (no sliding) thumbmouseover with one little change
	OnThumb2Change(idNr, this.nMaxIdNr, sSrc, nPos - this.nPos);
}
_CSlidingThumbsBase.prototype.StepLeft = function()
{
	if (!this.obj || (this.nPos <= 0))
		return;

	this.nPos -= this.nStepLength;
	this.obj.style.left = "-" + this.nPos + "px";
	this.obj.style.clip = "rect(0 " + (this.nPos + this.nVisibleLength) + "px " + this.nCrossLength + "px " + this.nPos + "px)";
	if (this.objIndicator)
		this._SetIndicatorPos(GetLeftPos(this.objIndicator) + this.nStepLength, "left");
	if (this.objSlider)
	{
		var x = GetLeftPos(this.objSlider) - this.nSliderStep;
		this.objSlider.style.left = x + "px";
	}
}
_CSlidingThumbsBase.prototype.StepRight = function()
{
//	this._Dump();
	if (!this.obj || (this.nPos >= this.nPosMax))
		return;

	this.nPos += this.nStepLength;
	this.obj.style.left = "-" + this.nPos + "px";
	this.obj.style.clip = "rect(0 " + (this.nPos + this.nVisibleLength) + "px " + this.nCrossLength + "px " + this.nPos + "px)";
	if (this.objIndicator)
		var x = this._SetIndicatorPos(GetLeftPos(this.objIndicator) - this.nStepLength, "left");
	if (this.objSlider)
	{
		var x = GetLeftPos(this.objSlider) + this.nSliderStep;
		this.objSlider.style.left = x + "px";
	}
}
_CSlidingThumbsBase.prototype.StepUp = function()
{
	if (!this.obj || (this.nPos <= 0))
		return;

	this.nPos -= this.nStepLength;
	this.obj.style.top = "-" + this.nPos + "px";
	this.obj.style.clip = "rect(" + this.nPos + "px " + this.nCrossLength + "px " + (this.nPos + this.nVisibleLength) + "px 0)";
	if (this.objIndicator)
		this._SetIndicatorPos(GetTopPos(this.objIndicator) + this.nStepLength, "top");
	if (this.objSlider)
	{
		var y = GetTopPos(this.objSlider) - this.nSliderStep;
		this.objSlider.style.top = y + "px";
	}
}
_CSlidingThumbsBase.prototype.StepDown = function()
{
	if (!this.obj || (this.nPos >= this.nPosMax))
		return;

	this.nPos += this.nStepLength;
	this.obj.style.top = "-" + this.nPos + "px";
	this.obj.style.clip = "rect(" + this.nPos + "px " + this.nCrossLength + "px " + (this.nPos + this.nVisibleLength) + "px 0)";
	if (this.objIndicator)
		this._SetIndicatorPos(GetTopPos(this.objIndicator) - this.nStepLength, "top");
	if (this.objSlider)
	{
		var y = GetTopPos(this.objSlider) + this.nSliderStep;
		this.objSlider.style.top = y + "px";
	}
}
_CSlidingThumbsBase.prototype._SetIndicatorPos = function(nNewPos, sStyleProp)
{
	if (!this.bKeepInside)
	{
		this.objIndicator.style.visibility = ((nNewPos >= 0) && (nNewPos <= this.nVisibleLength)) ? "visible" : "hidden";
		this.objIndicator.style[sStyleProp] = nNewPos + "px";
	}
	else if (nNewPos < 0)
	{
		var nFirstVisible = this.nStepLength ? this.nPos / this.nStepLength : 0;
		var idNewActive = this.nMinIdNr + nFirstVisible;
		var oThumbcell = document.getElementById("idThumbcell" + idNewActive);
		oThumbcell.className = "thumbmouseovercellactive";
		this.OnThumbChange(idNewActive, this.nIndicatorStartPos + nFirstVisible * this.nStepLength);
	}
	else if (nNewPos > this.nVisibleLength)
	{
		var nLastVisible = (this.nStepLength ? Math.round((this.nPos + this.nVisibleLength) / this.nStepLength) : 1) - 1;
		var idNewActive = this.nMinIdNr + nLastVisible;
		var oThumbcell = document.getElementById("idThumbcell" + idNewActive);
		oThumbcell.className = "thumbmouseovercellactive";
		this.OnThumbChange(idNewActive, this.nIndicatorStartPos + nLastVisible * this.nStepLength);
	}
	else
		this.objIndicator.style[sStyleProp] = nNewPos + "px";
}
_CSlidingThumbsBase.prototype._Dump = function()
{
	var s = "";
	for (var prop in this)
	{
		if (typeof this[prop] != "function")
			s += prop + ": " + this[prop] + "\n";
	}
	s += "\n";
	for (var prop in this)
	{
		if (typeof this[prop] == "function")
			s += prop + ": function()\n";
	}
	alert(s);
}




function CSlidingThumbsH(nIdNr, nIndicatorStartPos, nVisibleWidth, nStepWidth, nTotalWidth, nTotalHeight, bKeepInside)
{
	this.objIndicator = document.getElementById("idThumbArrow" + nIdNr);
	this._Construct(nIdNr, nIndicatorStartPos, nVisibleWidth, nStepWidth, nTotalWidth, nTotalHeight, bKeepInside);
//	this._Dump();
}
CSlidingThumbsH.prototype = new _CSlidingThumbsBase();
CSlidingThumbsH.prototype.constructor = "CSlidingThumbsH";



function CSlidingThumbsV(nIdNr, nIndicatorStartPos, nVisibleHeight, nStepHeight, nTotalHeight, nTotalWidth, bKeepInside)
{
	this.objIndicator = document.getElementById("idThumb2Arrow" + nIdNr);
	this._Construct(nIdNr, nIndicatorStartPos, nVisibleHeight, nStepHeight, nTotalHeight, nTotalWidth, bKeepInside);
}
CSlidingThumbsV.prototype = new _CSlidingThumbsBase();
CSlidingThumbsV.prototype.constructor = "CSlidingThumbsV";





function GetLeftPos(obj)
{
	var x = obj.style.pixelLeft;
	if (typeof x == "undefined")
		x = obj.offsetLeft;
	if (typeof x == "undefined")
		x = obj.style.left.replace(/[^0-9]+/g, "");
	return x;
}

function GetTopPos(obj)
{
	var y = obj.style.pixelTop;
	if (typeof y == "undefined")
		y = obj.offsetTop;
	if (typeof y == "undefined")
		y = obj.style.top.replace(/[^0-9]+/g, "");
	return y;
}
