$(document).ready(function(){

	
	$('.gallery').find('> div:eq(0)').nextAll().css({'opacity':'0','display':'none'});

	$('.image').each(function(index) {
			$(this).prepend('<p class="slidecontrols"><a title="Previous" class="active">&larr; Prev</a> <span>/</span> <a title="Next" class="active">Next Image &rarr;</a>');
	  	});

//	$('.gallery').find('> div:eq(0) .slidecontrols a:eq(0)').removeClass('active');

	$('.image:first .slidecontrols a:eq(0)').removeClass('active');
	$('.image:last .slidecontrols a:eq(1)').removeClass('active');
	
	
	
	$('.slidecontrols > a.active').click(function(event) {
		event.preventDefault();
		
		var currentslide = $(this).parents('div:first');
		var currentposition = $('.gallery div').index(currentslide);		
		var nextposition = ($(this).attr('title')=='Next') ? currentposition+1 : currentposition-1;

		$('.gallery div:eq('+currentposition+')').animate({opacity: 0}, 100, function() {
		    $('.gallery div:eq('+currentposition+')').css('display','none');		
		    $('.gallery div:eq('+nextposition+')').css('display','block');		
			$('.gallery div:eq('+nextposition+')').animate({opacity: 100}, 200);


		  }
		);
	});

});
