// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

  function make_hex (r,g,b)
  {
    r = r.toString(16); if (r.length == 1) r = '0' + r;
    g = g.toString(16); if (g.length == 1) g = '0' + g;
    b = b.toString(16); if (b.length == 1) b = '0' + b;
    return "#" + r + g + b;
  }

  function fade_element (id, fps, duration, from, to)
  {
    if (id == "entry1" || id == "entry2" || id == "entry3")  {
      width  = 300;
      height = 50;
    } else  {
    	var obj = document.getElementById (id);
      width   = getObjectWidth  (obj);
      height  = getObjectHeight (obj);
    }
    
    if (!fps) fps = 30;
    if (!duration) duration = 3000;
    if (!from || from=="#") from = "#FFFF33";
    if (!to) to = this.get_bgcolor(id);

    var frames = Math.round(fps * (duration / 1000));
    var interval = duration / frames;
    var delay = interval;
    var frame = 0;

    if (from.length < 7) from += from.substr(1,3);
    if (to.length < 7) to += to.substr(1,3);

    var rf = parseInt(from.substr(1,2),16);
    var gf = parseInt(from.substr(3,2),16);
    var bf = parseInt(from.substr(5,2),16);
    var rt = parseInt(to.substr(1,2),16);
    var gt = parseInt(to.substr(3,2),16);
    var bt = parseInt(to.substr(5,2),16);

    var r,g,b,h;
    while (frame < frames)
    {
      r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
      g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
      b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
      h = make_hex(r,g,b);

//      setTimeout("move_entry('"+id+"',null,null)", delay);
      setTimeout("centerOnWindow('"+id+"',true)", delay);
      setTimeout("set_bgcolor('"+id+"','"+h+"')", delay);

      frame++;
      delay = interval * frame;
//      setTimeout("set_bgcolor('"+id+"','"+to+"')", delay);

    }
  }

  function set_bgcolor (id, c)
  {
    var o = document.getElementById(id);
    o.style.backgroundColor = c;
  }

  function get_bgcolor (id)
  {
    var o = document.getElementById(id);
    while(o)
    {
      var c;
      if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
      if (o.currentStyle) c = o.currentStyle.backgroundColor;
      if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
      o = o.parentNode;
    }
    if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
    var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
    if (rgb) c = make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
    return c;
  }
/*
function move_entry (id, width, height)  {
  var screen_x, screen_y;
  if (window.screenTop)  {
    screen_x = window.screenLeft;
    screen_y = window.screenTop;
  } else if (window.innerHeight)  {
    screen_x = screen.width - window.innerWidth;
    screen_y = screen.height - window.innerHeight;
  } else  {
    screen_x = 0;
    screen_y = 0;
  }

  var scroll_x, scroll_y;
  if (window.pageXOffset)
    scroll_x = window.pageXOffset;
  else if (window.document.documentElement.scrollLeft)
    scroll_x = document.documentElement.scrollLeft;
  else if (window.document.body.scrollLeft)
    scroll_X = document.body.scrollLeft;
  else
    scroll_x = 0;

  if (window.pageYOffset)
    scroll_y = window.pageYOffset;
  else if (window.document.documentElement.scrollTop)
    scroll_y = document.documentElement.scrollTop;
  else if (window.document.body.scrollTop)
    scroll_y = document.body.scrollTop;
  else
    scroll_y = 0;

	var o = document.getElementById (id);
  if (id == "entry2")  {
	  o.style.left = Math.floor (scroll_x + (document.body.clientWidth - 300) / 2) + "px";
    o.style.top  = Math.floor (scroll_y + (document.body.clientHeight - 50) / 2) + "px";
	} else if (id == "entry1" || id == "entry3")  {
	  o.style.left = Math.floor (scroll_x + (screen.width - screen_x - 300) / 2) + "px";
    o.style.top  = Math.floor (scroll_y + (screen.height - screen_y - 50) / 2 - 24) + "px";
  } else  {
    var width  = iframeWidth  (id, width);
	  var height = iframeHeight (id, height);
	  o.style.left = Math.floor (scroll_x + (screen.width  - screen_x - width) / 2) + "px";
    o.style.top  = Math.floor (scroll_y + (screen.height - screen_y - height)/ 2 - 24) + "px";
  }
}
*/

