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


var ancho = 637;
var indice = 0;

var i = 0;//initialize
var int=0;//Internet Explorer Fix

$(document).ready(inicia);


function inicia() {
	
	$("#nav").hide();
	$("#nav").fadeIn(1000);	
	
	$(".fondo").css({ opacity:"0"});
	miniaturas();
	
	// REPETIMOS LA PRIMERA FOTO DENTRO DE CARRUSEL PARA EFECTO
	$("#carrusel").css({width:"2548px" }).append('<div class="destacado"><a href="#"><img class="cargadas" src="img/tenpel.jpg" /><h2>Tenpel - html, css, jquery</h2></a></div>');
	
	Cufon.replace('h2');
	
	//intervalo
	totalProximo = $(".carrusel div").length;
	clearInterval(intervaloProximo);
	intervaloProximo = setInterval(muestraProximo, segundos*1000);
	
	
	
	
		/*$('img.cargadas').hide();//hide all the images on the page*/
		
		
		$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
			var int = setInterval("doThis(i)",500);//500 is the fade in speed in milliseconds
		});

		
	
	
}/*cierre inicia*/


function doThis() {
			var imgs = $('img.cargadas').length;//count the number of images on the page
			if (i >= imgs) {// Loop the images
				clearInterval(int);//When it reaches the last image the loop ends
			}
			$('img:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
			i++;//add 1 to the count
		}




function miniaturas() {

$(".trabajo a").hover(
      function () {
		
		var identificador= $("this").attr("id");
		
		$(".fondo",this).fadeIn(150);
        $(".fondo",this).stop().animate({ top: "121px", opacity:"1"}, 150);
		$(".txtTrabajo", this).css({ color:"#03ACBD"});
		
		
      }, 
      function () {
		
		$(".fondo",this).fadeOut(150);
        $(".fondo",this).stop().animate({ top: "147px", opacity:"0"}, 150);
		$(".txtTrabajo", this).css({ color:"#333"});
      }
    );

}




//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);
}





