init = 0;

function addLoadEvent(func) {

	var oldonload = window.onload;

	if (typeof window.onload != 'function') {

		window.onload = func;

	}

	else {

		window.onload = function() {

			oldonload();

		}

	}

}


function initSlide(numberstudies) { 

 maxmoves = numberstudies - 3;
 position = 0;
 moved = 0;
 sliding = 0;
 init = 1;

}


function slide(direction) {
	
	if (init == 1) {
	
	if (sliding == 0) { 
	
	sliding = 1;
	
	if (document.getElementById('slider').offsetWidth > document.getElementById('slidearea').offsetWidth) {
	
	if (( (direction == 'left') && (position != 0) ) || ( (direction == 'right') && (moved < maxmoves) ))  { 
	
		sliding = setInterval("move('" + direction + "')", 10);
		distance = 0;
	
		} 
		
		if ( (direction == 'right') && (moved == maxmoves-1) ) {
		
		document.getElementById('slideright').style.display = 'none';
		
		} else if ( (direction == 'left') && (moved == maxmoves) ) {
		
		document.getElementById('slideright').style.display = 'block';
		
		}
		
		
		if ( (direction == 'left') && (moved == 1) ) {
										
		document.getElementById('slideleft').style.display = 'none';
		
		} else if ( (direction == 'right') && (moved == 0) ) {
		
		document.getElementById('slideleft').style.display = 'block';
		
		}
			
	}
	
	}
	
	}

}


function move(direction) {

	if ( (distance == 235) || (distance == -235) ) { 
	stopslide(direction);
	} else { 
	
		if (direction == 'left') { 
	
			position = position + 5;	
			distance = distance + 5;
			document.getElementById('slider').style.left = position + 'px';
			
	
		} 
	

		if (direction == 'right') { 
	
			position = position - 5;
			distance = distance - 5;
			document.getElementById('slider').style.left = position + 'px';
			
			
		}
	
	}
	
}

function stopslide(direction) {
	
	if (init == 1) {
	
clearInterval(sliding);
if (direction == 'right') { moved = parseInt(moved) + 1; } 
if (direction == 'left') { moved = parseInt(moved) - 1; }

sliding = 0;

	}
	
}
