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 = slideMax;
 sliding = 0;
 init = 1;

}


function autoSlide() { 

automatic = setInterval('slide(\'right\')', autoInterval);
timeout = (maxmoves + 1) * autoInterval + 500;

setTimeout("stopSlide()",timeout);

auto = 1;

}

function stopSlide() {

if (init == 1) { clearInterval(automatic); }

auto = 0;

}

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';
		
		}
			
	}
	
	}
	
	}

	if ((moved == maxmoves) && (auto == 1)) { 
	// Reached end of slideshow - reset
	var resetInterval = 5;
	resetinterval = setInterval(resetslides, resetInterval);
	resettimeout = ((((maxmoves + 1) * slideWidth) / slideInterval) * resetInterval) + 1000;
	}

}


function resetslides() {
if (position < 0) { 
position = position + slideInterval;
distance = distance + slideInterval;
document.getElementById('slider').style.left = position + 'px';
} else { 
stopreset();
}
}

function stopreset() { 
clearInterval(resetinterval);
sliding = 0;
document.getElementById('slideright').style.display = 'block';
document.getElementById('slideleft').style.display = 'none';
document.getElementById('slider').style.left = '0px';
distance = 0;
moved = 0;
sliding = 0;
position=0;
autoSlide();
}


function move(direction) {

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

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

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

sliding = 0;
}