function gallery(){
	
	var totWidth=0;
	var positions = new Array();

	$('#slides .slide').each(function(i){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		positions[i]= totWidth;
		totWidth += $(this).width();

		/* The positions array contains each slide's commulutative offset from the left part of the container */

		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});

	$('#slides').width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#menu ul li a').click(function(e){
		
		$("#tagLink").attr("href", "#").html("&nbsp;");
		
		//add tags link
		if($(this).attr("rel") == 1){
			
			$(".note").remove();
			$(".notep").remove();
			
			var image = "";
			var type = $(this).attr("rev");
			var prodid = $("#prodid").val();
			var file = $(this).attr("title");
			
			if(type == "default"){
				image = "images/products/"+file;
			}else{
				image = "images/products/"+prodid+"/"+file;
			}
			
			//swap out source image
			$("#image_notes img").attr("src", "images/timthumb.php?src="+image+"&w=500&h=500&q=100");
			
			//get notes
			$.ajax({
				url: "products.php?action=photonotes&prodid="+prodid+"&file="+file,
				dataType: "json",
				type: "GET",
				success: function(response){

					notes = response;
					$("#image_notes img").imgNotes();
				}
			});
			
			$("#tagLink").attr("href", "#").html("View Product Notes");
		}
		
		/* On a thumbnail click */
		$("#menu ul li.menuItem").removeClass("act").addClass("inact");
		//$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');

		var pos = $(this).parent().prevAll('.menuItem').length;

		$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
		/* Start the sliding animation */

		e.preventDefault();
		/* Prevent the default action of the link */
	});

	$("#menu ul li.menuItem").removeClass("act").addClass("inact");
	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	
	//do some cleanup, being that this is now swapped out with ajax
	$('#slides').stop().animate({marginLeft:'0px'},450);
	/* On page load, mark the first thumbnail as active */
}

$(document).ready(function(){
	gallery();
	$('#menu ul li a:first').click();
});
