var activePage = 1;

$(document).ready(function() {
	// ONLY SHOW THE FIRST CONTENT PAGE
	$(".contentpage").slice(1).hide();
	
	// MORE THAN ONE?
	numPages = $(".contentpage").length;
	
	if (numPages > 1) {
		$("#main-scroller").addClass("scroller");
		
		// ADD PAGING BAR UNDERNEATH
		$(".scroller").after("<div id=\"pagebar\"><a id=\"pageprev\" href=\"#\">Previous</a>&nbsp;<a id=\"pagenext\" href=\"#\">Next</a></div>");
		
		// HIDE PREVIOUS LINK (WONT NEED IT TO START WITH)
		$("#pageprev").hide();		
		
		// ATTACH EVENTS
		$("#pageprev").click(function() {
			if (activePage > 1) {
				activePage--;
				
				// MOVE PREVIOUS DIV INTO PLACE
				$(".contentpage:visible").fadeOut("fast",function() {
					$(".contentpage").slice(activePage - 1,activePage).show();				
				});
				
				if (activePage == 1) {
					$("#pageprev").hide();
				}
				
				// SHOW NEXT LINK
				$("#pagenext").show();
			}
			
			return false;
		});
		
		$("#pagenext").click(function() {
			if (activePage < numPages) {
				activePage++;
				
				// MOVE NEXT DIV INTO PLACE
				$(".contentpage:visible").fadeOut("fast",function() {
					$(".contentpage").slice(activePage - 1,activePage).show();
				});
				
				if (activePage == numPages) {
					$("#pagenext").hide();
				}
				
				// SHOW PREVIOUS LINK
				$("#pageprev").show();
			}
		
			return false;
		});
	}
});