function Helpbar() 
{
  this.$element = null; 
  this.$caption = null; 
  
  this.$expanded= false; 
  this.$link = null; 
  this.$content = null; 
  
  
  
  
  IMPLEMENT_GARBAGE(this); 
}

Helpbar.ACTIVEBAR = null


Helpbar.prototype.dispose = function() 
{ 
  Helpbar.ACTIVEBAR = null; 
}

Helpbar.prototype.attach = function (container, caption) 
{
  this.$element = document.getElementById(container); 
  this.$caption = document.getElementById(caption); 
  
  if (!this.$element) 
    alert("failed to locate helpbar: " + container); 

  if (!this.$caption) 
    alert("failed to locate helpbar caption: " + caption); 

  this.$caption.$ctx = this; 
  
  event_install(this.$caption, "onmousedown", this.start_drag); 
  event_install(this.$caption, "onmouseup", this.stop_drag); 
  event_install(document,"onmousemove", this.mouse_move); 
  
  // disable selection mozilla based engines 
  this.$caption.onmousedown = new Function("return false"); 
  
  // ie 
  if (typeof this.$element.onselectstart != "undefined")
    this.$caption.onselectstart = new Function("return false;");  	
  

  
   
}


Helpbar.prototype.start_drag = function() {




  var pos = this.$ctx.get_position(this); 
  
  // make it more realistic 
  // better than having the cursor always in centre
  if (pos) 	
     this.$ctx.$element.$offset = [pos, pos[0] - MouseCapture.XPOS] ;
     

  //this.$ctx.$inner = (document.body.clientWidth - document.getElementById("content").clientWidth) / 2;
    
  this.$drag = true; 
  
  Helpbar.ACTIVEBAR = this; 
  
}

Helpbar.prototype.stop_drag = function() {
  this.$drag = false; 
  this.style.cursor = 'default'; 
}


Helpbar.prototype.mouse_move = function() 
{ 
  if (!Helpbar.ACTIVEBAR || !Helpbar.ACTIVEBAR.$drag) 
    return false;
  
  // get active draging bar 
  var element = Helpbar.ACTIVEBAR.$ctx.$element; 
  var caption = Helpbar.ACTIVEBAR; 
  
  
  // only vertical scrolling present therefore calculate the scroll 
  // height and apply to element position 
  var top = 0;
  
  // ie specific bug on second conditional 
  if (document.documentElement.scrollTop && typeof document.onselectstart != "undefined" ) 
     top = document.documentElement.scrollTop;  
  
  // simulate draging
  caption.style.cursor = 'pointer'; 
    
  element.style.left = (MouseCapture.XPOS  + element.$offset[1] ) + 'px'; 
  element.style.top = (MouseCapture.YPOS - 20 + top) + 'px'; 
    
    
  return true; 
}

Helpbar.prototype.set_switch = function(link, content) 
{ 
  this.$link = document.getElementById(link); 
  if (!link) alert("failed to locate helpbar link: " + link); 
  
  this.$content = document.getElementById(content); 
  if (!content) alert("failed to locate helpbar link: " + content); 
  
  this.$link.$ctx = this; 
  
  
  event_install(this.$link,"onclick",this.link_click); 
  
}

Helpbar.prototype.link_click = function() {
  this.$ctx.$content.style.display = (!this.$ctx.$toggle) ? "block" : "none"; 
  this.$ctx.$toggle = !this.$ctx.$toggle; 
}

Helpbar.prototype.get_position = function(element) 
{ 
  var x = 0, y = 0; 
  
  do  { 
     x += element.offsetLeft || 0; 
     y += element.offsetTop || 0; 
     element = element.offsetParent;
  } while (element);
  
  return [x,y]; 
}
