$(document).ready(function () {
	
	//Gallery Animation
	
	//Global Variables
	
	var galleryItems = $("div#gallery_wrap > div").length;
	var galleryItem = 0;
	
	//Set current number
	function setCurrentNumber() {
		if(galleryItems == 1){
			$('div#gallery_control').hide();
		}
		$('div#gallery_control span').text((galleryItem + 1)+" / "+galleryItems);
	}
	
	setCurrentNumber();
	//Animation on forward click
	
	$("a#forward").click(function() {
				
		galleryItem ++;
	
		if( galleryItem >= galleryItems) {
			
			galleryItem = 0;
			$("div#gallery_wrap").animate({ marginLeft : - galleryItem * 500 }, { easing: 'easeOutCirc', duration: 1000 } );
		
		}else{
			
			$("div#gallery_wrap").animate({ marginLeft : - galleryItem * 500 }, { easing: 'easeOutCirc', duration: 500 } );
		
		}
		setCurrentNumber();
		return false;
		
	});
	
	//Animation on back click
	
	$("a#back").click(function() {
		
		galleryItem --;
		
		if(galleryItem < 0) {
			
			galleryItem = galleryItems -1;
			$("div#gallery_wrap").animate({ marginLeft : - galleryItem * 500 },{ easing: 'easeOutCirc', duration: 1000 } );
		
		}else{
			
			$("div#gallery_wrap").animate({ marginLeft : - galleryItem * 500 },{ easing: 'easeOutCirc', duration: 500 } );
		}
		setCurrentNumber();
		return false;
	});
	
});

