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.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;
	};

};
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.CompensateTopLeft) {
				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.CompensateTopLeft) {
				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;
	};
};
var TM=new TransitionManager();
TM.NoFade=false;

function TransitionOBJ(Element) {
	this.OBJ=Element;
	this.TMID=0;
};

var DefaultIterations=50;
var MinimumStepping=30;
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) {
//	this.CurrentOpacity=InOut?0:this.CurrentOpacity;
//	alert(this.OBJ.id+' - Starting fade '+InOut+', current '+this.CurrentOpacity);
	if (BrowserIE && TM.NoFade) {
		SetOpacity(this.OBJ, InOut);
		return;
	};
	if (Delay!=undefined) {
		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);
};
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, CompensateTopLeft, Iterations) {
	this.ZoomIteration=0;
	this.ZoomInOut=InOut;
	this.ZoomSeconds=Seconds;
	this.TargetWidth=TargetWidth;
	this.TargetHeight=TargetHeight;
	this.CompensateTopLeft=CompensateTopLeft!=undefined?CompensateTopLeft: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.MoveBack=function(Seconds, Iterations) {
	this.StartMove(this.PreviousLeft, this.PreviousTop, Seconds, Iterations);
};
TransitionOBJ.prototype.StopMove=function() {
	clearInterval(this.MoveInterval);
};

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;
};

