var IMAGEN_STOP_ON_JS   = 'imagenes/news/pause_on.gif';
var IMAGEN_STOP_OFF_JS  = 'imagenes/news/pause_off.gif';
var BANNER_PATH         = 'imagenes/home/banner/';

/*

CONTENIDOS

*/

var arrJs = new Array();
var iActualJs = -1;
var iContadorContenidos = 0;

var bAsincActivate = false;
var bBloqueada = false;
var iTiempoJs = 10000;

// Función la cual inicia la reproduccion.
function IniciarContenidos(iMax)
{  
    iMaxContenidosJs = iMax;
    
    if(iMaxContenidosJs < 2)
    {
        oReproductorJs.style.display = "none";
        oPaginadorJs.style.display = "none";
    }
	// ArmarContenido();
	
	previewContenido();
}

// Del array generado toma el HTML y lo muestra en el contenedor.
function ArmarContenido()
{
    if(oContenedorJs != null)
    {
	    oContenedorJs.innerHTML = arrJs[iActualJs];
	    
	    if(oPaginadorJs != null)
	    {
	        oPaginadorJs.innerHTML = (iActualJs+1).toString() + " / " + iMaxContenidosJs;
	    }
        
        oStop = document.getElementById('imgStop');
	    if(oStop != null)
	    {
		    if(bBloqueada)
			    oStop.src = IMAGEN_STOP_OFF_JS;
		    else
			    oStop.src = IMAGEN_STOP_ON_JS;
	    }
	}
}

// Funcion recursiva la cual se llama asi misma mostrando una tras otra.
function previewContenido()
{
	SiguienteContenido();	
	
	if(iMaxContenidosJs > 1)
	    iContadorContenidos = setTimeout("previewContenido()", iTiempoJs);
}

// Muestra el siguiente contenido.
function SiguienteContenido()
{
    iActualJs += 1;
    if(parseInt(iActualJs) > parseInt(iMaxContenidosJs) - 1)
	    iActualJs = 0;
		
	ArmarContenido();
}

// Muestra el contenido anterior.
function AnteriorContenido()
{
	iActualJs -= 1;
	if(iActualJs < 0)
		iActualJs = iMaxContenidosJs - 1;
	
	ArmarContenido();
}

// Si no esta bloqueado Frena el reproductor.
function FrenarContenido()
{
    oStop = document.getElementById('imgStop');
    if(oStop != null)
    {
	    if(!bBloqueada)
	    {
		    bBloqueada = true;
		    clearTimeout(iContadorContenidos);
		    oStop.src = IMAGEN_STOP_OFF_JS;
	    }else{
		    bBloqueada = false;
		    iContadorContenidos = setTimeout("previewContenido()", iTiempoJs);
		    oStop.src = IMAGEN_STOP_ON_JS;
	    }
	}
}

/*

BANNERS

*/
var iCantBannersJs = 3; // Cantidad total de banners a mostrar.
var iTiempoBannersJs = 6000; // Tiempo de espera entre banners.
var iBannerActualJs = 0
var iContadorBanners = 0;
var time;
var transparency = 0;

// Efecto de la imagen.
function fadeIn()
{
	if(oBanner != null)
	{
		//incrementamos el valor
		transparency += 10;
		
		//si termino la trnsicion borramos el intervalo
		if(transparency == 100)
		{
			clearInterval(time);
			transparency = 99.999;
		}
		
		if (document.all){
			//esto es para IE
		  	oBanner.style.filter = 'alpha(opacity='+Math.round(transparency)+')';
		}else{
			// Safari 1.2, posterior Firefox y Mozilla, CSS3
			oBanner.style.opacity = transparency /100;
			// anteriores Mozilla y Firefox
			oBanner.style.MozOpacity = transparency /100;
			// Safari anterior a 1.2, Konqueror
			oBanner.style.KHTMLOpacity = transparency /100;
		}
	}
}

// Muestro Banners.
function previewBanner()
{
    if(oBanner != null)
    {   	
    	// Verifico que el contador no supere el total.
    	iBannerActualJs++;
    	if(iBannerActualJs > iCantBannersJs)
    	    iBannerActualJs = 1;
    	
        // Hago transparente la imagen.
        transparency = -10;
	    fadeIn();

    	// Cargo la imagen.
    	oBanner.src = BANNER_PATH + iBannerActualJs.toString() + ".gif";
    	
	    // Empiezo a mostrar la imagen.
	    time = setInterval('fadeIn()',50);
	    
	    // Hago la recursividad.
	    iContadorBanners = setTimeout("previewBanner()", iTiempoBannersJs);
	}
}

