var cont = 1;
var tiempo_carga = 5000;
var time;
$(document).ready(function(){
	_crearPaginador();
		
	$(".tiempo_nro").live("click", function(evento){
		evento.preventDefault();
		if ($("#pausa a").attr("class")=="detener")
			{
				clearInterval(time);
				time = setInterval("_banner()",tiempo_carga);
			}
		cont = $(this).text() - 1;
		_banner();
	});
	
	$(".detener").live("click",function(evento){
		evento.preventDefault();
		clearInterval(time);			
		$(this).addClass("iniciar").removeClass("detener");
		$("#accion").attr("src","estilos/2010/bitmaps/play.png");
	});

	$(".iniciar").live("click",function(evento){
		evento.preventDefault();
		time = setInterval("_banner()",tiempo_carga);
		$(this).addClass("detener").removeClass("iniciar");
		$("#accion").attr("src","estilos/2010/bitmaps/pause.png");
	});	
})

function _banner(){
	var total = _cantidadBanner();
	if (cont >= total) cont=1;
	else ++cont;
	
	var actual = $(".seleccionado").text();
	$(".seleccionado").removeClass("seleccionado");
	$("#" + cont).addClass("seleccionado");
	
	$('#banner' + actual).fadeOut("fast", function(){
		$('#banner' + cont).css("opacity","0").show().animate({"opacity":"1"}, "fast");
	});
}

function _crearPaginador()
{
	$('div.banner_contenedor').load('banner_central/banner.asp',function(){
		$("div .banner_contenedor div").each(function(i){
			$(this).attr("id", "banner" + (i + 1));
			$(".banner_tiempo").append('<li id="'+ (i + 1) +'"><a href="#" class="tiempo_nro">'+ (i + 1) +'</a></li>');
		});
		
		var total = _cantidadBanner();
		if (total > 1)
			{
				$(".banner_tiempo").append('<li id="pausa"><a href="#" class="detener"><img id="accion" src="estilos/2010/bitmaps/pause.png" border="0" /></a></li>');
				$("#1").addClass("seleccionado");
				
				time = setInterval("_banner()",tiempo_carga);
			}
		else
			$(".banner_tiempo").remove();
    });
}

function _cantidadBanner(){
	return $(".tiempo_nro").length;
}

