function Opacity(o, v) {
	if(v<=100)
	{
		if(o.style.MozOpacity!=null){
			o.style.MozOpacity = (v/100)-.001;
		}else if(o.style.opacity!=null){
			o.style.opacity = (v/100);
		}else if(o.style.filter!=null){
			o.style.filter = "alpha(opacity="+v+")";
		}
	}
}




var Animation = {
	$:[],

	Play: function(o,p,c,cp){
		var id,i,e,g;

		id = Animation.$.length;

		g={o:o,p:p,c:c,n:0,cp:cp};

		for(i in g.p)
		{
			e = g.p[i];
			if(e)
			{
				if(e.effect)
				{
					g.n++;

					if(e.effect.Init)
					{
						g.p[i] = e.effect.Init(o,e);
					}

					if(!g.p[i])
					{
						g.n--;
					}
				}
			}
		}


		for(i in g.p)
		{
			e = g.p[i];
			if(e)
			{
				if(e.effect)
				{
					if(e.delay)
					{
						g.p[i] = e.effect.Step(o,e);
						if(g.p[i])
						{
							setTimeout('Animation.Step('+id+','+i+')', e.delay);
						}
					}
				}
			}
		}

		Animation.$[id] = g;

		if(g.n==0)
		{
			Animation.End(id);
		}

		return id;
	},

	Step: function(id,i){
		var g = Animation.$[id];

		g.p[i] = g.p[i].effect.Step(g.o,g.p[i]);
		if(g.p[i])
		{
			setTimeout('Animation.Step('+id+','+i+')', g.p[i].delay);
		}else{
			g.n--;
		}

		if(g.n==0)
		{
			Animation.End(id);
		}
	},

	End: function(id){
		var g = Animation.$[id];
		if(typeof g.c == 'function')
		{
			g.c(g.cp);
		}
	}
}



var Effects = {

	Squish: {
		Init: function(o,p)
		{
			o.style.overflow = 'hidden';
			return p;
		},

		Step: function(o,p)
		{
			var h = o.clientHeight, w = o.clientWidth;
			if(h > 0)
			{
				o.style.height = Math.max(h-p.step,0)+'px';
			}
			if(w > 0)
			{
				o.style.width = Math.max(w-p.step,0)+'px';
			}
			if(h>0 || w>0)
			{
				return p;
			}

			return null;
		}
	},


	FadeOut: {
		Init: function(o,p){
			p.opacity = 100;
			return p;
		},


		Step: function(o,p){

			Opacity(o, p.opacity);

			p.opacity -= p.step;

			if(p.opacity >= 0)
			{
				return p;
			}
			return null;
		}
	},



	FadeIn: {
		Init: function(o,p){
			p.opacity = 0;
			return p;
		},


		Step: function(o,p){

			Opacity(o, p.opacity);

			p.opacity += p.step;

			if(p.opacity <= 100)
			{
				return p;
			}

			Opacity(o, 100);
			return null;
		}
	},



	SlideUp: {
		Init: function(o,p){
			o.style.overflow = 'hidden';
			return p;
		},

		Step: function(o,p){
			var h, w, h1, step;

			h = Math.max(o.offsetHeight, o.clientHeight);
			w = o.offsetWidth;

			if(h > 0)
			{
				o.style.height = Math.max(h-p.step,0)+'px';
			}
			if(h>0)
			{
				return p;
			}

			o.style.display = 'none';
			return false;
		}
	},


	SlideOut: {
		Init: function(o,p){
			o.style.display = '';
			return p;
		},

		Step: function(o,p){
			var x, y, h = Math.max(o.offsetHeight,o.clientHeight), w = o.offsetWidth;

			y = Math.min(h+p.step,p.height);
			x = Math.min(w+p.step,p.width);


			if(h < p.height)
			{
				o.style.height = y+'px';
			}


			if(w < p.width)
			{
				o.style.width = x+'px';
			}

			if(y<p.height || x<p.width)
			{
				return p;
			}


			o.style.height = '';
			return false;
		}
	},


	BackOut: {
		Init: function(o,p){
			o.style.display = '';
			p.phase = 1;
			p.height += p.step*2;
			p.width += p.step*2;
			return p;
		},

		Step: function(o,p){
			var x, y, h = o.clientHeight, w = o.clientWidth;


			switch(p.phase)
			{
				case 1:
					p1 = Effects.SlideOut.Step(o,p);
					if(!p1)
					{
						p.phase = 2;
						p.height -= p.step*2;
						p.width -= p.step*2;
					}else{
						p = p1;
					}
					break;

				case 2:
					y = Math.max(h-p.step/4,p.height);
					x = Math.max(w-p.step/4,p.width);

					o.style.height = y+'px';
					o.style.width = x+'px';

					if(y==p.height && x==p.width)
					{
						return null;
					}

					break;
			}

			return p;
		}
	},


	Move: {
		Init: function(o,p){
			if(p.dx)
			{
				p.x = o.offsetLeft + p.dx;
			}
			if(p.dy)
			{
				p.y = o.offsetTop + p.dy;
			}

			p.xd=p.yd=1;

			if(p.x)
			{
				if(p.x < o.offsetLeft)
				{
					p.xd=-1;
				}
			}

			if(p.y)
			{
				if(p.y < o.offsetTop)
				{
					p.yd=-1;
				}
			}
			return p;
		},

		Step: function(o,p){
			var x,y,b=false;

			if(p.x)
			{
				x = o.offsetLeft+p.step*p.xd;
				x = p.xd>0 ? Math.min(x,p.x) : Math.max(x,p.x);
				o.style.left = x+'px';

				if(x!=p.x)
				{
					b=true;
				}
			}

			if(p.y)
			{
				y = o.offsetTop+p.step*p.yd;
				y = p.yd>0 ? Math.min(y,p.y) : Math.max(y,p.y);
				o.style.top = y+'px';

				if(y!=p.y)
				{
					b=true;
				}
			}
			return b?p:null;
		}
	},


	Expand: {
		Init: function(o,p){
			o.style.overflow = 'hidden';
			o.style.height = 0;
			return p;
		},

		Step: function(o,p){
			if(o.offsetHeight < p.height)
			{
//				o.style.marginTop = Math.min(o.offsetHeight - p.height)+'px';
				o.style.height = Math.min(p.height, o.offsetHeight + p.step)+'px';
				return p;
			}
			return false;
		}
	},


	Collapse: {
		Init: function(o,p){
			o.style.overflow = 'hidden';
			o.style.height = p.height+'px';
			return p;
		},

		Step: function(o,p){
			var y = o.offsetHeight;

			if(y > 0)
			{
				o.style.height = Math.max(0, o.offsetHeight - p.step)+'px';

				if(y == o.offsetHeight)
				{
					return false;
				}else{
					return p;
				}
			}
			return false;
		}
	},

	Dummy: {
		Init: function(o,p){return p},
		Step: function(o,p){return p}
	}
}

