var slideCache = new Array()
slideCache[0] = 'images/headlines/douglas.jpg';
slideCache[1] = 'images/headlines/kandi.jpg';
slideCache[2] = 'images/headlines/pope.jpg'
slideCache[3] = 'images/headlines/pope2.jpg';
slideCache[4] = 'images/headlines/sunset.jpg';
slideCache[5] = 'images/headlines/ordway.jpg';

var slideCount = slideCache.length;
var pictureID = "headline_img";
var backgroundID = "headline_bg";

var slideShowCache = new Array();
function preload(slideCache)
{
	for (x = 0; x < slideCache.length; x++){
		slideShowCache[x] = new Image();
		slideShowCache[x].src = slideCache[x];
	}
}

function autoslideshow(slide)
{
	slide++;
	if(slide == slideCount)
	{
		slide = 0;
	}	
	picture = slideCache[slide];		
	fadeIn(pictureID,picture,backgroundID);
	setTimeout("autoslideshow('"+slide+"')", displaySecs * 1000);
}

function fadeIn(foregroundID,newImage,backgroundID)
{
	var foreground=document.getElementById("headline_img");
	if(foreground !== null)
	{
		if (foreground.timer)
		{
			window.clearTimeout(foreground.timer);
		}
	}
  	if (backgroundID)
  	{
    	var background=document.getElementById(backgroundID);
    	if (background)
    	{
      		if (background.src)
      		{
        		foreground.src = background.src; 
        		setOpacity(foreground,100);
      		}
      		background.src = newImage;	  
      		background.style.backgroundImage = 'url(' + newImage + ')';
      		background.style.backgroundRepeat = 'no-repeat';
	  		var startMS = (new Date()).getTime();
      		foreground.timer = window.setTimeout("changeOpacity('" + foregroundID + "'," + fadeDuration + "," + startMS + ",100,0)",10);
    	}
	}
	else
	{
    	foreground.src = newImage;
  	}
}



function setOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}

function changeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    setOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    setOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    setOpacity(element,opacity);
    element.timer = window.setTimeout("changeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}

