var scrollposition = 0;

window.onload = function() { scrollshowposition(0, 0);}
function scrollnext(){
	if (scrollposition < peoplecount - 3){
		newscrollposition = scrollposition + 1;
		scrollshowposition(scrollposition, newscrollposition);
	}
}

function scrollprevious(){
	if (scrollposition > 0){
		newscrollposition = scrollposition - 1;
		scrollshowposition(scrollposition, newscrollposition);
	}
}

function scrollsetposition(newscrollposition){
	scrollshowposition(scrollposition, newscrollposition);
}

function scrollshowposition(oldscrollposition, newscrollposition){
	scrollposition = newscrollposition;

	var divscrollwrapper = document.getElementById('scroll-wrapper');
	var ulpeoplescroller = document.getElementById('peoplescroller');
	var liperson = document.getElementById('person_' + scrollposition);
	var lipersonlast = document.getElementById('person_' + (peoplecount - 1));

	var offset = liperson.offsetLeft - ulpeoplescroller.offsetLeft;
	if (BrowserDetect.browser == 'Explorer') {
		offset = liperson.offsetLeft;
	}

	var lastpersonimageend = lipersonlast.offsetLeft - liperson.offsetLeft + lipersonlast.offsetWidth;

	if (lastpersonimageend < divscrollwrapper.offsetWidth){
		var difference = divscrollwrapper.offsetWidth - lastpersonimageend;
		offset = offset - difference;
	}
	ulpeoplescroller.style.marginLeft = '-' + offset + 'px';

	var personthumbnaillink = null;
	for (var i = 0; i < peoplecount; i++){
		liperson = document.getElementById('person_' + i);
		personthumbnaillink = document.getElementById('personthumbnaillink_' + i);

		var lipersonoffsetLeft = liperson.offsetLeft;
		var lipersonoffsetend = liperson.offsetLeft + liperson.offsetWidth;
		var divscrollwrapperoffsetLeft = divscrollwrapper.offsetLeft;
		var divscrollwrapperoffsetend = divscrollwrapper.offsetLeft + divscrollwrapper.offsetWidth;

		if (BrowserDetect.browser == 'Explorer') {
			lipersonoffsetLeft = ulpeoplescroller.offsetLeft + liperson.offsetLeft;
			lipersonoffsetend = ulpeoplescroller.offsetLeft + liperson.offsetLeft + liperson.offsetWidth;
			if (BrowserDetect.version < 7){
				divscrollwrapperoffsetLeft = 0;
				divscrollwrapperoffsetend = divscrollwrapper.offsetWidth;
			}
//alert(lipersonoffsetLeft + '>=' + divscrollwrapperoffsetLeft + '&&' + lipersonoffsetend + '<=' + divscrollwrapperoffsetend);
		}

		if (lipersonoffsetLeft >= divscrollwrapperoffsetLeft && lipersonoffsetend <= divscrollwrapperoffsetend){
			personthumbnaillink.className = 'personthumbnailselected';
		} else {
			personthumbnaillink.className = 'personthumbnail';
		}
	}
}

function setimage(img, url){
	img.src = url;
}