/*VARIABLES ANUNCIOS*/
var totalAnuncios=0;
var contA=0;
var tiempoRetA=200;
/*FIN ANUNCIOS*/

/*VARIABLES BANNERS*/
var totalBanners=0;
var contB=0;
var tiempoRetB=2000;
var tiempoDurB=5000; //5 segundos
/*FIN BANNERS*/

$(document).ready (function ()
{
	inicializa_anuncio();
	inicializa_banner();
	$("#anuncio").animate({"opacity":0.30},1000);
});

function inicializa_banner()
{
	$("#slideshow a").css("opacity",0);	
	$("#slideshow a:first-child").addClass("zmayor");	
	$("#slideshow a:first-child").animate({"opacity":1},tiempoRetB);	
	totalBanners=$("#slideshow").children().length;
	setTimeout(anuncio,3000);
}

function inicializa_anuncio()
{
	$("#banner ul li").css("opacity",0);	
	$("#banner ul li:first-child").addClass("active");	
	$("#banner ul li:first-child").animate({"opacity":1},tiempoRetA);	
	totalAnuncios=$("#banner ul").children().length;
	setTimeout(banner,3000);
}

function anuncio()
{
	contA++;
	if(contA>totalAnuncios)
	{
		$("#banner ul li:first-child").addClass("active");	
		$("#banner ul li:first-child").animate({"opacity":1},tiempoRetA);	
		contA=0;
		setTimeout(anuncio,3000);
	}else{	
		var liAct=$("#banner ul li.active");
		liAct.removeClass("active");
		liAct.animate({"opacity":0},tiempoRetA);
		
		var sigLi=liAct.next();
		sigLi.animate({"opacity":1},tiempoRetA);
		sigLi.addClass("active");
		//alert("inicia");
		(contA==totalAnuncios)?setTimeout(anuncio,500):setTimeout(anuncio,3000);
		
		}
}


function banner()
{
	contB++;
	if(contB>totalBanners)
	{
		$("#slideshow a").removeClass("zmenor");
		$("#slideshow a:first-child").addClass("zmayor");	
		$("#slideshow a:first-child").animate({"opacity":1},tiempoRetB);	
		contB=0;
		setTimeout(banner,tiempoDurB);
	}else{	
		var aAct=$("#slideshow a.zmayor");
		
		$("#slideshow a").removeClass("zmenor");
		$("#slideshow a").removeClass("zmayor");
		
		aAct.removeClass("zmayor");
		aAct.addClass("zmenor");
		aAct.animate({"opacity":0},tiempoRetB);
		
		var sigA=aAct.next();
		sigA.addClass("zmayor");
		sigA.animate({"opacity":1},tiempoRetB);
		//alert("inicia");
		(contB==totalBanners)?setTimeout(banner,100):setTimeout(banner,tiempoDurB);
		}
}