//=======================
//
// Fading Image Slideshow
//
// http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11510
//
//=======================


var slideshowFadeAnimate = new Array();
var slidetext   = new Array();
var slideshowFadeTimer   = new Array();
var slideshowFadeCount   = new Array();
var slideshowFadeImages  = new Array();


//======================


function slideshowFade(id,cl,images, fadeInterval,holdTime, width, height, text)
{

  if(cl)
    cl = ' class="'+cl+'"';
//alert('<div id="'+id+'"'+cl+'>')
  //document.write('<div id="'+id+'"'+cl+'><img id="'+id+'img" onload="slideshowFadeRun(\''+id+'\')"/></div>');
  document.write('<img width="'+width+'px" height="'+height+'px" id="'+id+'img" onload="slideshowFadeRun(\''+id+'\')"/><br />');
  
  var ss = document.getElementById(id+'img');
  if(ss.addEventListener)
  {
    ss.addEventListener('mouseover',function(){slideshowFadeMouseover(id)},false);
    ss.addEventListener('mouseout',function(){slideshowFadeMouseout(id)},false);
  }
  else if(ss.attachEvent)
  {
    ss.attachEvent('onmouseover',function(){slideshowFadeMouseover(id)});
    ss.attachEvent('onmouseout',function(){slideshowFadeMouseout(id)},false);
  }
  
  slideshowFadeCount[id]   = 0;
  slideshowFadeImages[id]  = images;
  slidetext[id]  = text;
  slideshowFadeAnimate[id] = 'run';
  slideshowFadeTimer[id]   = setInterval('slideshowFadeAnimation(\''+id+'\',\''+holdTime+'\');',fadeInterval);

}


//======================


function slideshowFadeAnimation(id,holdTime)
{
  if(slideshowFadeAnimate[id]=='run')
  {
    var obj = document.getElementById(id+'img');
    var opa = slideshowFadeCount[id]%200;
	
    if(opa==0)
    {
      slideshowFadeAnimate[id] = 'load';
      obj.src = slideshowFadeImages[id][Math.floor(slideshowFadeCount[id]/200)%slideshowFadeImages[id].length];
	  
	  // Code for 3 boxes at once with changing colours
	  //document.getElementById('fader').innerHTML = slidetext[id][Math.floor(slideshowFadeCount[id]/200)%slideshowFadeImages[id].length];;
	  //document.getElementById('text0').style.backgroundColor = "#becad1";
	  //document.getElementById('text1').style.backgroundColor = "#becad1";
	  //document.getElementById('text2').style.backgroundColor = "#becad1";
	  //document.getElementById('text0').style.color = "#000";
	  //document.getElementById('text1').style.color = "#000";
	  //document.getElementById('text2').style.color = "#000";
	  //document.getElementById('text'+Math.floor(slideshowFadeCount[id]/200)%slideshowFadeImages[id].length).style.backgroundColor = "#0d96b4";
	  //document.getElementById('text'+Math.floor(slideshowFadeCount[id]/200)%slideshowFadeImages[id].length).style.color = "#fff";
	  
	  // Code for 1 box
	  document.getElementById('slidetext').innerHTML = slidetext[id][Math.floor(slideshowFadeCount[id]/200)%slideshowFadeImages[id].length];;
    }
    else if(opa==100)
    {
      slideshowFadeAnimate[id] = 'hold';
      setTimeout('slideshowFadeRun(\''+id+'\')',holdTime);
    }
    else if(opa>100)
      opa = 200-opa;
      
    obj.style.opacity = (opa/100).toString();
    obj.style.filter  = "alpha(opacity="+opa.toString()+")";
    
    slideshowFadeCount[id]++;
    
    if(slideshowFadeCount[id]==(slideshowFadeImages[id].length*200))
      slideshowFadeCount[id]=0;
  }
}


//======================


function slideshowFadeMouseout(id)
{
  if(slideshowFadeAnimate[id]=='mouseover')
    slideshowFadeAnimate[id] = 'run';
}


//======================


function slideshowFadeMouseover(id)
{
  if(slideshowFadeAnimate[id]=='run')
  {
    slideshowFadeAnimate[id] = 'mouseover';
    var obj = document.getElementById(id+'img');
    obj.style.opacity = "1";
    obj.style.filter  = "alpha(opacity=100)";
    slideshowFadeCount[id] = (Math.floor(slideshowFadeCount[id]/200)*200)+101;
  }
}


//======================


function slideshowFadeRun(id)
{
  slideshowFadeAnimate[id] = 'run';
}


//======================
