(function($) {
$(document).ready(function() {
	var interval = 8000;
	var no = 1;
	var num = $('#slider > div#slider-images > *').length;
	var animating = false;
	
	$('#slider > div#slider-images > *').each(function(i, obj) {
		$(obj).css('z-index', num);
	});
	$('#slider > div#slider-images > *:not(:first-child)')
		.css('left', $('#slider').outerWidth());
	
	$('#arrRight').click(function() {
		if (animating) return;
		animating = true;
		
		var tmp = no;
		if (--no < 1) {
			no = num;
		}
		$('#slider > div#slider-images > *:nth-child('+no+')')
			.css('z-index', num+1)
			.css('left', '-'+$('#slider').outerWidth()+'px')
			.animate(
				{left:'0px'},
				{
					duration:'normal',
					easing:'easeOutCubic',
					complete:function() {
						$(this).css('z-index', num);
						animating = false;
					}
				}
			);
		$('#slider > div#slider-images > *:nth-child('+tmp+')')
			.animate(
				{left:parseInt($('#slider').outerWidth())+'px'},
				{
					duration:'normal',
					easing:'easeOutCubic',
					complete:function() {
						$('#slider > div#slider-images > *:nth-child('+tmp+')')
							.css('left', $('#slider').outerWidth());
					}
				}
			);
	});
	$('#arrLeft').click(function() {
		if (animating) return;
		animating = true;
		
		var tmp = no;
		if (++no > num) {
			no = 1;
		}
		$('#slider > div#slider-images > *:nth-child('+no+')')
			.css('z-index', num+1)
			.css('left', parseInt($('#slider').outerWidth())+'px')
			.animate(
				{left:'0px'},
				{
					duration:'normal',
					easing:'easeOutCubic',
					complete:function() {
						$(this).css('z-index', num);
						animating = false;
					}
				}
			);
		$('#slider > div#slider-images > *:nth-child('+tmp+')')
			.animate(
				{left:-parseInt($('#slider').outerWidth())+'px'},
				{
					duration:'normal',
					easing:'easeOutCubic',
					complete:function() {
						$('#slider > div#slider-images > *:nth-child('+tmp+')')
							.css('left', $('#slider').outerWidth());
					}
				}
			);
	});
	var timer = setInterval(function() {
		$('#arrLeft').click();
	}, interval);
	$('#slider').hover(function() {
		if (timer) {
			clearInterval(timer);
			timer = null;
		}
	}, function() {
		if (timer) {
			clearInterval(timer);
		}
		timer = setInterval(function() {
			$('#arrLeft').click();
		}, interval);
	});
});
})(jQuery);

