logWindow = null;
function LOG(msg) {
//  if (logWindow==null) {
//    logWindow = open('', 'logWindow',
//             'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,'+
//             'resizable=0,width=300,height=200,dependent=1');
//  }
//  logWindow.document.write(msg+'<br />\n');
}
//
//
//
  var tile = Array();
  function tile_dimensions(ar) {
    this.w  = ar[0];      // tile width
    this.h  = ar[1];      // tile height
    this.ml = ar[2];      // tile margin left
    this.mt = ar[3];      // tile margin top
  }
//
  function menutile(me,sm,lg) {
    this.me = me;
    this.iterations = 30;
    this.count = 0;
    this.cur   = new tile_dimensions(sm);
    this.large = new tile_dimensions(lg);
    this.small = new tile_dimensions(sm);
    this.off   = new tile_dimensions(Array(
        (this.large.w - this.small.w) / this.iterations,
        (this.large.h - this.small.h) / this.iterations,
        (this.large.ml - this.small.ml) / this.iterations,
        (this.large.mt - this.small.mt) / this.iterations
    ));
    this.timer = null;

    this.layer = getLyr(me);
    this.image = getSty(me+'-img');
    this.layer.w(this.cur.w);  this.image.width = this.cur.w+'px';
    this.layer.h(this.cur.h);  this.image.height = this.cur.h+'px';
    this.layer.sty.marginLeft = this.cur.ml+'px';
    this.layer.sty.marginTop = this.cur.mt+'px';

    if (getSty(me+'Root')) {
      eval("if ("+me+") "+me+".activateMenu('"+me+"'+'Root', null);");
    }

    var doExpand = new Function('e',
            'var sty;'+
            'if (sty=getSty("'+me+'Root")) {'+
            'if (!isMouseLeaveOrEnter(e,this)) return;}'+
            'tile["'+me+'"].expandTile();'
    );
    var doShrink = new Function('e',
            'var sty;'+
            'if (sty=getSty("'+me+'Root")) {'+
            'if (!isMouseLeaveOrEnter(e,this)) return;'+
            'sty.visibility="hidden";}'+
            'clearInterval(tile["'+me+'"].timer);'+
            'tile["'+me+'"].timer = null;'+
            'tile["'+me+'"].shrinkTile();'
    );

    addEvent(this.layer.ref, 'mouseover', doExpand);
    addEvent(this.layer.ref, 'mouseout', doShrink);
  }
//
  menutile.prototype.expandTile = function() { with (this) {
    var newW,tmpW,newH,tmpH,newML,tmpML,newMT,tmpMT;
    if (!this.timer) {
      clearInterval(this.timer);
      this.timer = setInterval('tile["'+this.me+'"].expandTile()', 50);
      this.count = 0;
      newW = tmpW = this.cur.w;
      newH = tmpH = this.cur.h;
      newML = tmpML = this.cur.ml;
      newMT = tmpMT = this.cur.mt;
    } else {
      this.count++;
      newW = Math.round(tmpW = this.cur.w + this.off.w);
      newH = Math.round(tmpH = this.cur.h + this.off.h);
      newML = Math.round(tmpML = this.cur.ml + this.off.ml);
      newMT = Math.round(tmpMT = this.cur.mt + this.off.mt);
      if (this.count==this.iterations) {
        clearInterval(this.timer);
        this.timer = null;
        var sty = getSty(this.me+'Root');
        if (sty)    sty.visibility = 'visible';
      }
    }
    if (newW>=this.large.w)   return;       // ignore if too big
    this.cur.w = tmpW;
    this.cur.h = tmpH;
    this.cur.ml = tmpML;
    this.cur.mt = tmpMT;
    this.layer.w(newW);  this.image.width = newW+'px';
    this.layer.h(newH);  this.image.height = newH+'px';
    this.layer.sty.marginLeft = newML+'px';
    this.layer.sty.marginTop = newMT+'px';
  }};
//
  menutile.prototype.shrinkTile = function() { with (this) {
    var newW,tmpW,newH,tmpH,newML,tmpML,newMT,tmpMT;
    if (this.count<=0)   return;
    if (!this.timer) {
      clearInterval(this.timer);
      this.timer = setInterval('tile["'+this.me+'"].shrinkTile()', 50);
      newW = tmpW = this.cur.w;
      newH = tmpH = this.cur.h;
      newML = tmpML = this.cur.ml;
      newMT = tmpMT = this.cur.mt;
    } else {
      this.count--;
      newW = Math.round(tmpW = this.cur.w - this.off.w);
      newH = Math.round(tmpH = this.cur.h - this.off.h);
      newML = Math.round(tmpML = this.cur.ml - this.off.ml);
      newMT = Math.round(tmpMT = this.cur.mt - this.off.mt);
      if (this.count<=0) {
        clearInterval(this.timer);
        this.timer = null;
      }
    }
    if (newW<=this.small.w)   return;       // ignore if too small
    this.cur.w = tmpW;
    this.cur.h = tmpH;
    this.cur.ml = tmpML;
    this.cur.mt = tmpMT;
    this.layer.w(newW);  this.image.width = newW+'px';
    this.layer.h(newH);  this.image.height = newH+'px';
    this.layer.sty.marginLeft = newML+'px';
    this.layer.sty.marginTop = newMT+'px';
  }};

  function isMouseLeaveOrEnter(e, handler) {
    if (e.type != 'mouseout' && e.type != 'mouseover') return false;
    var reltg = e.relatedTarget ? e.relatedTarget :
                  e.type == 'mouseout' ? e.toElement : e.fromElement;
    while (reltg && reltg != handler) reltg = reltg.parentNode;
    return (reltg != handler);
  }

  var tile = Array();
  function startClusterMenu() {
    tiles = tileList.length-1;
    for (var i=0; i<tiles; i++) {
      var key = tileList[i][0];
      tile[key] = new menutile(key,tileList[i][1],tileList[i][2]);
    }
    if (typeof(animatingLogo)=='undefined')   getSty('cluster').visibility = 'visible';
  }
  addEvent(window, 'load', startClusterMenu);

