window.addEvent('domready', function() { initSliders(); });

var animatedDivs = new Array();

function initSliders() {
  var openSlider = getParameter('openslider');
  var divs = document.getElements('div.slider');
  var index = 0;
  for (var i = 0; i < divs.length; i++) {
    if (divs[i].id != "") {
      if (divs[i].id == openSlider) {
        // start opened
        animatedDivs[index++] = new animatedcollapse(divs[i].id, 500, "block");
      } else {
        // start closed
        animatedDivs[index++] = new animatedcollapse(divs[i].id, 500);
      }
    }
  }
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function scrollToPos(position) {
  window.scrollTo(0, position);
}

function slide(divid) {
  var divIndex = -1;
  var open = -1;
  for (var i = 0; i < animatedDivs.length; i++) {
  	if (animatedDivs[i].divObj.id != divid) {
  	  if (parseInt(animatedDivs[i].divObj.style.height) != 0) {
  	    animatedDivs[i].slideup();
        open = i;
      }
  	} else {
  	  var divIndex = i;
  	}
  }
  if (divIndex >= 0) {
    animatedDivs[divIndex].slideit();
    if (open > -1 && divIndex > open) {
      var scrollUp = animatedDivs[open].contentheight;
      window.setTimeout("scrollToPos(" + (getScrollY() - scrollUp) + ")", animatedDivs[divIndex].timelength + 50);
    }
  }
}

function getParameter(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
