jQuery(document).ready(function($) {

	count = $('.sliderPostWrapper').size();
	current = 1;
	timeron = 1;
	moving = 0;
	

	$('.sliderImg').not(':eq(0)').animate({
		'opacity' : '0'
	}, 1);
	
	$('.sliderPostWrapper').not(':eq(0)').animate({
		'opacity' : '0'
	}, 1);
	
	$.timer(4000, function (timer) {
	
		if(timeron == 0) { timer.stop(); }
		
		if(current < count && timeron == 1) {
			moving = 1;
			
			$('.sliderImg:eq(' + (current-1) + ')').animate({
			'opacity': '0'
			}, 200, function() {
				current++;
				$('.sliderPostWrapper').not(':eq(' + (current-1) + ')').animate({
					'opacity': '0', 
					'top': '+=100px'
				}, 100);
				$('.sliderPostWrapper:eq(' + (current-1) + ')').animate({
					'opacity': '1', 
					'top': '+=200'
				}, 300);
				$('#sliderWrapper').animate({
				'left': '-=901px'
				}, 300, function() {
					$('.sliderImg:eq(' + (current-1) + ')').animate({
					'opacity': '1'
					}, 200);
					moving = 0;
				});
			});
		}
		
  	});
	
	
	
	$('.sliderControlLeft').click(function(event) {
		event.preventDefault();

		if(current > 1 && moving == 0) {
				moving = 1;
				/*$('.sliderContent:eq(' + (current-1) + ')').animate({
					'top' : '+=80px', 
					'opacity': '0'
				}, 300, function() {
					current--;
					$('#sliderWrapper').animate({
						"left": "+=525px"
					}, 400, function() {
						$('.sliderContent:eq('+ (current-1) +')').animate({
							'top' : '-=80px', 
							'opacity': '0.8'
						}, 300, function() {
							moving = 0;
						});
					});
				});*/
				
				$('.sliderImg:eq(' + (current-1) + ')').animate({
					'opacity': '0'
				}, 200, function() {
					current--;
					$('.sliderPostWrapper').not(':eq(' + (current-1) + ')').animate({
						'opacity': '0' 
					}, 100);
					$('.sliderPostWrapper:eq(' + (current-1) + ')').animate({
						'opacity': '1'
					}, 300);
					$('#sliderWrapper').animate({
					'left': '+=901px'
					}, 300, function() {
						$('.sliderImg:eq(' + (current-1) + ')').animate({
						'opacity': '1'
						}, 200);
						moving = 0;
					});
				});
		}
		timeron = 0;
	
	});
	
	$('.sliderControlRight').click(function(event) {
		event.preventDefault();

		if(current < count && moving == 0) {
			moving = 1;
		
				/*$('.sliderContent:eq(' + (current-1) + ')').animate({
					'top' : '+=80px', 
					'opacity': '0'
				}, 300, function() {
					current++;
					$('#sliderWrapper').animate({
						"left": "-=525px"
					}, 400, function() {
						$('.sliderContent:eq('+ (current-1) +')').animate({
							'top' : '-=80px', 
							'opacity': '0.8'
						}, 300, function() {
							moving = 0;
						});
					});
				});*/
				
				$('.sliderImg:eq(' + (current-1) + ')').animate({
					'opacity': '0'
				}, 200, function() {
					current++;
					$('.sliderPostWrapper').not(':eq(' + (current-1) + ')').animate({
						'opacity': '0', 
						'top': '+=100px'
					}, 100);
					$('.sliderPostWrapper:eq(' + (current-1) + ')').animate({
						'opacity': '1', 
						'top': '+=200'
					}, 300);
					$('#sliderWrapper').animate({
					'left': '-=901px'
					}, 300, function() {
						$('.sliderImg:eq(' + (current-1) + ')').animate({
						'opacity': '1'
						}, 200);
						moving = 0;
					});
				});

		}
		timeron = 0;
	
	});

});