$(document).ready(function() {

	/* datos contacto buttons */
	$('a.mundo').click(function(){
		$('.datos_contacto').show();
	});
	
	$('a.cerrar').click(function(){
		$('.datos_contacto').hide();
	});
	
	$('a.imprimir').click(function(){
		window.print();
	});
		
	/* slides */
	switches 	= $('.menu li a');
	slides 		= $('.aside');
	testigo 	= $('.sprites.testigo'); 
	switches.each(function() {}).hover (
    function() {
        slides.hide();
        testigo.removeClass('historia');
        testigo.removeClass('servicios');
        testigo.removeClass('equipo');
        testigo.removeClass('contactos');
        testigo.addClass($(this).attr('id'));
		$('.aside.' + $(this).attr('id')).show();
		           
    });
        
    /* galeria de posts destacados */
    
    /* conf */
    var currentPanel = 1;
    var navClicks = 0;
    var autoSlideInterval = 10000;
    var slider = $('.post_destacados');
    var panelWidth = slider.find('.panel').width();
	var panelCount = slider.find('.panel').size();
	var panelContainerWidth = panelWidth*panelCount;
	slider.css({ width: panelContainerWidth });
	
	/* botones */
	$('.navegador-articulos a.icon.punto').each(function(z) {
		$(this).bind('click', function() {
			navClicks++;
			offset = - (panelWidth*z);
			currentPanel = z + 1;
			updatePreview();
		});
	});
	
	/* prev */
	$('.navegador-articulos a.icon.prev').click(function() {
		navClicks++;
		if (currentPanel == 1) {
			offset = - (panelWidth * (panelCount - 1));
			currentPanel = panelCount;
		} else {
			currentPanel -= 1;
			offset = - (panelWidth * (currentPanel - 1));
		};
		updatePreview();
		return false;
	});
		
	/* next */
	$('.navegador-articulos a.icon.next').click(function() {
		navClicks++;
		if (currentPanel == panelCount) {
			offset = 0;
			currentPanel = 1;
		} else {
			offset = - (panelWidth * currentPanel);
			currentPanel += 1;
		};
		updatePreview();
		return false;
	});
	
	var updatePreview = function () {
		$('.navegador-articulos').find('a.amarillo').removeClass('amarillo');
		$('.navegador-articulos').find('a').addClass('blanco');
		$('.navegador-articulos').find('#destacado_' + (currentPanel-1)).addClass('amarillo');
		$(slider).animate({ marginLeft: offset }, 1000, 'easeInOutExpo');
	}
	
	var autoSlide = function () {
		if (navClicks == 0) {
			if (currentPanel == panelCount) {
				offset = 0;
				currentPanel = 1;
			} else {
				offset = - (panelWidth * currentPanel);
				currentPanel += 1;
			};
			updatePreview();
			setTimeout(autoSlide, autoSlideInterval);
		};
	};
	
	setTimeout(autoSlide, autoSlideInterval);
    
});