<?php require_once('main_js.php'); ?>
/*
* Like HTML em unit - but it's my own .... ef .. for flickaway.
*
* The main use is to detect when a user changes the font-size and be able to update the board shadow etc.
* By providing an event to do so.
*
* @copyright 2006 flickaway.com
* @version   $Id: ef.js 2045 2009-05-12 06:57:05Z glen $
*/


EF = function()
{
  this.e_name   = "ef_embed";
  this.embedded = 0;
  this.started  = 0;
  this.listener = null;
  this.l_obj    = null;

  this.interval       = null;
  this.interval_delay = 200;

  this.value = null;
}

p = EF.prototype;


EF.prototype.gimme_ef = function(x)
{
  return x * this.value;
}


EF.prototype.gimme_ef_unit = function()
{
  return this.value;
}


EF.prototype.embed = function()
{
  document.write('<span style="position: absolute; left: -9999px;" id="' + this.e_name + '">m&nbsp;</span>');
  this.embedded = 1;
  if (this.started)
  {
    this.start_detect();
  }

  this.value = $GE(this.e_name).offsetWidth;
}


EF.prototype.set_listener = function(listener, l_obj)
{
  this.listener = listener;

  if (l_obj == 'undefined' || l_obj == null)
  {
    this.l_obj = this;
  }
  else
  {
    this.l_obj = l_obj;
  }
}


EF.prototype.start_detect = function()
{
  this.started = 1;           // this is used to handle the case when start_detect() is called before it is embedded

  if (this.interval)          // it's already running
    return;

  if (!this.embedded)         // not embedded yet - so wait until it does
    return

  var me = this;
  var e = $GE(this.e_name);
  var cur_size = e.offsetWidth;

  function on_interval()
  {
    var new_size = e.offsetWidth;
    if (new_size != cur_size)
    {
      cur_size = new_size;
      me.value = new_size;
      me.listener.call(me.l_obj, new_size);
    }
  }

  this.interval = setInterval(on_interval, this.interval_delay);
}


EF.prototype.stop_detect = function()
{
  this.started = 0;
  clearInterval(this.interval);
  this.interval = null;
}


g_ef = new EF();

