/*********************************************
(c) 1999-2003 Die Informationsgesellschaft mbH
www.informationsgesellschaft.com
*********************************************/

var bFirstInit = true;

function reloadOnResize (oEvent) {  //reloads the window if Nav4 resized
	if (!oEvent) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    	document._innerWidth=innerWidth; 
			document._innerHeight=innerHeight; 
			onresize=reloadOnResize; 
		}
	}
  else 
		if (innerWidth!=document._innerWidth || innerHeight!=document._innerHeight) location.reload();
}
reloadOnResize();


var cLayerMode = (document.layers ? 'NS4' : (document.getElementById ? 'DOM' : (document.all ? 'IE4' : '')));
var cLOnAnimComplete = null;

function initLayerAll (oLayer) {
	oLayer.setVisible = function (bVisible) {
		this.set ('visibility', bVisible);
	}

	oLayer.activateInteraction = function() {
	}
	
	oLayer.clipp = function (nClipLeft, nClipTop, nClipWidth, nClipHeight) {
		this.set ('clip', new Rect(nClipLeft, nClipTop, nClipWidth, nClipHeight));
	}
		
	oLayer.setBackground = function (cBackground) {
		if (cBackground.charAt(0) == '#')
			this.set ('backgroundColor', cBackground);
		else 
			this.set ('backgroundImage', cBackground);
	}

	oLayer.moveAbsTo = function (nLeft, nTop) {
		this.set('left', nLeft);
		this.set('top', nTop);
	}

	oLayer.moveTo = function (nLeft, nTop) {
		var oClip = this.get('clip');
		return (this.moveAbsTo (nLeft - 0, nTop - 0));
	}

	oLayer.moveBy = function (nDistX, nDistY) {
		return (this.moveAbsTo (this.get('left') + nDistX, this.get('top') + nDistY));
	}
	
	oLayer.scrollTo = function (nClipLeft, nClipTop) {
		var oClip = this.get('clip');
		return (this.scrollBy (nClipLeft - oClip.left, nClipTop - oClip.top));
	}

	oLayer.scrollBy = function (nDistX, nDistY) {
		var oClip = this.get('clip');
		var nClipRight = oClip.left + oClip.width,
				nClipBottom = oClip.top + oClip.height;
	
	  // If scrolling the given amounts would move past the edges of the layer,
	  // adjust the values so we stop right at the edge.
	  if (oClip.left + nDistX < 0)
	    nDistX = -oClip.left;
	  else if (oClip.getRight() + nDistX > this.get('width'))
	    nDistX = this.get('width') - oClip.getRight();
			
	  if (oClip.top + nDistY < 0)
	    nDistY = -oClip.top;
	  else if (oClip.getBottom() + nDistY > this.get('height'))
	    nDistY = this.get('height') - oClip.getBottom();
	
	  // Move both the clipping region and the layer so that the contents move
	  // but the viewable region of the layer appears fixed relative to the page.
	  this.clipp (oClip.left + nDistX, oClip.top + nDistY, oClip.width, oClip.height);
	  this.moveBy(-nDistX, -nDistY);
	}

	oLayer.AnimationCompleted = function (cOnComplete, cAnimationType) {
		var nType;
		
		if (cOnComplete) eval(cOnComplete);
		if (this.cOnAnimComplete && !this.isAnimationActive()) {
			eval (this.cOnAnimComplete);
			this.cOnAnimComplete = null;
		}
	
		if (cLOnAnimComplete && !isLayerAnimationActive()) {
			eval (cLOnAnimComplete);
			cLOnAnimComplete = null;
		}
	}

	oLayer.animateClip = function (nClipLeft, nClipTop, nClipWidth, nClipHeight, nMSeconds, nSteps) {
		var oNow = new Date(), oAnim, bQuit, cOnComplete;
		if (nClipLeft != null) {
			bQuit = false;	
			if (this.oAnimClip) {
				this.oAnimClip.nLeft 			= nClipLeft;
				this.oAnimClip.nTop  			= nClipTop;
				this.oAnimClip.nMSeconds 	= this.oAnimClip.nMSeconds - (this.oAnimClip.oEndTime - oNow.getTime()) + nMSeconds;
				this.oAnimClip.oEndTime.setTime (oNow.getTime() + nMSeconds);
				this.oAnimClip.nSteps			= this.oAnimClip.nSteps + nSteps;
				bQuit = true;
			}
			else
				this.oAnimClip = new LayerAnimationOptions(nClipLeft, nClipTop, nMSeconds, nSteps);
	
			this.oAnimClip.nWidth			= nClipWidth;
			this.oAnimClip.nHeight		= nClipHeight;
			aDebugInfo = new Array();
		}
		else
			bQuit = (!this.oAnimClip);
	
		if (!bQuit) {	
			if (this.oAnimClip.oEndTime - oNow.getTime() <= 0 || this.oAnimClip.nSteps <= 1) {
				this.clipp (this.oAnimClip.nLeft, this.oAnimClip.nTop, this.oAnimClip.nWidth, this.oAnimClip.nHeight);
				cOnComplete = this.oAnimClip.cOnComplete;
				this.oAnimClip = null;
				this.AnimationCompleted (cOnComplete, 'CLIP');
			}
			else {
				var nStepX1, nStepY1, nStepX2, nStepY2;
				var oClip = this.get ('clip');
			
				nStepX1 = Math.round((this.oAnimClip.nLeft - oClip.left) / this.oAnimClip.nSteps);
				nStepY1 = Math.round((this.oAnimClip.nTop - oClip.top) / this.oAnimClip.nSteps);
				nStepX2 = Math.round((this.oAnimClip.nWidth - oClip.width) / this.oAnimClip.nSteps);
				nStepY2 = Math.round((this.oAnimClip.nHeight - oClip.height) / this.oAnimClip.nSteps);
				this.clipp (oClip.left + nStepX1, oClip.top + nStepY1, oClip.width + nStepX2, oClip.height + nStepY2);
		
				setTimeout ('getLayer("' + this.get('ID') + '").animateClip()', this.oAnimClip.calculateWaitTime());
			}
		}
	}

	oLayer.animateMoveTo = function (nLeft, nTop, nMSeconds, nSteps) {
		var oNow = new Date(), bQuit, cOnComplete;
	
		if (this.animateMoveTo.arguments.length > 0) {
			bQuit = false;	
			if (this.oAnimMove) {
				this.oAnimMove.nLeft 			= nLeft;
				this.oAnimMove.nTop  			= nTop;
				this.oAnimMove.nMSeconds 	= this.oAnimMove.nMSeconds - (this.oAnimMove.oEndTime - oNow.getTime()) + nMSeconds;
				this.oAnimMove.oEndTime.setTime (oNow.getTime() + nMSeconds);
				this.oAnimMove.nSteps			= this.oAnimMove.nSteps + nSteps;
				bQuit = true;
			}
			else
				this.oAnimMove = new LayerAnimationOptions(nLeft, nTop, nMSeconds, nSteps);
			aDebugInfo = new Array();
		}
		else {
			bQuit = (this.oAnimMove == false);
		}
	
		if (!bQuit) {	
			if (this.oAnimMove.oEndTime - oNow.getTime() <= 0 || this.oAnimMove.nSteps <= 1) {
				this.moveTo (this.oAnimMove.nLeft, this.oAnimMove.nTop);
				cOnComplete = this.oAnimMove.cOnComplete;
				this.oAnimMove = null;
				this.AnimationCompleted (cOnComplete, 'MOVE');
			}
			else {
				var nStepX, nStepY;
				nStepX = Math.round((this.oAnimMove.nLeft - this.get('left')) / this.oAnimMove.nSteps);
				nStepY = Math.round((this.oAnimMove.nTop - this.get('top')) / this.oAnimMove.nSteps);
				this.moveBy (nStepX, nStepY);
		
				setTimeout ('getLayer("' + this.get('ID') + '").animateMoveTo()', this.oAnimMove.calculateWaitTime());
			}
		}
	}

	oLayer.animateMoveBy = function (nDistX, nDistY, nMSeconds, nSteps){
		var oNow = new Date();
		if (this.oAnimMove) {
			this.oAnimMove.nLeft 			= this.oAnimMove.nLeft + nDistX;
			this.oAnimMove.nTop  			= this.oAnimMove.nTop + nDistY;
			this.oAnimMove.nMSeconds 	= this.oAnimMove.nMSeconds - (this.oAnimMove.oEndTime - oNow.getTime()) + nMSeconds;
			this.oAnimMove.oEndTime.setTime (oNow.getTime() + nMSeconds);
			this.oAnimMove.nSteps			= this.oAnimMove.nSteps + nSteps;
		}
		else
			this.animateMoveTo (this.get('left') + nDistX, this.get('top') + nDistY, nMSeconds, nSteps);
	}
	
	oLayer.animateScrollTo = function (nLeft, nTop, nMSeconds, nSteps) {
		var oNow = new Date(), oAnim, bQuit, cOnComplete;
		if (nLeft != null) {
			bQuit = false;
			if (this.oAnimScroll) {
				this.oAnimScroll.nLeft 			= nLeft;
				this.oAnimScroll.nTop  			= nTop;
				this.oAnimScroll.nMSeconds 	= this.oAnimScroll.nMSeconds - (this.oAnimScroll.oEndTime - oNow.getTime()) + nMSeconds;
				this.oAnimScroll.oEndTime.setTime (oNow.getTime() + nMSeconds);
				this.oAnimScroll.nSteps			= this.oAnimScroll.nSteps + nSteps;
				bQuit = true;
			}
			else
				this.oAnimScroll = new L2_AnimationOptions(nLeft, nTop, nMSeconds, nSteps);
			aDebugInfo = new Array();
		}
		else
			bQuit = (!this.oAnimScroll);
	
		if (!bQuit) {	
			oAnim = this.oAnimScroll;
			if (this.oAnimScroll.oEndTime - oNow.getTime() <= 0 || this.oAnimScroll.nSteps <= 1) {
				this.scrollTo (this.oAnimScroll.nLeft, this.oAnimScroll.nTop);
				cOnComplete = this.oAnimScroll.cOnComplete;
				this.oAnimScroll = null;
				this.AnimationCompleted (cOnComplete, 'SCROLL');
			}
			else {
				var nStepX, nStepY;
				var oClip = this.get('clip');
			
				nStepX = Math.round((this.oAnimScroll.nLeft - oClip.left) / this.oAnimScroll.nSteps);
				nStepY = Math.round((this.oAnimScroll.nTop - oClip.top) / this.oAnimScroll.nSteps);
				this.scrollBy (nStepX, nStepY);
		
				setTimeout ('getLayer("' + this.get('ID') + '").animateScrollTo()', this.oAnimScroll.calculateWaitTime());
			}
		}
	}

	oLayer.animateScrollBy = function (nDistX, nDistY, nMSeconds, nSteps) {
		var oNow = new Date();
		if (this.oAnimScroll) {
			this.oAnimScroll.nLeft 			= this.oAnimScroll.nLeft + nDistX;
			this.oAnimScroll.nTop  			= this.oAnimScroll.nTop + nDistY;
			this.oAnimScroll.nMSeconds 	= this.oAnimScroll.nMSeconds - (this.oAnimScroll.oEndTime - oNow.getTime()) + nMSeconds;
			this.oAnimScroll.oEndTime.setTime (oNow.getTime() + nMSeconds);
			this.oAnimScroll.nSteps			= this.oAnimScroll.nSteps + nSteps;
		}
		else {
			var oClip = this.get ('clip');
			this.animateScrollTo (oClip.left + nDistX, oClip.top + nDistY, nMSeconds, nSteps);
		}
	}

	oLayer.isAnimationActive = function (cAnimationType) {
		if (cAnimationType) cAnimationType = cAnimationType.toUpperCase();
		switch (cAnimationType) {
			case 'CLIP'		: return (this.oAnimClip != null); break;
			case 'MOVE'		: return (this.oAnimMove != null); break;
			case 'SCROLL'	: return (this.oAnimScroll != null); break;
			default				:	return (this.oAnimClip!=null || this.oAnimMove!=null || this.oAnimScroll!=null);
		}
	}
	
	oLayer.interuptAnimation = function (cAnimationType) {
		if (cAnimationType) cAnimationType = cAnimationType.toUpperCase();
		switch (cAnimationType) {
			case 'CLIP'		: this.oAnimClip		= null; break;
			case 'MOVE'		: this.oAnimMove 		= null; break;
			case 'SCROLL'	: this.oAnimScroll 	= null;
			default				: this.oAnimClip		= null;
											this.oAnimMove 		= null;
		}
	}

	oLayer.onAnimationComplete = function (cExpr, cAnimationType) {
		if (cAnimationType) cAnimationType = cAnimationType.toUpperCase();
		switch (cAnimationType) {
			case 'CLIP'		: if (this.oAnimClip) this.oAnimClip.cOnComplete = cExpr; break;
			case 'MOVE'		: if (this.oAnimMove) this.oAnimMove.cOnComplete = cExpr; break;
			case 'SCROLL'	: if (this.oAnimScroll) this.oAnimScroll.cOnComplete = cExpr; break;
			default				: if (this.isAnimationActive()) this.cOnAnimComplete = cExpr;
		}
	}

}

