function d2h(dec) { 
	  return dec.toString(16);
}
function h2d(hex) { 
	   return parseInt(hex,16);
}
function rgb2h(r,g,b) { 
		 return [d2h(r),d2h(g),d2h(b)];
}
function h2rgb(h,e,x) {
		return [h2d(h),h2d(e),h2d(x)];
}
function cssColor2rgb(color) {
	if(color.indexOf('rgb')<=-1) {
		return h2rgb(color.substring(1,3),color.substring(3,5),color.substring(5,7));
	}
	return color.substring(4,color.length-1).split(',');
}

function animateColor(elm,begin,end, duration, fps) {

  if(!duration) duration = 1000;
  if(!fps) fps = 20;
  duration=parseFloat(duration);
  fps=parseFloat(fps);
  var interval    = Math.ceil(1000/fps);
  var totalframes = Math.ceil(duration/interval);

  for(i=1;i <= totalframes;i++) {
		   (function() {
				var frame=i;
				var b = cssColor2rgb(begin);
				var e  = cssColor2rgb(end);
				var change0=e[0]-b[0];
				var change1=e[1]-b[1];
				var change2=e[2]-b[2];

				function color() {
					var increase0=ease(frame, b[0], change0, totalframes);
					var increase1=ease(frame, b[1], change1, totalframes);
					var increase2=ease(frame, b[2], change2, totalframes);

				elm.style['backgroundColor']  = 'rgb('+parseInt(increase0)+','+parseInt(increase1)+','+parseInt(increase2)+')';
				
				/*
				jQuery("#menu a:hover ins").css("background-color", "yellow");
				jQuery("#menu li:hover ins").css("background-color", "yellow");
				jQuery("#menu li.col").css("background-color", "yellow");
				*/
		  }
		  timer = setTimeout(color,interval*frame);
	 })(); 
 }
}
function ease(frame,begin,change,totalframes) {
	   return begin+change*(frame/totalframes);
}

var previousColor="#d0e8ec";

function changeBG(color)
{
	animateColor(document.body,previousColor,color,500);
	previousColor=color;
}

