/* user edit ------------- */

//thumbnail width INCLUDING margin, padding and border
var thumbWidth = 	115;
//total number of thumbnails visible
var thumbsVis = 5;

/* ---------------------- */


var x = 0;
var curPage = 0;

$(document).ready(
	function() {
		var numThumbs = $("#scroll").find("img").size();
		$("#next").click(function() { 
			updateOffset(1,numThumbs);
			$("#scroll").animate({ left: x }, 1000);	
			return false;
		})
		$("#prev").click(function() { 
			updateOffset(0,numThumbs);
			$("#scroll").animate({ left: x }, 1000);
			return false;
		})
		
		var numPages = numThumbs/thumbsVis;
		for (i=0;i<numPages;i++) {
			if (i == 0) {
				pageCopy = '<li id="page-'+i+'" class="on">Page '+i+'</li>';
			} else {
				pageCopy = pageCopy + '<li id="page-'+i+'">Page '+i+'</li>';
			}
		}
		$("#pages").html(pageCopy);
});


	function updateOffset(next,thumbs) {
		if(next == 1) {
			if (x == (0 - ((thumbs - thumbsVis) * thumbWidth))) {
				x = 0;
				curPage = 0;
			} else {
				x = x - (thumbWidth*thumbsVis);
				curPage++;
			}
		}
		if(x <= 0 && next != 1) {
			if (x == 0) {
				x = (0 - ((thumbs - thumbsVis) * thumbWidth));
				curPage = (thumbs/thumbsVis)-1;
			} else {
				x = x + (thumbWidth*thumbsVis);
				curPage--;
			}
		}
		
		$("#pages li").removeClass("on");
		$("#page-"+curPage).addClass("on");
		
		//temporary firefox animation fix - jQuery bug
		foxFix();
	}// end function
	
	
	function foxFix(end) {
		if($.browser.mozilla) {
			if(x == 0) {
				$("#scroll").addClass("fix");
			} else {
				$("#scroll").removeClass("fix");
			}
		}
	}