var panels = new Object();

var panelHideDelay = 500;

function Panel(_num)
{
  this.num = _num;
  this.slider = new StyleSlider('panel-' + _num, 'top');
  this.delay = panelHideDelay;
  this.hideTimeout = null;
}

Panel.prototype.getHidePanelFunction = function(e)
{
  num = this.num;
  delay = this.delay;

  return function(e)
  {
    if (panels[num].hideTimeout)
      clearTimeout(panels[num].hideTimeout);
    top.document.title = num;
    if (!inPanel(e, num)) 
      panels[num].hideTimeout = setTimeout('panels[' + num + '].hidePanel()', delay); 
  }
  
  
}

Panel.prototype.showPanel = function()
{
  if (this.hideTimeout)
  {
    clearTimeout(this.hideTimeout);
  }
  this.slider.startValue = 110;
  this.slider.endValue = 0;
  this.slider.steps = 20;
  this.slider.length = 200;
  this.slider.slideMode = 'easeOut';
  this.slider.startSlide();
  num = this.num;
  //$('panel-' + this.num).onmouseout = this.getHidePanelFunction();
  
  $('panel-' + this.num).onmouseout = function(e) { if (!inPanel(e, num)) panels[num].hidePanel(); }
}

Panel.prototype.hidePanel = function()
{
  this.slider.startValue = 0;
  this.slider.endValue = 110;
  this.slider.steps = 20;
  this.slider.length = 200;
  this.slider.slideMode = 'easeOut';
  this.slider.startSlide();
}

function inPanel(e, num, include_panel)
{
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
  var target = e.target || e.srcElement;
  
  var p = $('panel-' + num);
  if (isChildOf(relTarg, p)) return true;

  return false;
}

function isChildOf(element1, element2)
// Determine if element 1 is a child of element 2
{
  if (!element1) return false;
  if (element1 == element2) return true;
  while(element1.parentNode)
  {
    if (element1 == element2) return true;
    element1 = element1.parentNode;
  }
  return false;
}

function initPanel(_link, num)
{
  var p = new Panel(num);
  panels[num] = p;
  var el = document.getElementById(_link);
  el.onmouseover = new Function('panels[' + num + '].showPanel()');
  //el.onmouseout = function(e) { if (!inPanel(e, num)) setTimeout('panels[' + num + '].showPanel()', panelHideDelay); }
  el.onmouseout = function(e) { if (!inPanel(e, num)) panels[num].hidePanel(); }
}

 