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


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




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

function slideshowFade(id,cl,imageArray,fadeInterval,holdTime)
{



  if(cl)
    cl = ' class="'+cl+'"';

	document.write('<div id="'+id+'"'+cl+'><a id="slideLink" href="#"><img id="'+id+'img" onload="slideshowFadeRun(\''+id+'\')"/></a></div>');
	
		

//	  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]  = imageArray;
  slideshowFadeAnimate[id] = 'run';
  slideshowFadeTimer[id]   = setInterval('slideshowFadeAnimation(\''+id+'\',\''+holdTime+'\');',fadeInterval);
}


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

var curname = 0 //count and IDs the current image

function slideshowFadeAnimation(id,holdTime)
{
		
  if(slideshowFadeAnimate[id]=='run')
  {
    var obj = document.getElementById(id+'img');
    var opa = slideshowFadeCount[id]%200;


    if(opa==0)
    {

	for(var i=0; i < nameArray.length; i++) { //Take the nameArray (sorted by number) and delete the numbers 
	nameArray[i] = nameArray[i].replace(/0|1|2|3|4|5|6|7|8|9/g, '');
	}

      slideshowFadeAnimate[id] = 'load';
      obj.src = slideshowFadeImages[id][Math.floor(slideshowFadeCount[id]/200)%slideshowFadeImages[id].length];

	  	if (document.getElementById("Nav-French").style.display == "block") // if Version Francaise - set DIR to artistes
		{
			document.getElementById("slideLink").setAttribute("href", "index.php?/artistes/" +  nameArray[curname]);
		}
		else //if English Version - set DIR to artists
		{
			document.getElementById("slideLink").setAttribute("href", "index.php?/artists/" +  nameArray[curname]);
		}
		
		if (curname == nameArray.length-1) //in any case, count the current image until the last array element
		{
		curname= 0;
		}
		else
		{	
		curname++
		}
	
    }
    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';
    	
}


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