var useFilters;
var displayTime;
var mozNonFadingTime;

//define the elementIds for a, image, id and info for each pic div

//the array names
var imgUrl_users;
var id_users;
var info_users;

//the arr length
var ARR_LEN_USERS;
   
function initSlideShow()
{
  //alert('hi');
  displayTime = 16000;
  mozNonFadingTime = displayTime - 1600; //6400;
  useFilters = getUseFilters();

  imgUrl_users = new Array();
  id_users = new Array();
  info_users = new Array();
  JSFrontPageInit();
  var rand = Math.round(20*Math.random()) ;
  var j = rand;
  playSlides(j, 0);
  j = rand;
  playSlides(j, 1);
  j = rand;
  playSlides(j, 2);
  j = rand;
  playSlides(j, 3); 
  j = rand;
  playSlides(j, 4);   
  j = rand;     
  playSlides(j, 5);
}

function getUseFilters()
{
  if (typeof window.document.body.filters != 'undefined')
  {
    return true;
  }
  else
  {
    return false;
  } 
}

function setOpacity(obj, val)
{
  if(typeof window.document.body.style.opacity != 'undefined') 
  {
    obj.style.opacity = val;
  } 
  else if(typeof window.document.body.style.MozOpacity != 'undefined') 
  {
    obj.style.MozOpacity = val;
  } 
  else if(typeof window.document.body.style.KhtmlOpacity != 'undefined') 
  {
    obj.style.KhtmlOpacity = val;
  } 
}

function playSlide(aRef, img, imgSrc, id, idVal, txt, txtVal, i)
{
  if (useFilters) 
  {    
    img.filters[0].Apply();    
    img.src = imgSrc;
    img.filters[0].Play();
  }
  else 
  {
    img.src = imgSrc;
    fadein(0.04, i);
  }
  //alert(idVal +' '+ txtVal+ ' ' + idVal);
  aRef.href = '/'+idVal+'/profile';
  txt.innerHTML = txtVal;
  id.innerHTML = idVal;
}

function fadein(opacity, i) 
{
  //alert('img_'+i);
  img_user = document.getElementById('img_'+i);
  if (opacity < 0.99) 
  {
    opacity += 0.05;
    setOpacity(img_user, opacity);
    setTimeout('fadein('+opacity+','+i+')', 50);
  }
  else 
  {
    setTimeout('fadeout('+1+','+i+')', mozNonFadingTime);
  }
}

function fadeout(opacity, i) 
{
  img_user = document.getElementById('img_'+i);
  if (opacity > 0.1) 
  {
    opacity -= 0.08;
    setOpacity(img_user, opacity);
    setTimeout('fadeout('+opacity+','+i+')', 50);
  }
}  

function playSlides(j, i)
{
  //alert(images_arr);
  a_user = document.getElementById('a_'+i);
  img_user = document.getElementById('img_'+i);
  idTxt_user = document.getElementById('idTxt_'+i);
  infoTxt_user = document.getElementById('infoTxt_'+i);
  
  j += 6;  
  if(j>(ARR_LEN_USERS-6)) 
  {
    j = 0;
  }
  //alert(j +','+i);
  playSlide( a_user, img_user, imgUrl_users[j+i], idTxt_user, id_users[j+i], infoTxt_user, info_users[j+i], i);   
  if (useFilters)
  {
    rand = Math.round(20000*Math.random()) ;
    setTimeout('playSlides('+ j +','+ i +')', displayTime + rand);
  }
  else
  {
    setTimeout('playSlides('+ j +','+ i +')', displayTime);
  }

}
