var secs;
var timerID = null;
var timerRunning = false;
var delay = 3000; //3 Sekunden
var aProm = null;
var imgProm = null;

function InitializeTimer(aPromID,imgPromID)
{
    // Set the length of the timer, in seconds
    pid = -1;
    aProm   = document.getElementById(aPromID);
    imgProm = document.getElementById(imgPromID);
    StopTheClock();
    if((aProm != null) && (imgProm != null))
	   StartTheTimer();
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer()
{
    if ((Promotions == null) || (Promotions.length < 1) || (aProm == null) || (imgProm == null) )
    {
		pid = -1;
        StopTheClock();
    }
    else
    {
		pid++;
		if(pid >= Promotions.length)
			pid=0;
        aProm.href = Promotions[pid]["Url"];
        aProm.title = Promotions[pid]["Alt"];
        imgProm.alt = Promotions[pid]["Alt"];
        imgProm.src = Promotions[pid]["Src"];
        if(Promotions.length > 1)
        {
           timerRunning = true;
           timerID = setTimeout("StartTheTimer()", delay);
        }
    }
    //self.status = pid;
}


var ie = (document.styleSheets && document.all)?true:false;

		var iRight    = 0;
		var pMaxRight = 0;
		var oMoving  = null;
		var oAround  = null;
		var iStep    = 0;
		var pTime    = 10;
		var pStep    = 25;
		var timerID = null;
		var pMaxWidth = 0;
		var iFirst = 0;
		var iVisible = 0;
		var iWait    = 0;
		var pWait    = 40;
		var bScrolling = false;
		var bWaiting = false;
		var bStopping = true;
		var iDest     = 0;

		function InitTopButton(objTableName,pMinHeight)
		{
			oTable = document.getElementById(objTableName);
			oButtonTop = document.getElementById('aButtonTop');
			if(oTable.offsetHeight > pMinHeight)
			{
				oButtonTop.style.visibility = "visible";
			}
			else
			{
				oButtonTop.style.visibility = "hidden";
			}
		}
		function InitMove(objAround,objToMove,objButtonLeft,objButtonRight,useMaxWidth,useStep,useTime,useWait)
		{
			oMoving = document.getElementById(objToMove);
			oAround = document.getElementById(objAround);
			oButtonLeft = document.getElementById(objButtonLeft);
			oButtonRight = document.getElementById(objButtonRight);
			pMaxWidth = useMaxWidth;
			pTime = useTime;
			pStep = useStep;
			pWait = useWait;
			iFirst = 0;
			pMaxRight = 0;
			if(oMoving != null)
			{
				oAround.style.width = pMaxWidth;
				pMaxRight = oMoving.offsetWidth - oAround.offsetWidth;
				if(pMaxRight > 0)
				{
					AdjustWidth();
					oButtonLeft.style.visibility = "visible";
					oButtonRight.style.visibility = "visible";
				}
				else
				{
					oButtonLeft.style.visibility = "hidden";
					oButtonRight.style.visibility = "hidden";
				}
			}
			//oAround.style.visibility = "visible";
		}
		function AdjustWidth()
		{
			var iPasst = 0;
			iVisible = 0;
			for(i=iFirst;i<oMoving.rows[0].cells.length;i++)
			{
				if((iPasst+oMoving.rows[0].cells[i].offsetWidth) <= pMaxWidth)
				{
					iPasst += oMoving.rows[0].cells[i].offsetWidth;
					iVisible++;
				}
				else
					break;
			}
			oAround.style.width = iPasst;
		}
		function StartMoveRight()
		{
			StartMove(pStep);
		}
		function StartMoveLeft()
		{
			StartMove(-pStep);
		}
		function StartMove(parStep)
		{
			bStopping = false;
			bWaiting = false;
			bScrolling = false;
			if((pMaxRight > 0) && (oAround != null) && (oMoving != null))
			{
				iStep  = parStep;
				iRight = oAround.scrollLeft;			
				MoveNext();
			}
			else
			{
				iStep = 0;
			}
		}
		function CellReached()
		{
			bScrolling = false;
		}
		function NextStep()
		{
			iRight += iStep;
			if(((iStep < 0) && (iRight <= iDest)) ||
				((iStep > 0) && (iRight >= iDest)) )
			{
				iRight = iDest;
				bScrolling = false;
				iWait = 0;
				bWaiting = true;
			}
			oAround.scrollLeft =  iRight;
		}
		function MoveNext()
		{
			if((oAround == null) && (oMoving == null))
			{
				return;
			}
			else if(bScrolling) //Do not STOP !
			{
				NextStep();
			}
			else if(bWaiting)
			{
				if(iWait == 0) //Zuerst die Breite setzen !!
				{
					var oldVisible = iVisible;
					AdjustWidth();
					if(iVisible < oldVisible)
					{
						bWaiting = false; //sofort Weitermachen
					}
				}
				else
				{
					if(bStopping)
					{
						return;
					}
				}
				if(iWait < pWait)
					iWait ++;
				else
				{
					bWaiting = false;
				}
			}
			else
			{				
				//iRight += iStep;
				var bEndReached = false;
				if(iStep < 0)
				{ 					
					if(iFirst > 0)
					{
						iFirst --;
						iDest = oMoving.rows[0].cells[iFirst].offsetLeft;
					}
					else
					{
						bEndReached = true;//Stop on Leftmost position
					}
				}
				if(iStep > 0) 
				{
					if(oMoving.rows[0].cells[iFirst].offsetLeft < pMaxRight) // Ende Rechts
					{				
						iFirst ++;
						if(iFirst < oMoving.rows[0].cells.length)
						{
							iDest = oMoving.rows[0].cells[iFirst].offsetLeft;
//							if(iDest >= pMaxRight)
//							{
//								iStep = 0;//Stop on Rightmost position
//							}
						}
						else
						{
							iFirst --;
							bEndReached = true;//Stop on Rightmost position
						}
					}
					else
					{
						bEndReached = true;
					}
				}
				if(bEndReached)
				{
					AdjustWidth(); //Die Breite setzen !!
					return;
				}
				else
				{
					bScrolling = true;
					NextStep(); //Gleich weitermachen
				}
			}
			timerID = setTimeout("MoveNext()", pTime);
		}
		function StopMove()
		{
			bStopping = true;
			//iStep = 0;
			//clearTimeout(timerID);
		}

function displayQuicknavBoxRel(obj, count, skip, topID){
	var qnb = document.getElementById("dvQuicknavBox");
	
	if (qnb.style.display=="none"){
		var theX = findPosX(obj,topID);
		var theY = findPosY(obj,topID);
		var newH = count-1+(count*14);
		var newT = theY+obj.offsetHeight-skip-newH;
		//alert("Pos QuickNav X="+theX+" Y="+theY+" H="+obj.offsetHeight+" BH="+newH+" TOP="+newT);
		qnb.style.left = theX  + "px";
		qnb.style.top  = newT + "px";
		qnb.style.height = newH +"px";
		qnb.style.display="block";
	} else {
		qnb.style.display="none";
	}
}

function showDesc(obj, txDesc, url, topID, padding, topLines){
	var theX = findPosX(obj,topID);
	var theDesc = document.getElementById("dvProdDesc");
	theDesc.innerHTML = "<a href=\"" + url + "\">" + txDesc + "<img src=\"../../images/arrow.gif\" alt=\"\" border=0\/><\/a>";
	theDesc.style.left = theX;
	theDesc.style.display = "block";
	theDesc.style.marginLeft = padding;
	theDesc.style.paddingTop = (topLines-1) * 15;
}

function findPosX(obj,topID){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent) {
		    if((topID != '') && (topID == obj.id))
				break;
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj,topID){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent) {
		    if((topID != '') && (topID == obj.id))
				break;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function SetBgImage(strTable, strImage)
{
	var oTable = document.getElementById(strTable);
	if(strImage == '')
	{
		oTable.style.backgroundImage = '';
	}
	else
	{
		oTable.style.backgroundImage = "url("+strImage+")";
	}
	oTable.style.backgroundRepeat = "no-repeat";
}
