BrowserIE=navigator.appVersion.indexOf("MSIE")!=-1?true:false;

function TransitionManager() {
	this.TransitionOBJs=new Array();
};
TransitionManager.prototype.AddOBJ=function(Element) {
	if (Element.TMID!=undefined && isFinite(Element.TMID))
		return Element.TMID;
	this.TransitionOBJs.push(new TransitionOBJ(Element));
	var Index=this.TransitionOBJs.length-1;
	Element.TMID=Index;
	this.TransitionOBJs[Index].TMID=Index;
	return this.TransitionOBJs[Index];
};
TransitionManager.prototype.GetOBJ=function(Element) {
	if (!isNaN(Element.TMID) && Element.TMID!=undefined && isFinite(Element.TMID))
		return this.TransitionOBJs[Element.TMID];
	else	return this.AddOBJ(Element);
};
TransitionManager.prototype.FadeEngine=function(OBJIndex) {
	var thisObject=this.TransitionOBJs[OBJIndex];
	thisObject.Iteration++;
	if (thisObject.CurrentOpacity<thisObject.FadeInOut) {	// FadeIn
		thisObject.CurrentOpacity+=thisObject.FadeOpacityStepping;
		if (thisObject.CurrentOpacity>=thisObject.FadeInOut)
			thisObject.CurrentOpacity=thisObject.FadeInOut;
	} else { 	// FadeOut
		thisObject.CurrentOpacity-=thisObject.FadeOpacityStepping;
		if (thisObject.CurrentOpacity<thisObject.FadeInOut)
			thisObject.CurrentOpacity=thisObject.FadeInOut;
	};
/*	if (thisObject.FadeInOut) {	// FadeIn
		thisObject.CurrentOpacity+=thisObject.FadeOpacityStepping;
		if (thisObject.CurrentOpacity>=1)
			thisObject.CurrentOpacity=0.99;
	} else { 	// FadeOut
		thisObject.CurrentOpacity-=thisObject.FadeOpacityStepping;
		if (thisObject.CurrentOpacity<0)
			thisObject.CurrentOpacity=0;
	};*/
	SetOpacity(thisObject.OBJ, thisObject.CurrentOpacity);
	if (thisObject.FadeBlink) {
		if (thisObject.CurrentOpacity<=0.2) {
			thisObject.CurrentOpacity=0.21;
			thisObject.FadeInOut=(thisObject.FadeInOut+1)%2;
		} else if (thisObject.CurrentOpacity>=0.8) {
			thisObject.CurrentOpacity=0.79;
			thisObject.FadeInOut=(thisObject.FadeInOut+1)%2;
		};
	} else if (thisObject.CurrentOpacity<=0 || thisObject.CurrentOpacity>=0.99) {
		clearInterval(thisObject.Interval);
		thisObject.Iteration=0;
		if (thisObject.Callback)
			thisObject.Callback(thisObject);
	};
};
TransitionManager.prototype.ZoomEngine=function(OBJIndex) {
	var thisObject=this.TransitionOBJs[OBJIndex];
	thisObject.ZoomIteration++;
	var DidSomething=false;
	if (thisObject.ZoomInOut) { // ZoomIn
		if (thisObject.CurrentWidth<thisObject.TargetWidth) {
//alert(thisObject.TMID+' - CurrentWidth '+thisObject.CurrentWidth);
			thisObject.CurrentWidth+=thisObject.ZoomWidthStepping;
//			if (thisObject.CurrentWidth>thisObject.TargetWidth)
//				thisObject.CurrentWidth=thisObject.TargetWidth;
			if (thisObject.CompensateLeft) {
				thisObject.Left-=thisObject.ZoomWidthStepping+thisObject.ZoomMovementOffset;
				thisObject.OBJ.style.left=thisObject.Left+'px';
			};
			if (thisObject.OBJ.nodeName=='DIV')
				thisObject.OBJ.style.width=thisObject.CurrentWidth+'px';
			else	thisObject.OBJ.width=thisObject.CurrentWidth;
			DidSomething=true;
		} else if (thisObject.OBJ.nodeName=='DIV') {
//			thisObject.OBJ.style.width=thisObject.TargetWidth+'px';
//			if (parseInt(thisObject.OBJ.style.left)<0)
//				thisObject.OBJ.style.left='0px';
		};
		if (thisObject.CurrentHeight<thisObject.TargetHeight) {
			thisObject.CurrentHeight+=thisObject.ZoomHeightStepping;
//			if (thisObject.CurrentHeight>thisObject.TargetHeight)
//				thisObject.CurrentHeight=thisObject.TargetHeight;
			if (thisObject.CompensateTop) {
				thisObject.Top-=thisObject.ZoomHeightStepping+thisObject.ZoomMovementOffset;
				thisObject.OBJ.style.top=thisObject.Top+'px';
			};
			if (thisObject.OBJ.nodeName=='DIV')
				thisObject.OBJ.style.height=thisObject.CurrentHeight+'px';
			else	thisObject.OBJ.height=thisObject.CurrentHeight;
			DidSomething=true;
		} else if (thisObject.OBJ.nodeName=='DIV') {
//			thisObject.OBJ.style.height=thisObject.TargetHeight+'px';
//			if (parseInt(thisObject.OBJ.style.top)<0)
//				thisObject.OBJ.style.top='0px';
		};
	} else { // ZoomOut
//alert(thisObject.CurrentWidth+' vs '+thisObject.TargetWidth);
		if (thisObject.CurrentWidth>thisObject.TargetWidth) {
			thisObject.CurrentWidth+=thisObject.ZoomWidthStepping;
			if (thisObject.CurrentWidth<0)
				thisObject.CurrentWidth=0;
			if (thisObject.OBJ.nodeName=='DIV')
				thisObject.OBJ.style.width=thisObject.CurrentWidth+'px';
			else	thisObject.OBJ.width=thisObject.CurrentWidth;
			DidSomething=true;
		};
		if (thisObject.CurrentHeight>thisObject.TargetHeight) {
			thisObject.CurrentHeight+=thisObject.ZoomHeightStepping;
			if (thisObject.CurrentHeight<0)
				thisObject.CurrentHeight=0;
			if (thisObject.OBJ.nodeName=='DIV')
				thisObject.OBJ.style.height=thisObject.CurrentHeight+'px';
			else	thisObject.OBJ.height=thisObject.CurrentHeight;
			DidSomething=true;
		};
	};
	if (!DidSomething) {
		clearInterval(thisObject.ZoomInterval);
		thisObject.ZoomIteration=0;
	};
};
TransitionManager.prototype.MoveEngine=function(OBJIndex) {
	var thisObject=this.TransitionOBJs[OBJIndex];
	thisObject.MoveIteration++;
	var DidSomething=false;
	if (thisObject.TargetLeft!=-1 && thisObject.Left!=thisObject.TargetLeft) {
		var NewLeft=thisObject.Left;
		if (thisObject.TargetLeft>thisObject.Left) {
			NewLeft=thisObject.Left+thisObject.MoveXStepping;
			if (NewLeft>thisObject.TargetLeft)
				NewLeft=thisObject.TargetLeft;
		} else {
			NewLeft=thisObject.Left-thisObject.MoveXStepping;
			if (NewLeft<thisObject.TargetLeft)
				NewLeft=thisObject.TargetLeft;
		};
		thisObject.Left=NewLeft;
		thisObject.OBJ.style.left=NewLeft+'px';
		DidSomething=true;
	};
	if (thisObject.TargetTop!=-1 && thisObject.Top!=thisObject.TargetTop) {
		var NewTop=thisObject.Top;
		if (thisObject.TargetTop>thisObject.Top) {
			NewTop=thisObject.Top+thisObject.MoveYStepping;
			if (NewTop>thisObject.TargetTop)
				NewTop=thisObject.TargetTop;
		} else {
			NewTop=thisObject.Top-thisObject.MoveYStepping;
			if (NewTop<thisObject.TargetTop)
				NewTop=thisObject.TargetTop;
		};
		thisObject.Top=NewTop;
		thisObject.OBJ.style.top=NewTop+'px';
		DidSomething=true;
	};
	if (!DidSomething) {
//		clearInterval(thisObject.MoveInterval);
		thisObject.StopMove();
		thisObject.MoveIteration=0;
	};
};
TransitionManager.prototype.ScrollEngine=function(OBJIndex) {
	var thisObject=this.TransitionOBJs[OBJIndex];
	thisObject.ScrollIteration++;
	var DidSomething=false;
	if (thisObject.ScrollLeft!=-1 && thisObject.ScrollLeft!=thisObject.TargetScrollLeft) {
		var NewLeft=thisObject.ScrollLeft;
		if (thisObject.TargetScrollLeft>thisObject.ScrollLeft) {
			NewLeft=thisObject.ScrollLeft+thisObject.ScrollXStepping;
			if (NewLeft>thisObject.TargetScrollLeft)
				NewLeft=thisObject.TargetScrollLeft;
		} else {
			NewLeft=thisObject.ScrollLeft-thisObject.ScrollXStepping;
			if (NewLeft<thisObject.TargetScrollLeft)
				NewLeft=thisObject.TargetScrollLeft;
		};
		thisObject.ScrollLeft=NewLeft;
		thisObject.OBJ.scrollLeft=NewLeft;
		DidSomething=true;
	};
	if (thisObject.ScrollTop!=-1 && thisObject.ScrollTop!=thisObject.TargetScrollTop) {
		var NewTop=thisObject.ScrollTop;
		if (thisObject.TargetScrollTop>thisObject.ScrollTop) {
			NewTop=thisObject.ScrollTop+thisObject.ScrollYStepping;
			if (NewTop>thisObject.TargetScrollTop)
				NewTop=thisObject.TargetScrollTop;
		} else {
			NewTop=thisObject.ScrollTop-thisObject.ScrollYStepping;
			if (NewTop<thisObject.TargetScrollTop)
				NewTop=thisObject.TargetScrollTop;
		};
		thisObject.ScrollTop=NewTop;
		thisObject.OBJ.scrollTop=NewTop;
		DidSomething=true;
	};
	if (!DidSomething) {
		thisObject.StopScroll();
		thisObject.ScrollIteration=0;
	};
};
TransitionManager.prototype.RotateEngine=function(OBJIndex) {
	var thisObject=this.TransitionOBJs[OBJIndex];
	if (thisObject.ImageCache[thisObject.RotateIndex]!=undefined) {
		TM.TransitionOBJs[OBJIndex].StartFade(0, 0.5);
		setTimeout('TM.RotateEngineChangeover('+OBJIndex+')', 600);
	} else {
		thisObject.ImageCache[thisObject.RotateIndex]=new Image();
		thisObject.ImageCache[thisObject.RotateIndex].onload=new Function('TM.TransitionOBJs['+OBJIndex+'].StartFade(0, 0.5); setTimeout("TM.RotateEngineChangeover('+OBJIndex+')", 600);');
		thisObject.ImageCache[thisObject.RotateIndex].src=thisObject.RotationImages[thisObject.RotateIndex];
	};
};
TransitionManager.prototype.RotateEngineChangeover=function(OBJIndex) {
	var thisObject=this.TransitionOBJs[OBJIndex];
	thisObject.OBJ.src=thisObject.RotationImages[thisObject.RotateIndex];
	thisObject.StartFade(1, 0.5);
	thisObject.RotateIndex=(thisObject.RotateIndex+1)%thisObject.RotationImages.length;
	thisObject.Timeout=setTimeout('TM.RotateEngine('+OBJIndex+')', thisObject.RotationInterval);
};
var TM=new TransitionManager();
TM.NoFade=false;

