var pic_changeinterval = 4500;

var pic_current = 0;
var pic_current_opacity = 1;

setInterval("FadeInImage('foregroundimg','backgrounddiv')", pic_changeinterval);

//fadePics();

/*loadPics();

function loadPics()
{
	var objDiv 		= document.getElementById("imagecycle_old");
	var objDiv2		= document.getElementById("imagecycle_new");
	
	++pic_current;
	if (pic_current >= pic_array.length)
		pic_current = 0;
	
	objDiv2.style.background = "url("+pic_array[pic_current]+") no-repeat center center";
	objDiv.style.background = objDiv2.style.background;
	
	pic_current_opacity = 1;

	if (typeof objDiv2.style.opacity == "string")
	{
		objDiv2.style.opacity = pic_current_opacity / 100;
	}
	else
	{
		objDiv2.style.filter = "alpha(opacity="+pic_current_opacity+")";
	}
	setTimeout("fadePics()", pic_fadeinterval);
	
//	setTimeout("fadeinPics()", pic_fadeinterval);
}*/

/*
function fadeoutPics()
{
	var objDiv 		= document.getElementById("imagecycle_old");
	var objDiv2		= document.getElementById("imagecycle_new");
	
	pic_current_opacity -= pic_fadestep;
	
	if (pic_current_opacity < 1)
		pic_current_opacity = 1;
	
	if (typeof objDiv.style.opacity == "string")
	{
		objDiv.style.opacity = pic_current_opacity / 100;
	}
	else
	{
		objDiv.style.filter = "alpha(opacity="+pic_current_opacity+")";
	}

	if (pic_current_opacity > 1)
	{
		setTimeout("fadeoutPics()", pic_fadeinterval);
	}
	else
	{
		setTimeout("loadPics()", pic_fadeinterval);
	}
}

function fadeinPics()
{
	var objDiv 		= document.getElementById("imagecycle_old");
	var objDiv2		= document.getElementById("imagecycle_new");

	pic_current_opacity += pic_fadestep;
	
	if (pic_current_opacity > 100)
		pic_current_opacity = 100;

	if (typeof objDiv.style.opacity == "string")
	{
		objDiv.style.opacity = pic_current_opacity / 100;
	}
	else
	{
		objDiv.style.filter = "alpha(opacity="+pic_current_opacity+")";
	}

	if (pic_current_opacity < 100)
	{
		setTimeout("fadeinPics()", pic_fadeinterval);
	}
	else
	{
		setTimeout("fadeoutPics()", pic_changeinterval);
	}
}
*/
/*function fadeIn()
{
	var objDiv		=	document.getElementById("imagecycle_old");
	var objDiv2		=	document.getElementById("imagecycle_new");

	pic_current_opacity		+=	pic_fadestep;
	
	if (pic_current_opacity > 100)
		pic_current_opacity = 100;
		
	alert (pic_current_opacity);

	objDiv2.style.opacity = ""+(pic_current_opacity / 100);
	objDiv2.style.filter = "alpha(opacity="+pic_current_opacity+")";

	if (pic_current_opacity < 100)
	{
		setTimeout("fadeIn()", pic_fadeinterval);
	}
	else
	{
		setTimeout("fadePics()",pic_changeinterval);
	}
	
}

function fadePics()
{
	var objDiv		=	document.getElementById("imagecycle_old");
	var objDiv2		=	document.getElementById("imagecycle_new");
	
	++pic_current;
	
	if (pic_current >= pic_array.length)
		pic_current = 0;
		
	pic_current_opacity = 1;
	
/*	if (typeof objDiv2.style.opacity == "string")
	{
		objDiv2.style.opacity = pic_current_opacity / 100;
	}
	else
	{
		objDiv2.style.filter = "alpha(opacity="+pic_current_opacity+")";
	}
*/	
/*	objDiv.style.background		=	"url("+pic_array[pic_current-1]+") no-repeat center center";
	objDiv2.style.background 	= 	"url("+pic_array[pic_current]+") no-repeat center center";
	alert (objDiv2.style.background + "\n\n" + objDiv.style.background);
	
	setTimeout("fadeIn()", pic_fadeinterval);
	
}
*/

// Opacity and Fade in script.
// Script copyright (C) 2008 http://www.cryer.co.uk/.
// Script is free to use provided this copyright header is included.
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 opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
function FadeInImage(foregroundID,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  
  ++pic_current;
  
  if (pic_current >= pic_array.length)
	pic_current = 0;
	
  var newImage = pic_array[pic_current];
	
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = foreground.style.backgroundImage;
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.style.backgroundImage = "url("+newImage+")";
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10);
}