function interuptLayerAnimations () {
	var aLayers = getAllLayers();
	for (var oLayer in aLayers) oLayer.interuptAnimation();
}

function isLayerAnimationActive (cAnimationType) {
	var bActive = false;
	var aLayers = getAllLayers();
	var i=0;

	while (!bActive && i < aLayers.length) {
		bActive = aLayers[i].isAnimationActive(cAnimationType);
		i++;
	}
	return (bActive);
}

function onLayerAnimationComplete (cExpr) {
	cLOnAnimComplete = cExpr;
}



function LayerAnimationOptions (nLeft, nTop, nMSeconds, nSteps, oEndTime) {
	this.nLeft 			= nLeft;
	this.nTop				= nTop;
	this.nWidth			= 0;
	this.nHeight		= 0;
	this.nMSeconds	= nMSeconds;
	this.oEndTime		= new Date();
	this.oEndTime.setTime (this.oEndTime.getTime() + nMSeconds);
	this.nSteps			= nSteps;
	this.nStepsDone	= 0;
	this.cOnComplete= null;
	
	this.calculateWaitTime = function () {
		var oNow = new Date(), nCalcSteps, nLeftTime = (this.oEndTime - oNow.getTime());
		if (this.nStepsDone > 0 && this.nSteps > 20 && (nLeftTime < this.nMSeconds)) {
			nCalcSteps = Math.round(this.nStepsDone * nLeftTime / (this.nMSeconds - nLeftTime));
			if (nCalcSteps >= 10 && nCalcSteps < this.nSteps-1) {
				aDebugInfo[aDebugInfo.length] = 'correctSteps ' + this.nSteps + ' -> ' + nCalcSteps;
				this.nSteps = nCalcSteps + 1;
			}
		}
		this.nSteps--;
		this.nStepsDone++;
		return (this.nSteps > 0 ? Math.round (nLeftTime / this.nSteps) : 0);
	} 
}

function Rect(left, top, width, height) {
	this.left = left;
	this.top  = top;
	this.width = width;
	this.height = height;

	this.getRight = function() {
		return (this.left + this.width);
	}
	
	this.getBottom = function() {
		return (this.top + this.height);
	}
}

var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + 'js/Lib/';
document.write ('<SCR' + 'IPT LANGUAGE="JavaScript1.2" SRC="' + cPath + 'BLayer3_' + cLayerMode + '.js" TYPE="text/javascript"><\/SCR' + 'IPT>');



