var firstVisibleItemId = 0;
var itemsNrPerPage = 0;

function activateScroll() {
	fixShadows();
	var maxMainContentWidth = parseInt($(window).width(), 10) - 134 - 15;
	var itemWidth = 0;
	itemWidth = Math.max(275 + 7 + 15 + 5, 	parseInt($('.mainContent .item:first').width()));

	itemsNrPerPage = parseInt(maxMainContentWidth / itemWidth);
	if (itemsNrPerPage > 4) {
		itemsNrPerPage = 4;
	}
	if (itemsNrPerPage < 1) {
		itemsNrPerPage = 1;
	}

	var mainContentWidth = itemsNrPerPage * itemWidth;
	$('.mainContent').css('width', mainContentWidth + 'px');
	$('#ScrollingPane').css('width', mainContentWidth + 'px');
	$('.header-center').css('width', (maxMainContentWidth) + 'px');

	if (typeof (nScheepensLines) == "undefined") {
		nScheepensLines = 1;
	}

	var itemsCount = $('.mainContent').find('.item').length;
	var totalLength = Math.round(itemsCount / nScheepensLines);
	totalLength = totalLength * itemWidth + 1000;
	$('.allitems').css('width', totalLength + 'px');
	
	scrollVisibility();
}
function nextPage() {
	// scroll on the next item from the list, only if this one exists
	firstVisibleItemId = firstVisibleItemId + nScheepensLines;
	var nextItem = $(".mainContent .item[id='item_" + (firstVisibleItemId) + "']");
	if (nextItem.length > 0) {
		
		var shadow = nextItem.parent('.shadow');
		if (shadow.length > 0){
			$('.mainContent').scrollTo(shadow, { speed: 700 });
		}
		else{
			$('.mainContent').scrollTo(nextItem, { speed: 700 });
		}
	}
	scrollVisibility();
}

function prevPage() {
	// scroll on the prev item from the list, only if this one exists
	firstVisibleItemId = firstVisibleItemId - nScheepensLines;
	var prevItem = $(".mainContent .item[id='item_" + (firstVisibleItemId) + "']");
	if (prevItem.length > 0) {
	
		var shadow = prevItem.parent('.shadow');
		if (shadow.length > 0){
			$('.mainContent').scrollTo(shadow, { speed: 700 });
		}
		else{
			$('.mainContent').scrollTo(prevItem, { speed: 700 });
		}
		
	}
	scrollVisibility();
}

function scrollVisibility() {
	if (firstVisibleItemId >= nScheepensLines) {
		$('#ScrollingPane .shadow_scrollback').css('visibility', 'visible');
	}
	else {
		$('#ScrollingPane .shadow_scrollback').css('visibility', 'hidden');
	}

	if (firstVisibleItemId + (nScheepensLines * itemsNrPerPage) < $('.mainContent').find('.item').length) {
		$('#ScrollingPane .shadow_scrollnext').css('visibility', 'visible');
	}
	else {
		$('#ScrollingPane .shadow_scrollnext').css('visibility', 'hidden');
	}
	$("div[id^='staticScreen_']").hide();
}

function fixShadows() {
	$('.item').css('position', 'relative');
	if (($.browser.msie) && (parseInt(jQuery.browser.version, 10) == 7))
	{
		$('.allitems .item').css('position', 'static');
	}
}
