function checkNavigation() {
	if (viewMore.length==lastPosition) {
		$("moveRight").hide();
		$("moveRightDis").show();
	} else {
		$("moveRightDis").hide();
		$("moveRight").show();
	}
	
	if (lastPosition<=4) {
		$("moveLeft").hide();
		$("moveLeftDis").show();
	} else {
		$("moveLeftDis").hide();
		$("moveLeft").show();
	}
}

var htmlToAdd = "";

for (i=0;i<viewMore.length;i++) {
	var n = i + 1;
	htmlToAdd += '<a href="' + viewMore[i] + '" id="viewmore-' + n + '" style="display:none;">' + n + '</a>';
}

document.getElementById('viewmenu').innerHTML = htmlToAdd;

var startingPlace;

for (i=0;i<viewMore.length;i++) {
	var n = i + 1;
	if (viewMore[i].toLowerCase()==jQuery.url.attr("file").toLowerCase()) {
		startingPlace = n;
	}
	if (n<5) {
		$("viewmore-" + n).show();
		if (viewMore[i].toLowerCase()==jQuery.url.attr("file").toLowerCase()) {
			document.getElementById('viewmore-' + n).style.backgroundColor = "#e2dfd1";
		}
	}
}

var lastPosition;

if (viewMore.length>4) {
	lastPosition = 4;
} else {
	lastPosition = viewMore.length;
}

checkNavigation();

function moveRight() {
	if (lastPosition>=4) {
		var incrementMoves = viewMore.length - lastPosition;
		
		if (incrementMoves>4) {
			incrementMoves = 4;
		}
		
		for (i=0;i<incrementMoves;i++) {
			var n = i + 1;
			var oldLink = lastPosition - 4 + n;
			var newLink = lastPosition + n;
			$("viewmore-" + oldLink).hide();
			$("viewmore-" + newLink).show();
			if (viewMore[newLink-1].toLowerCase()==jQuery.url.attr("file").toLowerCase()) {
				document.getElementById('viewmore-' + newLink).style.backgroundColor = "#e2dfd1";
			}
		}
		
		lastPosition += incrementMoves;
		
		checkNavigation();
		
	}
}

function moveLeft() {
	if (lastPosition>=4) {
		var incrementMoves = lastPosition - 4;
		
		if (incrementMoves>4) {
			incrementMoves = 4;
		}
		
		for (i=0;i<incrementMoves;i++) {
			var n = i + 1;
			var oldLink = lastPosition - incrementMoves + n;
			var newLink = lastPosition - 4 - i;
			$("viewmore-" + oldLink).hide();
			$("viewmore-" + newLink).show();
			if (viewMore[newLink-1].toLowerCase()==jQuery.url.attr("file").toLowerCase()) {
				document.getElementById('viewmore-' + newLink).style.backgroundColor = "#e2dfd1";
			}
		}
		
		lastPosition -= incrementMoves;
		
		checkNavigation();
	}
}

if (startingPlace>4) {
	if (startingPlace<=8) {
		moveRight();
	} else if (startingPlace<=12) {
		moveRight();
		moveRight();
	} else if (startingPlace<=16) {
		moveRight();
		moveRight();
		moveRight();
	}
}