//  JavaScript Document

//  animPullDownElement (2010-03-22)

//  typical using of this component
//  var animPullDownElement1 = new animPullDownElement();
//  animPullDownElement1.init('table.scan-list','a.col-change','div.col-change-submenu');

function animPullDownElement() {
  var self = this;
  //
  this.containerElem = null;
  this.holderElem = null;
  this.popupElem = null;
  //
  this.animSpeed = 250;
  //
  this.init = function(containerQuery,holderQuery,popupQuery) {
    self.containerElem = dojo.query(containerQuery)[0];
    if (!self.containerElem) return false;
    self.holderElem = dojo.query(holderQuery,self.containerElem)[0];
    self.popupElem = dojo.query(popupQuery,self.containerElem)[0];
    if (!self.holderElem || !self.popupElem) return false;
    self.transform();
    return true;
  };
  //
  this.transform = function() {
    self.holderElem.onmouseover = self.mouseOver;
    self.holderElem.onmouseout = self.mouseOut;
    self.holderElem.onclick = function() {return false;};
    self.popupElem.onmouseover = self.mouseOver;
    self.popupElem.onmouseout = self.mouseOut;
    //
    self.popupElem.style.display = 'block';
    //
    self.popupElem.animPullDownElement = new Object;
    self.popupElem.animPullDownElement.visible = false;
    self.popupElem.animPullDownElement.height = self.popupElem.offsetHeight;
    self.popupElem.animPullDownElement.timerID = null;
    //
    self.popupElem.style.height = 0+'px';
    self.popupElem.style.display = 'none';
  };
  //
  this.mouseOver = function(e,thisElem) {
    if (!thisElem) thisElem = this;
    clearTimeout(self.popupElem.animPullDownElement.timerID);
    if (!self.popupElem.animPullDownElement.visible) {
      dojo.addClass(thisElem,'hover');
      self.popupElem.style.height = 0+'px';
      self.popupElem.style.display = 'block';
      self.popupElem.animPullDownElement.visible = true;
      dojo.animateProperty({node:self.popupElem,properties:{height:{start:0,end:self.popupElem.animPullDownElement.height,unit:"px"}},duration:self.animSpeed}).play();
    }
  };
  //
  this.mouseOut = function(e,thisElem) {
    if (!thisElem) thisElem = this;
    self.popupElem.animPullDownElement.timerID = setTimeout(function(){self.playHidding(e,thisElem);},self.animSpeed);
  };
  //
  this.playHidding = function(e,thisElem) {
    if (!thisElem) thisElem = this;
    dojo.animateProperty({node:self.popupElem,properties:{height:{start:self.popupElem.animPullDownElement.height,end:0,unit:"px"}},duration:self.animSpeed}).play();
    setTimeout(function(){self.endHidding(e,thisElem);},self.animSpeed);
  };
  //
  this.endHidding = function(e,thisElem) {
    if (!thisElem) thisElem = this;
    dojo.removeClass(thisElem,'hover');
    self.popupElem.style.height = 0+'px';
    self.popupElem.style.display = 'none';
    self.popupElem.animPullDownElement.visible = false;
  };
  //
  //return self.init();
}

//  end of document