var arr_slideshow_images = new Array();

var slideshow_active;
var slideshow_start = 0;

function load_slideshow() {
  arr_slideshow_images = $$('div#slideshow img');
  arr_slideshow_images_save = $$('div#slideshow img');
  arr_slideshow_images_save.each(function(s) {
    arr_slideshow_images.push(s);
  });

  arr_slideshow_images.each(function(s) {
    s.setOpacity(0);
  });

  arr_slideshow_images[slideshow_start].setStyle({
    display: 'block'
  });

  arr_slideshow_images[slideshow_start].setOpacity(1);

  stop_pe = false;
  new PeriodicalExecuter(function(pe) {
    if (stop_pe != true) {
      slideshow_active = window.setInterval('fade(slideshow_start)', 100);
      stop_pe = true;
    } else {
      pe.stop();
    }
  }, 2);
}

function fade(c) {
  currentOpacity = arr_slideshow_images[c].getStyle('opacity');
  arr_slideshow_images[c].setOpacity(currentOpacity - 0.05);

  if (c + 2 == arr_slideshow_images.length) {
    arr_slideshow_images_save.each(function(s) {
      arr_slideshow_images.push(s);
    });
  }

  if (currentOpacity == 0) {
    slideshow_start = c+1;

    window.clearInterval(slideshow_active);

    stop_pe = false;
    new PeriodicalExecuter(function(pe) {
      if (stop_pe != true) {
        slideshow_active = window.setInterval('fade(slideshow_start)', 100);
        stop_pe = true;
      } else {
        pe.stop();
      }
    }, 2);

    return false;
  } else {
    arr_slideshow_images[c+1].setStyle({
      display: 'block'
    });
    currentOpacity = arr_slideshow_images[c+1].getStyle('opacity');
    arr_slideshow_images[c+1].setOpacity(currentOpacity + 0.05);
  }
}

function openBrWindowFever(theURL,winName,features,ref,center){
  eval("var "+winName);	if (eval(winName)==true && !winName.closed)
  {winName.focus();}else{if(ref){
  var refURL=theURL+"?URL="+document.location;}else{var refURL=theURL;}
  if(center!="vals"){a=new Array();a=center.split('|');
  t=((screen.height)-a[0])/2;l=((screen.width)-a[1])/2;
  features=features+",top="+t+",left="+l;}
  winName=window.open(refURL,winName,features);
  winName.focus();winName = true;}
}

function ping() {
  new PeriodicalExecuter(function(pe) {
    new Ajax.Request('/ping.php', { method: 'post', asynchronous: false });
  }, 60);
}

Event.observe(window, 'load', ping, false);