$(document).ready(function() {
	
	var actual = 1;
	var timer;
	function sliderFade(){
		$('.slrc-'+actual).fadeOut('slow');
		$('.slrt-'+actual).fadeOut('slow');
				
		$(".slider-nav a").each(function(){		
			if ($(this).hasClass("active")) $(this).removeClass('active');
        });		
		
		actual++;
		
		if (actual >4 ) { actual=1; }
		
		$("#slider-nav-"+actual).addClass("active");
		
		$('.slrc-'+actual).fadeIn('slow');
		$('.slrt-'+actual).fadeIn('slow');	
	}
	function initTimer(){
		timer = setInterval(function(){sliderFade();}, 17000);
	}

	initTimer();
	
	$('.slider-nav a').click(function() {
		
		$(".slider-nav a").each(function(){		
			if ($(this).hasClass("active")) $(this).removeClass('active');
        });		
			
		var partsArray = $(this).attr("id").split('-');
		if (partsArray[2] != actual) {
			clearInterval(timer);
			$('.slrc-'+actual).fadeOut('slow');
			$('.slrt-'+actual).fadeOut('slow');
			actual = partsArray[2];
			$(this).addClass("active");
			$('.slrc-'+actual).fadeIn('slow');
			$('.slrt-'+actual).fadeIn('slow');
		}
		return false
	});	
	
});
