/*PDATA
	compress = yes
PDATA*/

function TLogoAnim()
{
	if(gId('tlogo'))
		new Tween('tlogo').manip('OUT2:0-1/1', [gId('tlogo'),'style.opacity']);
}

function Tween(name, fps)
{
	if( name == undefined )
		var name = "_"+Tween.prototype.next_uid++;

	if( !Tween.prototype.instances[name] )
	{
		if( (this.constructor != Object) || (this == window) )
			return false;

		initClassInstance(Tween.prototype, this, "timer,callback,p1,p2,d,type,e,param,s,manip_data");
		this.name = name;

		if( fps )
			this.fps = fps
		else
			this.fps = 30;

		Tween.prototype.instances[name] = this;
	}

	return Tween.prototype.instances[name];
}

Tween.prototype = 
{
	instances	: {},
	next_uid	: 1,
	timer		: null,
	name		: "",
	callback	: [],
	p1			: 0,
	p2			: 1,
	d			: 1,
	type		: 'no',
	e			: 1,
	param		: {},
	s			: 1,
	fps			: 30,
	manip_data	: {},

	getPos : function(t)
	{
		switch(this.type)
		{
			case 'IN'	: return this.p1+Math.pow(t/this.d, this.e)*this.s;
			case 'OUT'	: return this.p1-Math.pow(1-t/this.d, this.e)*this.s;
			default		: return this.p1+t/this.d*this.s;
		}
	},

	tweenProc : function()
	{
		var t = getTime() - this.t0;

		if( t >= this.d )
		{
			this.callback[0][this.callback[1]](this.p2, this.param);
			delete Tween.prototype.instances[this.name];
		}
		else
		{
			this.callback[0][this.callback[1]](this.getPos(t), this.param);
			this.timer = setTimeout("try{Tween('"+this.name+"').tweenProc()}catch(e){}",Math.round(1000/this.fps));
		}
	},

	// tween	: eg. IN1:1-10/0.3
	// callback : [obj, method]
	// param	: mixed
	start : function( tween, callback, param)
	{
		var tween		= tween.split(':');
		var dim			= tween[1].split('/');

		this.callback	= callback;
		this.param		= param;
		this.p1			= parseFloat(dim[0].split('-')[0]);
		this.p2			= parseFloat(dim[0].split('-')[1]);
		this.d			= parseFloat(dim[1])*1000;
		this.type		= tween[0].replace(/[0-9]/g,'').toUpperCase();
		this.e			= parseFloat(tween[0].replace(/[^0-9]/g,''));
		this.s			= this.p2-this.p1;
		this.t0			= getTime();

		if( this.type == 'OUT' )
			this.p1 = this.p2;

		if( this.timer )
			clearTimeout(this.timer);

		this.timer = setTimeout("try{Tween('"+this.name+"').tweenProc()}catch(e){}",Math.round(1000/this.fps));

		return this.name;
	},

	stop: function()
	{
		if( this.timer )
			clearTimeout(this.timer);

		this.timer = null;

		delete Tween.prototype.instances[this.name];
	},

	getAsRGB: function(c)
	{
		var n=c >> 8;
		return {r:n >> 8,g:n%256,b:c%256};
	},

	RGBPos: function(c1, c2, p)
	{
		var c1 = this.getAsRGB(c1);
		var c2 = this.getAsRGB(c2);

		var r = (c1.r+Math.floor((c2.r-c1.r)*p)).toString(16);
		var g = (c1.g+Math.floor((c2.g-c1.g)*p)).toString(16);
		var b = (c1.b+Math.floor((c2.b-c1.b)*p)).toString(16);

		r = pad_left(r, "0", 2);
		g = pad_left(g, "0", 2);
		b = pad_left(b, "0", 2);

		return "#"+r+g+b;
	},

	manipProc : function(p, _param)
	{
		var trg = this.manip_data.target;

		if( trg[2] )
		{
			if( trg[2] == "rgb" )
				var p = this.RGBPos(this.manip_data.c1, this.manip_data.c2, p);
			else
				var p = trg[2].replace('%%', p);
		}

		if( trg[1] == 'style.opacity' )
		{
			try{trg[0].style.opacity = p;}catch(e){};
			try{trg[0].style.MozOpacity = p;}catch(e){};
			if( isMSIE() )
				{try{trg[0].style.filter = "alpha(opacity="+Math.round(p*100)+")";}catch(e){};}
		}
		else
			eval("trg[0]."+trg[1]+"=p");

		var t = getTime() - this.t0;
		if( t >= this.d )
		{
			if( this.manip_data.callback )
			{
				var cb = this.manip_data.callback;
				cb[0][cb[1]](this.manip_data.param);
			}
		}
	},

	manip : function( tween, target, callback, param )
	{
		this.manip_data = {target: target, callback: false, param: {}};
		if( param )
			this.manip_data.param = param;
		if( callback )
			this.manip_data.callback = callback;

		if( target[2] && (target[2] == "rgb" ) )
		{
			var tween		= tween.split(':');
			var dim			= tween[1].split('/');

			this.manip_data.c1	= parseInt(dim[0].split('-')[0].replace("#",''),16);
			this.manip_data.c2	= parseInt(dim[0].split('-')[1].replace("#",''),16);
	
			tween = tween[0]+":0-1/"+dim[1];
		}

		this.start(tween, [this, "manipProc"] );
	}
}