//variables intervalo
var intervaloProximo;
var proximoActual = 1;
var totalProximo;
var segundos = 4;

var ancho = 525;
var indice = 0; 

$(document).ready(inicia);


function inicia() {
	
	$("#contenido").hide();
	$("#contenido").fadeIn(500);
	
	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('h4');
	Cufon.replace('h5');
	Cufon.replace('h6');
	Cufon.replace('#tquienes');
	Cufon.replace('#stquienes');
	Cufon.replace('#menu a', {hover: true});

	
  
  $('#bg').css({opacity:".6"});
  $('#bg100').css({opacity:".6"});
  $('#bg_servicios').css({opacity:".6"});  
  $('#flecha').css({opacity:"0"});

  
  menu();
  
  
  // REPETIMOS LA PRIMERA FOTO DENTRO DE CARRUSEL PARA EFECTO
	$("#carrusel").css({width:"2625px" }).append('<div class="destacado"><img src="img/carrusel/1.jpg"/></div>');
	 //intervalo
	totalProximo = $(".carrusel div").length;
	clearInterval(intervaloProximo);
	intervaloProximo = setInterval(muestraProximo, segundos*3000); 
  
  //acordeon
	$("#submenu h4").click(muestraLista);
}


//acordeon


function muestraLista(){
	$("#submenu ul").slideUp();
	$(this).next().stop().slideDown();
}
  


function menu(){
	
	
	$("#1").hover(
      function () {	
		$('#flecha').stop().animate({left: "35px", opacity:"1"}, 200);
      }, 
      function () {
		$("#flecha").stop().animate({ left: "0", opacity:"0"}, 200);
      }
    );
	
	$("#2").hover(
      function () {	
		$('#flecha').stop().animate({left: "140px", opacity:"1"}, 200);
      }, 
      function () {
		$("#flecha").stop().animate({ left: "0", opacity:"0"}, 200);
      }
    );
		
	$("#3").hover(
      function () {	
		$('#flecha').stop().animate({left: "260px", opacity:"1"}, 200);
      }, 
      function () {
		$("#flecha").stop().animate({ left: "0", opacity:"0"}, 200);
      }
    );
			
	$("#4").hover(
      function () {	
		$('#flecha').stop().animate({left: "356px", opacity:"1"}, 200);
      }, 
      function () {
		$("#flecha").stop().animate({ left: "0", opacity:"0"}, 200);
      }
    );
	
	$("#5").hover(
      function () {	
		$('#flecha').stop().animate({left: "450px", opacity:"1"}, 200);
      }, 
      function () {
		$("#flecha").stop().animate({ left: "0", opacity:"0"}, 200);
      }
    );
	
}


//intervalo
function muestraProximo(){
		indice++;
		if (indice>3){
		$("#carrusel").css({marginLeft:"0px" });
		indice = 1;
		}
		mueveCarrusel()
		return false;
}

function mueveCarrusel(){
		var posicion = -indice*ancho;
		$("#carrusel").stop().animate({marginLeft:posicion+"px" }, 300);
} 


// Slide de Servicios //

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow2 IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow2 IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow2 IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});




