$(document).ready(function() {
var anim_id;
	// set up anim
	var anim_con = $('.anim_window ul');
	var num_items = $('.anim_window li').length;
	var wrapper_width = $('.anim_window li').width();
	var max_move = ((wrapper_width * num_items) - wrapper_width)
        var speed = 500;

	$(anim_con).css({'width' : num_items * wrapper_width});

	$('.anim .wall a').click(function(event) {
		event.preventDefault();
		clearInterval(anim_id);
		var index = $('.anim .wall a').index(this);
		$('.anim .wall a').each(function(index) {
			$(this).removeClass('active');
		});
		$(this).addClass('active');
		move_wrapper(index)
	});
	function move_wrapper(index)
	{
		var position = parseInt($(anim_con).position());
		var move_to = -parseInt((wrapper_width * index))
			$(anim_con).animate({
				left: move_to
			  }, speed, function() {
				// Animation complete.
				rotate();
			 });
	}
	// stop anim on hover
	/*$(".anim .anim_window li .bigIm").hover(
	  function () {
		clearInterval(anim_id);
		$(anim_con).stop();
	  },
	  function () {
		rotate();
	  });*/

	function rotate()
	{
		anim_id = setInterval('anim()', 3000);
	}

	anim = function()
	{
		var listItem = $('.wall .active');
		var index = $('.wall a').index(listItem) + 1;
		var position = parseInt($(anim_con).position());
		var move_to = -parseInt((wrapper_width * index))
		if(index < num_items) {
			$(anim_con).animate({
				left: move_to
			  }, speed, function() {
				// Animation complete.
				$('.anim .wall .active').next().addClass("active");
				$(listItem).removeClass('active');
			 });
		} else {
			$(anim_con).animate({
				left: '0'
			  }, speed, function() {
				// Animation complete.
				$(listItem).removeClass('active');
				$('.anim .wall a').first().addClass("active");
			 });
		}

	}
	rotate();
});



