var opValue = 0.1;
var hilo;
//============================================================================================================================================================
window.size = function()
{
   var w = 0;
   var h = 0;
   //IE
   if(!window.innerWidth){
      //strict mode
      if(!(document.documentElement.clientWidth == 0)){
         w = document.documentElement.clientWidth;
         h = document.documentElement.clientHeight;
      }
      //quirks mode
      else{
         w = document.body.clientWidth;
         h = document.body.clientHeight;
      }
   }
   //w3c
   else{
      w = window.innerWidth;
      h = window.innerHeight;
   }
   return {width:w,height:h};
}
//============================================================================================================================================================
/**
* Función que calcula el centro de la ventana actual o de un rectángulo de
* las dimensiones que se le pasen, devuelve el vértice superior izquierdo
*
*/
window.center = function(){
   var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
   var _x = 0;
   var _y = 0;
   var offsetX = 0;
   var offsetY = 0;
   //IE
   if(!window.pageYOffset)
   {
      //strict mode
      if(!(document.documentElement.scrollTop == 0)){
         offsetY = document.documentElement.scrollTop;
         offsetX = document.documentElement.scrollLeft;
      }
      //quirks mode
      else{
         offsetY = document.body.scrollTop;
         offsetX = document.body.scrollLeft;
      }
   }
   //w3c
   else{
      offsetX = window.pageXOffset;
      offsetY = window.pageYOffset;
   }
   _x = ((this.size().width-hWnd.width)/2)+offsetX;
   _y = ((this.size().height-hWnd.height)/2)+offsetY;
   return{x:_x,y:_y};
}
//============================================================================================================================================================
function showDiv(capaId, numNoticias)
{
	//Antes de mostrar ninguna notica oculto todas las posibles mostradas
	hideAll(numNoticias);
	//alert('capaId:' + capaId);
	var miCapa = document.getElementById(capaId);
	if (miCapa)
	{
		var punto = window.center({width:660,height:400});
		//alert('x: ' + punto.x  + '; y: ' + punto.y);
        miCapa.style.top = punto.y + "px";
		//centro la capa en el eje y
        miCapa.style.left = punto.x + "px";
		//centro la capa en el eje x
        miCapa.style.display="block";
		//muestro la capa
	}
	var opFunc = 'setOpacity("' + capaId + '")';
	//alert(opFunc);
	hilo = setInterval(opFunc, 70);
}
//============================================================================================================================================================
function applyOpacity(capa)
{
	capa.style.opacity = opValue;
	capa.style.filter = 'alpha(opacity=' + opValue*100 + ')';
}
//============================================================================================================================================================
function setOpacity(capaId)
{
	var capa = document.getElementById(capaId);
	//alert(capa);
	if (opValue < 1)
	{
		applyOpacity(capa);
		opValue = opValue + 0.1;
	}
	else
	{
		clearInterval(hilo);
	}
	
}
//============================================================================================================================================================
function hideDiv(capaId)
{
	var miCapa = document.getElementById(capaId);
	miCapa.style.display="none";
	opValue = 0.1;
	applyOpacity(miCapa);
	
}
//============================================================================================================================================================
/**
 * Oculta todas las noticias en funcion del numero de noticias que existen recibido como parametro
 */
function hideAll(numNoticias)
{
	for (i=0; i<numNoticias; i++)
	{
		hideDiv('noticia' + i);
	}
}