function TransitionOBJ(Element) {
	this.OBJ=Element;
	this.TMID=0;
};

var DefaultIterations=20;
var MinimumStepping=15;
TransitionOBJ.prototype.SetOpacity=function(OpacityOverride) {
	var TargetOpacity=OpacityOverride!=undefined?OpacityOverride:this.CurrentOpacity;
	if (TargetOpacity<0)
		TargetOpacity=0;
	else if (TargetOpacity>1)
		TargetOpacity=1;
	if (BrowserIE)
		this.OBJ.style.filter='alpha(opacity='+TargetOpacity*100+')';
	else	this.OBJ.style.opacity=TargetOpacity;
	this.CurrentOpacity=TargetOpacity;
};
TransitionOBJ.prototype.StartFade=function(InOut, Seconds, Iterations, Delay, Callback) {
//	this.CurrentOpacity=InOut?0:this.CurrentOpacity;
	if (this.CurrentOpacity==undefined)
		this.CurrentOpacity=1;
//	alert(this.OBJ.id+' - Starting fade '+InOut+', current '+this.CurrentOpacity);
	if (BrowserIE && TM.NoFade) {
		SetOpacity(this.OBJ, InOut);
		return;
	};
	if (Delay!=undefined && Delay>0) {
		setTimeout('TM.TransitionOBJs['+this.TMID+'].StartFade('+InOut+', '+Seconds+', '+Iterations+');', Delay*1000);
		return;
	};
//debug(this.OBJ.id+InOut);
	clearInterval(this.Interval);
	this.Iteration=0;
	this.FadeInOut=InOut;
//	this.SetOpacity();
	this.FadeSeconds=Seconds;
	this.FadeIterations=Iterations!=undefined && !isNaN(Iterations)?Iterations:DefaultIterations;
	this.FadeStepping=Math.round(Seconds*1000/this.FadeIterations);
	if (this.FadeStepping<MinimumStepping) {
		this.FadeStepping=MinimumStepping;
		this.FadeIterations=Seconds*1000/this.FadeStepping;
	};
	this.FadeOpacityStepping=Math.round(1/this.FadeIterations*100)/100;
	this.Interval=setInterval('TM.FadeEngine('+this.OBJ.TMID+')', this.FadeStepping);
//	TM.FadeEngine(this.OBJ.TMID, this.FadeStepping);
	if (Callback!=undefined)
		this.Callback=Callback;
	else	this.Callback=false;
};
TransitionOBJ.prototype.Blink=function(Seconds, Iterations) {
	this.FadeBlink=true;
	this.StartFade(this.CurrentOpacity==0?1:0, Seconds, Iterations);
};
TransitionOBJ.prototype.StopTransition=function() {
	clearInterval(this.Interval);
};
TransitionOBJ.prototype.StopBlink=function(FinalInOut) {
	this.FadeBlink=false;
	this.FadeInOut=FinalInOut;
};
TransitionOBJ.prototype.StartZoom=function(InOut, Seconds, TargetWidth, TargetHeight, CompensateTop, CompensateLeft, Iterations) {
	this.ZoomIteration=0;
	this.ZoomInOut=InOut;
	this.ZoomSeconds=Seconds;
	this.TargetWidth=TargetWidth;
	this.TargetHeight=TargetHeight;
	this.CompensateTop=CompensateTop!=undefined?CompensateTop:false;
	this.CompensateLeft=CompensateLeft!=undefined?CompensateLeft:false;
	this.ZoomIterations=Iterations!=undefined && !isNaN(Iterations)?Iterations:DefaultIterations;
	this.ZoomStepping=Math.round(Seconds*1000/this.ZoomIterations);
	if (this.ZoomStepping<MinimumStepping) {
		this.ZoomStepping=MinimumStepping;
		this.ZoomIterations=Seconds*1000/this.ZoomStepping;
	};
	this.ZoomPercentageStepping=Math.round(1/this.ZoomIterations*100)/100;
	this.CurrentWidth=parseInt(this.OBJ.width);
	if (isNaN(this.CurrentWidth))
		this.CurrentWidth=parseInt(this.OBJ.style.width);
	if (isNaN(this.CurrentWidth))
		this.CurrentWidth=parseInt(this.OBJ.offsetWidth);
	this.CurrentHeight=parseInt(this.OBJ.height);
	if (isNaN(this.CurrentHeight))
		this.CurrentHeight=parseInt(this.OBJ.style.height);
	if (isNaN(this.CurrentHeight))
		this.CurrentHeight=parseInt(this.OBJ.offsetHeight);
	this.ZoomWidthStepping=Math.round((TargetWidth-this.CurrentWidth)/this.ZoomIterations);
	this.ZoomHeightStepping=Math.round((TargetHeight-this.CurrentHeight)/this.ZoomIterations);
	this.ZoomInterval=setInterval('TM.ZoomEngine('+this.OBJ.TMID+')', this.ZoomStepping);
	this.Left=this.OBJ.offsetLeft;
	this.Top=this.OBJ.offsetTop;
	this.OBJ.style.position='absolute';
	this.ZoomMovementOffset=0;
};
TransitionOBJ.prototype.IsVisible=function() {
	if (BrowserIE && TM.NoFade)
		return this.OBJ.style.visibility!='hidden';
	return this.CurrentOpacity!=undefined?this.CurrentOpacity>=1:(this.OBJ.style.visibility!='hidden');
};
TransitionOBJ.prototype.StartMove=function(NewLeft, NewTop, Seconds, Iterations) {
	this.MoveIteration=0;
	this.MoveSeconds=Seconds;
	this.MoveIterations=Iterations!=undefined && !isNaN(Iterations)?Iterations:DefaultIterations;
	this.MoveStepping=Math.round(Seconds*1000/this.MoveIterations);
	if (BrowserIE && TM.NoFade) {
		this.MoveStepping=1;
		this.MoveIterations=1;
	} else if (this.MoveStepping<MinimumStepping) {
		this.MoveStepping=MinimumStepping;
		this.MoveIterations=Seconds*1000/this.MoveStepping;
	};
	this.Left=this.OBJ.offsetLeft;
	this.Top=this.OBJ.offsetTop;
	this.PreviousLeft=this.Left;
	this.PreviousTop=this.Top;
	this.TargetLeft=NewLeft;
	this.TargetTop=NewTop;
	this.MoveXStepping=Math.ceil(Math.abs(NewLeft-this.Left)/this.MoveIterations);
	this.MoveYStepping=Math.ceil(Math.abs(NewTop-this.Top)/this.MoveIterations);
	this.MoveInterval=setInterval('TM.MoveEngine('+this.OBJ.TMID+')', this.MoveStepping);
};
TransitionOBJ.prototype.StartScroll=function(NewScrollLeft, NewScrollTop, Seconds, Iterations) {
	this.ScrollIteration=0;
	this.ScrollSeconds=Seconds;
	this.ScrollIterations=Iterations!=undefined && !isNaN(Iterations)?Iterations:DefaultIterations;
	this.ScrollStepping=Math.round(Seconds*1000/this.ScrollIterations);
	if (BrowserIE || TM.NoFade) {
		this.ScrollStepping=1;
		this.ScrollIterations=1;
	} else if (this.ScrollStepping<MinimumStepping) {
		this.ScrollStepping=MinimumStepping;
		this.ScrollIterations=Seconds*1000/this.ScrollStepping;
	};
	this.ScrollLeft=this.OBJ.scrollLeft;
	this.ScrollTop=this.OBJ.scrollTop;
	this.PreviousScrollLeft=this.ScrollLeft;
	this.PreviousScrollTop=this.ScrollTop;
	this.TargetScrollLeft=NewScrollLeft;
	this.TargetScrollTop=NewScrollTop;
	this.ScrollXStepping=Math.ceil(Math.abs(NewScrollLeft-this.ScrollLeft)/this.ScrollIterations);
	this.ScrollYStepping=Math.ceil(Math.abs(NewScrollTop-this.ScrollTop)/this.ScrollIterations);
	this.ScrollInterval=setInterval('TM.ScrollEngine('+this.OBJ.TMID+')', this.ScrollStepping);
};
TransitionOBJ.prototype.MoveBack=function(Seconds, Iterations) {
	this.StartMove(this.PreviousLeft, this.PreviousTop, Seconds, Iterations);
};
TransitionOBJ.prototype.ScrollBack=function(Seconds, Iterations) {
	this.StartScroll(this.PreviousScrollLeft, this.PreviousScrollTop, Seconds, Iterations);
};
TransitionOBJ.prototype.StopMove=function() {
	clearInterval(this.MoveInterval);
};
TransitionOBJ.prototype.StopScroll=function() {
	clearInterval(this.ScrollInterval);
};
TransitionOBJ.prototype.Hide=function() {
	this.prevDisplay=this.OBJ.style.display!=undefined?this.OBJ.style.display:'';
	this.OBJ.style.display='none';
};
TransitionOBJ.prototype.Show=function() {
	if (this.prevDisplay!=undefined)
		this.OBJ.style.display=this.prevDisplay;
};
TransitionOBJ.prototype.StartRotate=function(Images, Interval) {
	if (Images!=undefined) {
		this.RotationImages=Images;
		this.ImageCache=new Array();
	};
	if (Interval!=undefined)
		this.RotationInterval=Interval;
	this.RotateIndex=0;
	TM.RotateEngine(this.OBJ.TMID);
};
TransitionOBJ.prototype.StopRotate=function() {
	window.clearTimeout(this.Timeout);
};

function SetOpacity(Element, TargetOpacity) {
	TargetOpacity=Math.round(parseFloat(TargetOpacity)*100)/100;
	if (TargetOpacity<0)
		TargetOpacity=0;
	else if (TargetOpacity>1)
		TargetOpacity=0.99;
	var TargetVisibility='visible';
	if (TargetOpacity==0)
		TargetVisibility='hidden';
//	Element.style.visibility=TargetVisibility;
	if (BrowserIE) {
		if (!TM.NoFade || TM.Debug==1)
			Element.style.filter='alpha(opacity='+TargetOpacity*100+')';
if (TM.Debug==1) {
//alert(Element);
}
	} else
		Element.style.opacity=TargetOpacity;
};


