var xh, ajaxboxinterval, simxmlhttp, sfiles, lastdiv, currentcphoto=-1, timeout;

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 FileListReady() {
  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(new Array(FileEntry.getAttribute('filename'), FileEntry.getAttribute('name'), FileEntry.getAttribute('description'), FileEntry.getAttribute('width'), FileEntry.getAttribute('p')));
        }
      }
      StartImagesSwitching();
    }
  }
}

function StartImagesSwitching() {
  CyclePhotos();
}

function UpdateCarousel() {
  $('carouselcontent').innerHTML = '<a href="#" onclick="javascript: PrevPhoto(); return false;" class="la">&nbsp;</a><div id="carouselcontentinner"><div class="carouseldescription">'+sfiles[currentcphoto][2]+'</div></div><a href="#" onclick="javascript: NextPhoto(); return false;" class="ra">&nbsp;</a>';
  SetTransparency($('carouselcontentinner'), 0);
  if(zaloba==true) $('carouselcontentinner').style.backgroundImage = "url('./skins/szeptyccy_zaloba/smoothgenerata.php?img=../."+sfiles[currentcphoto][0]+"&p="+sfiles[currentcphoto][4]+"&str="+sfiles[currentcphoto][1]+"')";
  else $('carouselcontentinner').style.backgroundImage = "url('./skins/szeptyccy/smoothgenerata.php?img=../."+sfiles[currentcphoto][0]+"&p="+sfiles[currentcphoto][4]+"&str="+sfiles[currentcphoto][1]+"')";
  //$('carouselcontentinner').style.width = '667px';
  $('carouselcontentinner').style.width = ((637-sfiles[currentcphoto][3])<0 ? 637 : sfiles[currentcphoto][3])+'px';
  $('carouselcontentinner').style.paddingRight = ((637-sfiles[currentcphoto][3])<0 ? 0 : (637-sfiles[currentcphoto][3]))+'px';
  
  
   //alert(sfiles[currentcphoto][3]+' + '+(667-sfiles[currentcphoto][3]));
 
//  CufonReplace('#carouselcontent h1', { fontFamily: 'Garamond' });
}

function CyclePhotos() {
  if(currentcphoto!=-1) {
    for(var i=1; i<=10; i++) setTimeout("SetTransparency($('carouselcontentinner'), "+(10-i)+"*10)", (parseInt(i*50)));
  }
  currentcphoto++;
  if(currentcphoto==sfiles.length) currentcphoto = 0;
  
  setTimeout('UpdateCarousel();', (parseInt(11*50)));
  
  for(var i=1; i<=10; i++) setTimeout("SetTransparency($('carouselcontentinner'), "+i+"*10)", (parseInt((i+12)*50)));
  timeout = setTimeout('CyclePhotos();', 8000);
}

function NextPhoto() {
  clearTimeout(timeout);
  if(currentcphoto!=-1) {
    for(var i=1; i<=10; i++) setTimeout("SetTransparency($('carouselcontentinner'), "+(10-i)+"*10)", (parseInt(i*50)));
  }
  currentcphoto++;
  if(currentcphoto==sfiles.length) currentcphoto = 0;
  
  setTimeout('UpdateCarousel();', (parseInt(11*50)));
  
  for(var i=1; i<=10; i++) setTimeout("SetTransparency($('carouselcontentinner'), "+i+"*10)", (parseInt((i+12)*50)));
  timeout = setTimeout('CyclePhotos();', 8000);
}

function PrevPhoto() {
  clearTimeout(timeout);
  if(currentcphoto!=-1) {
    for(var i=1; i<=10; i++) setTimeout("SetTransparency($('carouselcontentinner'), "+(10-i)+"*10)", (parseInt(i*50)));
  }
  currentcphoto--;
  if(currentcphoto==-1) currentcphoto = sfiles.length-1;
  
  setTimeout('UpdateCarousel();', (parseInt(11*50)));
  
  for(var i=1; i<=10; i++) setTimeout("SetTransparency($('carouselcontentinner'), "+i+"*10)", (parseInt((i+12)*50)));
  timeout = setTimeout('CyclePhotos();', 8000);
}

function InitCarousel() {
  if($('carouselcontent')) {
    delete simxmlhttp;
    simxmlhttp = GetXmlHttpObject(); 
    simxmlhttp.onreadystatechange = FileListReady;
    if(mod_rewrite) simxmlhttp.open("GET",'/skins/szeptyccy/getimages.php?lng='+lng,true);  
    else simxmlhttp.open("GET",'./skins/szeptyccy/getimages.php?lng='+lng,true);  
    simxmlhttp.send(null);
  }
}
