var out_to = false;
var state = 0;

function blend_in_timer() {
  var obj = document.getElementById('content');

  if (!!obj && state == 1) {
    move(obj.style,'opacity',.7,1,'',100);
    state = 0;
  }
}

function blend_out() {
  if (!!out_to)
    window.clearTimeout(out_to);

  var obj = document.getElementById('content');

  if (!!obj && state == 0) {
    move(obj.style,'opacity',1,.7,'',100);
    state = 1;
  }

}

function blend_in() {
  if (!!out_to)
    window.clearTimeout(out_to);
    
  out_to = window.setTimeout("blend_in_timer();",50);
}

var move_in_progress = new Object();

function move(obj, param, from, to, unit, duration) {

  var floor = true;

  if (move_in_progress[param]) return;
  move_in_progress[param] = true;

  obj[param] = from+unit;

  var time_start = (new Date()).getTime();
  var val = to-from;
  
  //if (Math.abs(from)<1 && Math.abs(from)>0) floor = false;
  floor = false;
  
  function go_move() {
    var time_elapsed = (new Date()).getTime() - time_start;
    
    if (time_elapsed < duration) {
      setTimeout(go_move,1);
      step = val*(Math.sin( (Math.PI/(duration*2))*time_elapsed ));
      if (floor) step = Math.floor(step);
      obj[param] = (from + step)+unit;

    } else {
      move_in_progress[param] = false;
      obj[param] = to+unit;
    }


  }

  setTimeout(go_move,1);
}

