$(document).ready(function() {
		var increment = 880;
		var current = 0;
		var maxItems = ( $("#nav a").size()-1 ) * increment;
		var teller = 0;
		var currentLoc = 0;
		var pageLoc = new Array
		for(i=0; i<$("#nav a").size(); i++) {
				pageLoc[i] = i * increment;
				//alert(i + "/" + pageLoc[i]);
		}
		
		maxItems = maxItems - (maxItems * 2);
		$('#carousel_left').css("visibility", "hidden");
		
		$('#carousel_right').click(function() {
		if ( (currentLoc+1) == $("#nav a").size()-1 ) {
	         $('#carousel_right').css("visibility", "hidden");
		}
		 if( current <= 0 && current > maxItems ) {
			 current -= increment;
			 teller++;
			 currentLoc = teller;
			 makeActive(teller);
		  $('#itemhouder').animate({
			left: '-=' + increment
		  }, 1000, function() {
			// Animation complete.
			$('#carousel_left').css("visibility", "visible");
		  });
		 }
		});
		
		$('#carousel_left').click(function() {
		  if ( (currentLoc-1) == 0 ) {
	         $('#carousel_left').css("visibility", "hidden");
		  }
		  if( current < 0 ) { 
		  teller--;
		  currentLoc = teller;
		  makeActive(teller);
		  current += increment;
			  $('#itemhouder').animate({
				left: '+=' + increment
			  }, 1000, function() {
				// Animation complete.
				$('#carousel_right').css("visibility", "visible");
			  });
		  }
		});
		
		function makeActive(i) {
			$("#nav a img").attr("src", "/img/navOff.png");
			$("#blokkie_"+i+" img").attr("src", "/img/navOn.png");	
		}
		
		
		$("#nav a").click(function() { 
		if($("div#eenBlog").size() == 0) {
			var activeId = $(this).attr("id");
			activeId = activeId.replace("blokkie_", "");
			
			makeActive(activeId);
			
			// GO
			newMove = "-"+pageLoc[activeId];
			current = "-"+pageLoc[activeId];
			
			if( currentLoc != activeId ) {
			$('#itemhouder').animate({
				left: newMove
			  }, 1000, function() {
				// Animation complete.
				
			  });
			currentLoc = activeId;
			teller = currentLoc;
			}
			
			$('#carousel_left').css("visibility", "visible");
		$('#carousel_right').css("visibility", "visible");
		 if ( (activeId) == 0 ) {
	         $('#carousel_left').css("visibility", "hidden");
		  }
		  if ( (activeId) == $("#nav a").size()-1 ) {
	         $('#carousel_right').css("visibility", "hidden");
		}
		}
		});
		
	/* observe pad */
	var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
	  
	  $("#nav a").each(function(index) {
		if( $(this).attr("href") == "#" +  myFile.split('#')[1] ) {
			//alert( $(this).attr("href") + "/" + myFile.split('#')[1] + "/" + index);
			var activeId = index;
			
			makeActive(activeId);
			
			// GO
			newMove = "-"+pageLoc[activeId];
			current = "-"+pageLoc[activeId];
			
			if( currentLoc != activeId ) {
			$('#itemhouder').animate({
				left: newMove
			  }, 1000, function() {
				// Animation complete.
				
			  });
			currentLoc = activeId;
			teller = currentLoc;
			}
			
			$('#carousel_left').css("visibility", "visible");
		$('#carousel_right').css("visibility", "visible");
		 if ( (activeId) == 0 ) {
	         $('#carousel_left').css("visibility", "hidden");
		  }
		  if ( (activeId) == $("#nav a").size()-1 ) {
	         $('#carousel_right').css("visibility", "hidden");
		}
		}
		
	  });
	}

		
	$('.text').jScrollPane( { dragMaxHeight: 40 } );
		

  });
