$(document).ready(function(){
		var currentPosition = 0;
		var slideWidth = 1024;
		var slides = $('.slide1');
		var numberOfSlides = slides.length;

		// Remove scrollbar in JS
		$('#slidesContainer1').css('overflow', 'hidden');

		// Wrap all .slides with #slideInner div
		slides
		.wrapAll('<div id="slideInner1"></div>')
		// Float left to display horizontally, readjust .slides width
		.css({
			'float' : 'left',
			'width' : slideWidth
		});

		// Set #slideInner width equal to total width of all slides
		$('#slideInner1').css('width', slideWidth * numberOfSlides);

		// Insert left and right arrow controls in the DOM
		$('#slideshow1')
		  //.prepend('<span class="control" id="leftControl">Move left</span>')
		  //.append('<span class="control" id="rightControl">Move right</span>');

		// Hide left arrow control on first load
		manageControls(currentPosition);

		// Create event listeners for .controls clicks
		$('.control1')
		  .bind('click', function(){
		  // Determine new position
		  currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;

		// Hide / show controls
		//manageControls(currentPosition);
		// Move slideInner using margin-left
		$('#slideInner1').animate({
		  'marginLeft' : slideWidth*(0)
		});
		});
				
		$('.control-ourfood')
			.bind('click', function(){
				
				$('#wwd-bg').removeClass();
				$('#wwd-bg').addClass('ourfood-bg');
				
				$('#wwd-top').removeClass();
				$('#wwd-top').addClass('ourfood-top');
				
				$('#wwd-bottom').removeClass();
				$('#wwd-bottom').addClass('ourfood-bottom');
				
				$('#wwd-bg-content').html('');
				
				var bg_content = '<img src="images/ymber-delcto.png" alt="ymber delcto" class="ymber-delcto" /><img src="images/joan-gussow.png" alt="joan gussow" class="joan-gussow" /><img src="images/cow1.png" alt="cow" class="cow1" /><img src="images/a-and-b.png" alt="a and b" class="a-and-b" />';
				
				$('#wwd-bg-content').html(bg_content);
				
				$('#slideInner1').animate({
					'marginLeft' : slideWidth*(currentPosition)
				});
				
			});
		
		$('.control-ourpeople')
			.bind('click', function(){
				
				$('#wwd-bg').removeClass();
				$('#wwd-bg').addClass('ourpeople-bg');
				
				$('#wwd-top').removeClass();
				$('#wwd-top').addClass('ourpeople-top');
				
				$('#wwd-bottom').removeClass();
				$('#wwd-bottom').addClass('ourpeople-bottom');
				
				$('#wwd-bg-content').html('');
				
				var bg_content = '<img src="images/prime-pork.png" alt="prime pork" class="prime-pork" /><img src="images/chirpy-chickens.png" alt="chirpy-chickens" class="chirpy-chickens" />';
				
				$('#wwd-bg-content').html(bg_content);
				
				$('#slideInner1').animate({
					'marginLeft' : slideWidth*(currentPosition - 1)
				});
			
			});
		
		$('.control-ourvalues')
			.bind('click', function(){
				
				$('#wwd-bg').removeClass();
				$('#wwd-bg').addClass('ourvalues-bg');
				
				$('#wwd-top').removeClass();
				$('#wwd-top').addClass('ourvalues-top');
				
				$('#wwd-bottom').removeClass();
				$('#wwd-bottom').addClass('ourvalues-bottom');
				
				$('#wwd-bg-content').html('');
				$('#wwd-bg-content').html('<img src="images/arrows4.png" alt="prime pork" class="arrow4" /><img src="images/arrows5.png" alt="chirpy-chickens" class="arrow5" /><img src="images/tractor.png" alt="chirpy-chickens" class="tractor" /><div id="credentials"><p>Our credentials...</p><a href="http://www.leafuk.org/leaf/home.eb" target="_blank"><img src="images/leaf.png" /><br /></a><img src="images/iso.png" /><br /><a href="http://www.fairtrade.org.uk/" target="_blank"><img src="images/fairtrade.png" /></a><br /><a href="http://www.loco2energy.com/" target="_blank"><img src="images/loco2.gif" /></a></div>');
				
				$('#slideInner1').animate({
					'marginLeft' : slideWidth*(currentPosition - 2)
				});
				
			});
				
		// manageControls: Hides and shows controls depending on currentPosition
		function manageControls(position){
			// Hide left arrow if position is first slide
			if(position==0){ $('#leftControl1').hide() }
			else{ $('#leftControl1').show() }
				// Hide right arrow if position is last slide
			if(position==numberOfSlides-1){ $('#rightControl1').hide() }
				else{ $('#rightControl1').show() }
			}
	});

