var colorFade=function(){
	return{
		init:function(id,element,start,end,steps,speed) {
			var srgb,ergb,er,eg,eb,step,rint,gint,bint;
			t=document.getElementById(id);
			steps=steps||20; speed=speed||20;
			clearInterval(t.timer);
			ergb=conv(end);
			er=ergb[0]; eg=ergb[1]; eb=ergb[2];
			if(!t.r){
				srgb=colorConv(start);
				r=srgb[0]; g=srgb[1]; b=srgb[2];
				t.r=r; t.g=g; t.b=b;
			}
			rint=Math.round(Math.abs(t.r-er)/steps);
			gint=Math.round(Math.abs(t.g-eg)/steps);
			bint=Math.round(Math.abs(t.b-eb)/steps);
			if(rint==0){rint=1}
			if(gint==0){gint=1}
			if(bint==0){bint=1}
			t.step=1;
			t.timer=setInterval(function(){animate(id,el,steps,er,eg,eb,rint,gint,bint)},speed);
		},
		animate:function(id,el,steps,er,eg,eb,rint,gint,bint){
		  var t=document.getElementById(id); var color;
		  if(t.step<=steps){
		    var r,g,b; r=t.r; g=t.g; b=t.b;
			r=(r>=er)?(r-int):(parseInt(r)+parseInt(rint))
			g=(g>=eg)?(g-gint):(parseInt(g)+parseInt(gint))
			b=(b>=eb)?(b-bint):(parseInt(b)+parseInt(bint))
			color='rgb('+r+','+g+','+b+')';
			if(el=='background'){
			  t.style.backgroundColor=color;
			}else if(el=='border'){
			  t.style.borderColor=color;
			}else{t.style.color=color}
			t.r=r; t.g=g; t.b=b; t.step=t.step+1;
		  }else{
			clearInterval(t.timer);
			color='rgb('+er+','+eg+','+eb+')';
			if(el=='background'){
			  t.style.backgroundColor=color;
			}else if(el=='border'){
			  t.style.borderColor=color;
			}else{t.style.color=color}
		  }
		},
		conv:function(color){
		  var rgb=[parseInt(color.substring(0,2),16), parseInt(color.substring(2,4),16), parseInt(color.substring(4,6),16)];
		  return rgb;
		}
	}
}();
