var xh, ajaxboxinterval, simxmlhttp, sfiles, currentreytanimage, lastdiv;

function FadeIn2(objid) {
  for(var i=1; i<=10; i++) setTimeout("if (document.getElementById('"+objid+"')) SetTransparency(document.getElementById('"+objid+"'), "+i+"*10)", (parseInt(i*50)));
}

function FadeOut2(objid) {
  for(var i=1; i<=10; i++) setTimeout("if (document.getElementById('"+objid+"')) SetTransparency(document.getElementById('"+objid+"'), 100-("+i+"*10))", (parseInt(i*50)));
}

function InitAjaxBox() {
  ajaxboxinterval = setInterval('ReloadAjaxBox();', 16000);
  ReloadAjaxBox();
}

function ReloadAjaxBox() {
  delete xh;
  FadeOut2('ajaxbox');
  xh = GetXmlHttpObject();
  xh.onreadystatechange = function() {
    if (xh.readyState==4){
      if (xh.status==200) { 
        var response = xh.responseText;
        document.getElementById('ajaxbox').innerHTML = response;
        FadeIn2('ajaxbox');
      } 
    }
  };
  xh.open('GET','./bincms/reytaninfo.php',true);
  setTimeout('xh.send(null);', 550);
}

function ReytanFileListReady() {
  delete sfiles;
  sfiles = new Array();
  if (simxmlhttp.readyState==4){
    if (simxmlhttp.status==200) { 
      var FileListXML = simxmlhttp.responseXML.documentElement;
      for(i=0; i<FileListXML.childNodes.length; i++) {
        if (FileListXML.childNodes.item(i).nodeType==1) { 
          var FileEntry = FileListXML.childNodes.item(i);
          sfiles.push(FileEntry.getAttribute('filename'));
        }
      }
      StartImagesSwitching();
    }
  }
}

function StartImagesSwitching() {
  currentreytanimage = -1;
  lastframe = 1;
  CyclePhotos();
}

function CyclePhotos() {
  currentreytanimage++;
  if(currentreytanimage>=sfiles.length) currentreytanimage = 0;
  var im1 = document.getElementById('rimage1');
  var im2 = document.getElementById('rimage2');
  
  if(lastframe==1) {
    if(mod_rewrite) im1.style.backgroundImage = "url('/skins/reytan/reytanarcimg.php?img="+sfiles[currentreytanimage]+"')";
    else im1.style.backgroundImage = "url('./skins/reytan/reytanarcimg.php?img="+sfiles[currentreytanimage]+"')";
    setTimeout('FadeOut2(\'rimage2\');', 2000);
  } else {
    if(mod_rewrite) im2.style.backgroundImage = "url('/skins/reytan/reytanarcimg.php?img="+sfiles[currentreytanimage]+"')";
    else im2.style.backgroundImage = "url('./skins/reytan/reytanarcimg.php?img="+sfiles[currentreytanimage]+"')";
    setTimeout('FadeIn2(\'rimage2\');', 2000);
  }
  lastframe = (lastframe==1 ? 2 : 1);
  setTimeout('CyclePhotos();', 8000);
}

delete simxmlhttp;
simxmlhttp = GetXmlHttpObject(); 
simxmlhttp.onreadystatechange = ReytanFileListReady;
if(mod_rewrite) simxmlhttp.open("GET",'/skins/reytan/getarcimages.php',true);  
else simxmlhttp.open("GET",'./skins/reytan/getarcimages.php',true);  
simxmlhttp.send(null);