$(document).ready(function() {
/*COLOCACIONES*/
	$(".paging a:first").addClass("active");
	
	//Rotation + Timing Event
	rotate = function(){
		var mov = 732;
		$(".image_reel").animate({ 
			left: -mov
		},20000, 'linear', function(){
				$(".image_reel").css('left','0');
				rotate();
			});
	};
	
	
	rotateSwitch = function(){
		play = setInterval(function(){
			$(".image_reel").css('left','0');
			rotate();
		},18000);
	};
	rotate();
	
	//On Hover
	$(".image_reel div").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	$(".image_reelFondo a").click(function(event){
		event.preventDefault();
		window.open('apertura.html','apertura','width=660,height=436');
	});

	//On Click
	$(".paging div").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
/*FONDOS*/
	$(".pagingFondo a:first").addClass("active");
	//Paging + Slider Function
	rotateF = function(){
		$(".pagingFondo a").fadeOut('slow'); //Remove all active class
		$activeF.fadeIn('slow');
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitchF = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$shown = $(".show");
			$hidden= $(".hidden");
			$shown.fadeOut('slow');
			$hidden.fadeIn('slow');
			$shown.removeClass('show');
			$shown.addClass('hidden');
			$hidden.removeClass('hidden');
			$hidden.addClass('show');
		}, 3000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitchF(); //Run function on launch
	
	//On Hover
	$(".image_reelFondo a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});
	
	//On Click
	$(".pagingFondo a").click(function() {	
		$activeF = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});		
});
