var effect_delay = 3000;
var effect_counter = 0;
var effect_image_list = "";
var effect_image_count = 0;

function getElementsByStyleClass (className)
{
  var all = document.getElementsByTagName('*');
  var elements = new Array();
  for (var i = 0; i < all.length; i++)
  {
    if (all[i].className == className)
    {
      elements[elements.length] = all[i];
      effect_image_count++;
    }
  }
  return elements;
}

function initRotateImages()
{
  effect_image_list = getElementsByStyleClass ('rotate');
  if(effect_image_count<1)
    return;
  effect_counter = 0;
  rotateImages();
}

function rotateImages()
{
  var obj = effect_image_list[effect_counter];
  setOpacity(obj, 0);
  obj.style.display='block';
  fadeIn(obj.id,0,obj);
  effect_counter++;
  if(effect_counter > effect_image_count-1)
    effect_counter = 0;

  setTimeout('rotateImages()',effect_delay);
}

function setOpacity(obj, opacity)
{
  opacity = (opacity == 100)?99.999:opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity,image)
{
  if (document.getElementById)
  {
    obj = document.getElementById(objId);
    obj.style.display='block';
    if (opacity <= 100)
    {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+",'"+image+"')", 100);
    }
    else
    {
      window.setTimeout("fadeOut('"+objId+"',100,'"+image+"')", effect_delay-1000);
    }
  }
}

function fadeOut(objId,opacity,image)
{
  if (document.getElementById)
  {
    obj = document.getElementById(objId);
    obj.style.display='block';
    if (opacity >= 0)
    {
      setOpacity(obj, opacity);
      opacity -= 10;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+",'"+image+"')", 100);
    }
  }
}
