var Sublist={
  aObj:new Array(),
  oTimerSUB:null,
  /**Show subscription */
  show: function(elSelf){
    this.delay();
    var pEl=this.findParent(elSelf, 'xmlbutton');
    var chEl=this.findChild(pEl, 'SUBsub');
    if(typeof(chEl)!='undefined' && (chEl.style.visibility=='hidden' || chEl.style.visibility=='')){
      aPosition = this.findPosition(elSelf);
      placeX = parseInt(aPosition.x);
      placeY = parseInt(aPosition.y) + 13;
      chEl.style.left=placeX+'px';
      chEl.style.top=placeY+'px';
      chEl.style.visibility='visible';
    }
  },

  /*set timer for the out function*/
  setout: function(elSelf){
    /*get parent element*/
    var pEl=this.findParent(elSelf, 'xmlbutton');
    /*get child element*/
    var chEl=this.findChild(pEl, 'SUBsub');
    if(typeof(chEl)!='undefined' && chEl.style.visibility=='visible'){
      this.oTimerSUB=setTimeout("Sublist.close()", 150);
      this.aObj[this.aObj.length]=chEl;
    }
  },

  /*close the sublist*/
  close: function(idEl){
    for(var k=0; k<this.aObj.length; k++){
      this.aObj[k].style.visibility='hidden';
    }
    this.aObj=new Array();
    if(typeof(idEl)!='undefined'){
      var pEl=this.findParent(idEl, 'xmlbutton');
      var chEl=this.findChild(pEl, 'SUBsub');
      chEl.style.visibility='hidden';
    }
    if(this.oTimerSUB){
      clearTimeout(this.oTimerSUB);
    }
    return true;
  },
  /*delay close for next out*/
  delay: function(){
    if(this.oTimerSUB){
      clearTimeout(this.oTimerSUB);
    }
  },
  /*Find child HTML element element by className*/
  findChild: function(el, className){
    /*check for an old browsers IE4, NS4 no support for childNodes and other new fuctions*/
    if(!document.getElementById){
      var i=0;
      chEl=null;
      while((chEl=el.children(i)) && i<100){
        if(chEl.className==className){
          return chEl;
        }
        i++;
      }
    }
    var i=0;
    chEl=null;
    while((chEl=el.childNodes[i]) && i<100){
      if(chEl.className==className){
        return chEl;
      }
      i++;
    }
  },
  /*Find parent HTML element element by className*/
  findParent: function(el, className){
    var i=0;
    while(el && i<100){
      if(el.className==className){
        return el;
      }
      if(!document.getElementById){
        el=el.parentElement;
      }else{
        el=el.parentNode;
      }
      i++;
    }
  },

  findPosition: function(elSelf) {
    if (elSelf.offsetParent){
      for (var iPosX = 0, iPosY = 0; elSelf.offsetParent; elSelf = elSelf.offsetParent) {
        iPosX += elSelf.offsetLeft;
        iPosY += elSelf.offsetTop;
      }
      return {'x':iPosX, 'y':iPosY};
    } else {
      return {'x':elSelf.x, 'y':elSelf.y};
    }
  },
  /** Find element position*/
  findPos: function (obj) {
    var curleft = curtop = -10;
    var flParent=0;
    text='';
    while (obj) {
      if(typeof(obj.tagName)=='undefined'){
        break;
      }else if(obj.tagName=='TBODY' || obj.tagName=='FORM' || obj.tagName=='TR' || obj.tagName=='THEAD' || obj.tagName=='TFOOT'){
        obj= obj.parentNode;
        continue;
      }
      text+=obj.tagName+" "+obj.className+" > "+obj.offsetLeft+" > "+obj.scrollLeft+"\n";
      if (obj.tagName=='DIV'){
        if(obj.scrollLeft){
          curleft-= obj.scrollLeft;
        }
        if (obj.scrollTop){
          curtop-= obj.scrollTop;
        }
      }
      if(flParent==0){
        //alert(obj.offsetLeft);
        curleft += obj.offsetLeft;
        curtop += obj.offsetTop;
      }else{
        curleft -= obj.offsetLeft;
        curtop -= obj.offsetTop;
      }
      obj= obj.parentNode;
    }
    //window.status="Parent: "+flParent+'  left'+curleft+'  top'+curtop;
    alert(curleft+"\n"+text);
    return {'x':curleft, 'y':curtop};

    //var pos=Utils.getAbsolutePos(obj);
   // return {'left':pos.x, 'top':pos.y, 'width':pos.w, 'height':pos.h};
  }
};
