var step = 4;
var speed = 5;

var divHeight = 380;
var topLeft = 0;
var topRight = 0;
var leftDivHeight;
var rightDivHeight;

var scrollTimer;

var mouseOverSide;

/* Show the arrows if neccesary */
function getDivHeight(div){
	if(div.offsetHeight) {
		return div.offsetHeight;
	}
	if (div.clip) {
		return div.clip.height;
	}
	return 0;
}

function showArrows(){
	if(document.getElementById("moveleftcontent")){
		leftDivHeight = getDivHeight(document.getElementById("moveleftcontent"));
		if (leftDivHeight > divHeight) {document.getElementById("leftarrowup").style.visibility = 'visible'; document.getElementById("leftarrowdown").style.visibility = 'visible';}
	}
	if(document.getElementById("moverightcontent")){
		rightDivHeight = getDivHeight(document.getElementById("moverightcontent"));
		if (rightDivHeight > divHeight) {document.getElementById("rightarrowup").style.visibility = 'visible'; document.getElementById("rightarrowdown").style.visibility = 'visible';}
	}
	if(navigator.appName == "Netscape"){
		speed = speed*5;
	}
}


/* Scroll the content by stating side and direction */
function scroll(side, direction) {
if(navigator.appName == "Netscape"){
	direction = direction*2;
}
	if( side == "left"){
		if ( topLeft + (step * direction) > 0){
			topLeft = 0;
			document.getElementById("moveleftcontent").style.top = topLeft + "px";
		} else if ( topLeft + (step * direction ) + leftDivHeight < divHeight){
			if (divHeight < leftDivHeight){
				topLeft = divHeight - leftDivHeight;
				document.getElementById("moveleftcontent").style.top = topLeft + "px";
			}
		} else {
			topLeft = topLeft + (step * direction );
			document.getElementById("moveleftcontent").style.top = topLeft + "px";
		}
	} else if( side == "right"){
		if ( topRight + (step * direction) > 0){
			topRight = 0;
			document.getElementById("moverightcontent").style.top = topRight + "px";
		} else if ( topRight + (step * direction ) + rightDivHeight < divHeight){
			topRight = divHeight - rightDivHeight;
			document.getElementById("moverightcontent").style.top = topRight + "px";
		} else{
			topRight = topRight + (step * direction );
			document.getElementById("moverightcontent").style.top = topRight + "px";
		}
	} 
}

/* scroll by using the arrows */
function startScroll(side, direction){
	scrollTimer = setInterval('scroll(\"' + side + '\",' + direction +')', speed);	
}

function stopScroll(){
	clearInterval(scrollTimer);
}

/* scroll by using the mousewheel */
function handle(delta) {
	scroll(mouseOverSide, delta);
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
	if( mouseOverSide != null){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/20;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } 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*2.2;
        }
        /** 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;
}

function mouseOver(side){
	mouseOverSide = side;
}

function mouseOut(){
	mouseOverSide = null;
}



/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;

