var inProgress = false;
var boxVisible = false;

/*
Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }

    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;

    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } else {

    }
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});
*/

function changeText (elem, showText, hideText) {
	if (elem.innerHTML==hideText)
	  elem.innerHTML=showText;
	else 
	  elem.innerHTML=hideText;
}


function toggleBox(element, myDuration, switcher, showText, hideText) {
		if (element && !inProgress) {
		inProgress = true;
		if (myDuration == undefined)
			myDuration = 0.5;
		if (element.style.display == 'none')  { //show
			Effect.BlindDown(element.id, {
				duration: myDuration, 
				afterFinish:function(){
					inProgress = false;
					if (switcher) 
						changeText(switcher, showText, hideText);
					//re-init scrollbars
					if (dw_scrollObj.isSupported()) {
						init_dw_Scroll();
					}
				}
			}); 
		} else { //hide
			Effect.BlindUp(element.id, {
				duration: myDuration, 
				afterFinish:function() {
					inProgress = false;
					if (switcher) 
						changeText(switcher, showText, hideText);
					//re-init scrollbars
					if (dw_scrollObj.isSupported()) {
						init_dw_Scroll();
					}
				}
			});
		}
	}
	return false;
}


function showBox(element, myDuration) {
	if (element && !inProgress && !boxVisible) {
		inProgress = true;
		if (myDuration == undefined)
			myDuration = 0.5;
		if (element.style.display == 'none')  {
			Effect.BlindDown(element.id, {duration: myDuration, afterFinish:function(){inProgress = false; boxVisible = true;}}); 
		}

	}
	return false;
}


function hideBox(element, myDuration) {
	if (element && !inProgress && boxVisible) {
		inProgress = true;
		if (myDuration == undefined)
			myDuration = 0.5;
		if (element.style.display != 'none')  {
			Effect.BlindUp(element.id, {duration: myDuration, afterFinish:function(){inProgress = false; boxVisible = false;}}); 
		}
	}
	return false;
}


// mouse wheel code from http://adomas.org/javascript-mouse-wheel/
function handle(delta) {
	slider3.setValueBy(-delta);
}


/** Event handler for mouse wheel event. */
function wheel(event){
	var delta = 0;
	if (!event) /* For IE. */
		event = window.event/90;
	if (event.wheelDelta) { /* IE/Opera. */
		delta = event.wheelDelta/90;
		/** In Opera 9, delta differs in sign as compared to IE. */
		if (window.opera)
			delta = -delta/90;
	} else if (event.detail) { /** Mozilla case. */
		/** In Mozilla, sign of delta is different than in IE.
		* Also, delta is multiple of 3.
		*/
		delta = -event.detail/90;
	}

	/** If delta is nonzero, handle it.
	* Basically, delta is now positive if wheel was scrolled up,
	* and negative, if wheel was scrolled down.
	*/
	if (delta)
		handle(delta);

	/** Prevent default actions caused by mouse wheel.
	* That might be ugly, but we handle scrolls somehow
	* anyway, so don't bother here..
	*/
	if (event.preventDefault)
		event.preventDefault();
	
	event.returnValue = false;
}

