var current = 0;
var aHeaders = new Array();
var current_header = "link_header_1";
var activeProcess = false;

$(document).ready(function(){
	$(".video_1").colorbox();
	$("#slideshow").find(".imghead").each(function(){
		aHeaders.push($(this).attr("id"));
	});
	autoSlide = setInterval("slide()",6200);

        testimonialAutoSlide = setInterval("testimonial_slide()",20000);
	
	$("#slideshow .morelinkslide").click(function(){
		clearInterval(autoSlide);
		if(activeProcess==false){
			if($(this).attr("id") != current_header){
				header_amagar = "#"+current_header.replace("link_","");
				header_mostrar = "#"+$(this).attr("id").replace("link_","");
				$("#"+current_header).removeClass("selectedlinkslide");
				$("#"+$(this).attr("id")).addClass("selectedlinkslide");
				activeProcess = true;
				$(header_amagar).fadeOut(300, function() {
					$(header_mostrar).fadeIn(300, function(){
							activeProcess = false;
					});
				});
				current_header = $(this).attr("id");
			}
		}
	});
});

function slide(){
	header_amagar = aHeaders[current];
	if((parseInt(current)+1) < aHeaders.length){
		current = parseInt(current) + 1;
	}else {
		current = 0;
	}
	header_mostrar = aHeaders[current];
	$("#link_"+header_amagar).removeClass("selectedlinkslide");
	$("#link_"+header_mostrar).addClass("selectedlinkslide");
	current_header = "link_header_"+(parseInt(current)+1);
	$("#"+header_amagar).fadeOut(500, function() {
		$("#"+header_mostrar).fadeIn(500);
	});
}
function testimonial_slide(){
    
    $(".testimonios").find(".visible").each(function(){
        $(this).fadeOut(200,function(){
            $(this).removeClass("visible");
            $(this).addClass("invisible");

            if($(this).next(".invisible").attr("id") != null){
                $(this).next(".invisible").fadeIn(200,function(){
                    $(this).removeClass("invisible").addClass("visible");
                });
            } else {
                $(".testimonios .invisible:first").fadeIn(200,function(){
                    $(this).removeClass("invisible").addClass("visible");
                });
            }        
        });  
    });
}
