
var intervalSpeed = 100;
var splitSize = 2.4;
var preventBGChange = false;
var menuHeight = 150;


function Slider(id) {

   // varialbes
   if (document.getElementById(id))
   {
      this.props = document.getElementById(id).style;
      this.iy = parseInt(this.props.top);
      this.dy = 0;
      this.slideTime = 4;
      this.interval = null;
      this.offTimer = null;
      this.name = id + "_slider";
      eval(this.name + " = this");
      this.isOpen = false;

      
      // define the functions
      this.slideUp = slideUp;
      this.slideDown = slideDown;
      this.getTop = getTop;
      this.hideSub = hideSub;
   }
}



function slideDown() {
   
   var y = this.getTop();
   var dy = this.dy;
   var gap = Math.abs(y - dy);


   // if it is moving slowly, allow the backgrounds to change
   if(gap < 40) {
      preventBGChange = false;
   } else {
      preventBGChange = true;
   }

   if((y + (gap/splitSize)) < (dy-1)) {
      this.props.top = y + Math.round(gap/splitSize);
      document.getElementById("dropdowns").style.height = menuHeight + "px";
   } else {
      this.props.top = dy;
      clearInterval(this.interval);
      this.interval = null;
   }

}


function slideUp() {
   
   var y = this.getTop();
   var dy = this.iy;
   var gap = Math.abs(y - dy);
   
   // if it's sliding up, don't change the backgrounds
   preventBGChange = true;
   
   if((y - (gap/splitSize)) > (dy+1)) {
      this.props.top = y - Math.round(gap/splitSize);
      document.getElementById("dropdowns").style.height = menuHeight + "px";
   } else {
      document.getElementById("dropdowns").style.height = "20px";
      this.props.top = dy;
      clearInterval(this.interval);
      this.interval = null;
      preventBGChange = false;
   }

}



function getTop() {
   
   return parseInt(this.props.top);

}



function subOver(overSub) {

   var slider = eval(overSub + "_slider");

   // clear any timers
   if(slider.offTimer != null) {
      clearTimeout(slider.offTimer);
      slider.offTimer = null;
   }


   if(!slider.isOpen) {
      document.getElementById("dropdowns").style.height = menuHeight + "px";
      slider.isOpen = true;

      if(slider.interval != null) {
         clearInterval(slider.interval);
      }
      slider.interval = setInterval(slider.name + ".slideDown()", intervalSpeed);
   }

}


function subOut(outSub) {

   var slider = eval(outSub + "_slider");
   
   if(slider.offTimer == null) {
      slider.offTimer = setTimeout(slider.name + ".hideSub()", 400);
   }
   
}



function hideSub() {
   
   if(this.interval != null) {
      clearInterval(this.interval);
   }
   
   this.offTimer = null;
   this.isOpen = false;
   this.interval = setInterval(this.name + ".slideUp()", intervalSpeed);

}








function changeBG(td) {
   
   if(!preventBGChange) {
      td.className = "subOver";
   }

}

function changeBGback(td) {

   td.className = "sub";

}



function initSliders() {

   var community_sub_slider = new Slider("community_sub");
   var products_sub_slider = new Slider("products_sub");
   
}
