// Documento JavaScript


var cant_noticias = 3;
var ver_noticia = -1;
var time = 0;
var transparency = 0;
var transparency_prev = 0;
var noti = 0;
var noti_prev = -1;
var in_transition = 0;

function init(cant){
	var k = 0;
	transparency = 0;
	for ( var i = 0; i < cant; i++ ) {
		obj = eval("document.getElementById('not_" + i + "')");
		if(obj){
			obj.style.visibility = 'hidden';
			if (document.all){
				//esto es para IE, como siempre hay q programarlo a parte
				obj.style.filter = 'alpha(opacity='+transparency+')';
			}else{
				// Safari 1.2, posterior Firefox y Mozilla, CSS3
				obj.style.opacity = transparency /100;
				// anteriores Mozilla y Firefox
				obj.style.MozOpacity = transparency /100;

				// Safari anterior a 1.2, Konqueror
				obj.style.KHTMLOpacity = transparency /100;  
			}

			//NO BORRAR LAS SIGUIENTES 2 LINEAS O DEJA DE FUNCIONAR EN IE
			//SI SE PUEDEN MODIFICAR LOS VALORES PERO NO SE PUEDEN BORRAR
			obj.style.width = '485px';
			//obj.style.height = '200px';

			k++;
		}
	}
}


function transition(noti,transparency) {
	obj = eval("document.getElementById('not_" + noti + "')");
	if(obj){
		if(transparency <= 0)
			obj.style.visibility = 'hidden';
		else obj.style.visibility = 'visible';
		if (document.all){
			//esto es para IE, como siempre hay q programarlo a parte
			obj.style.filter = 'alpha(opacity='+transparency+')';
		}else{
			// Safari 1.2, posterior Firefox y Mozilla, CSS3
			obj.style.opacity = transparency /100;

			// anteriores Mozilla y Firefox
			obj.style.MozOpacity = transparency /100;

			// Safari anterior a 1.2, Konqueror
			obj.style.KHTMLOpacity = transparency /100;  
		}
		return true;
	}else return false;
};


function clic(num){
	if(ver_noticia == num && !in_transition){
		ver_noticia = -1;
		time = 0;
		if (num != noti){
			noti_prev = noti;
			transparency_prev = 90
			transition(noti_prev,transparency_prev);
		}
		noti = num;
		transparency = 10;
	}
}


function noticias() {
	clic(0);
	clic(1);
	clic(2);
	
	if(transparency != 100){
		in_transition = 1;
		transparency_prev -= 10;
		transition(noti_prev,transparency_prev);
		transparency += 10;
		transition(noti,transparency);
	}else{
		in_transition = 0;
		time++;
		if(time == 100){
			time = 0;
			noti_prev = noti;
			noti = (noti +1) % cant_noticias;
			transparency_prev = 90
			transition(noti,transparency_prev);
			transparency = 10;
			while(!transition(noti,transparency) && (noti != noti_prev)){
				noti = (noti +1) % cant_noticias;
			}
		}
	}

	
}


window.onload = function() {
  setInterval('noticias()',100);
};

