addDOMLoadEvent = (function(){
  // create event function stack
  var load_events = [],safari_timer,done,exec,script;
 
  var init = function () {
    done = true;

    // kill the timer
    clearInterval(safari_timer);

    // execute each function in the stack in the order they were added
    while (exec = load_events.shift())
      exec();
      if (script) script.onreadystatechange = '';
    }

    return function (func) {
      // if the init function was already ran, just run this function now and stop
      if (done) return func();

      if (!load_events[0]) {
        // for Mozilla/Opera9
        if (document.addEventListener)
          document.addEventListener("DOMContentLoaded", init, false);
    
   /*@cc_on @*/
   /*@if (@_win32)
   var proto = "src='javascript:void(0)'";
   if (location.protocol == "https:") proto = "src=//0";
   document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
   var script = document.getElementById("__ie_onload");
   script.onreadystatechange = function() {
    if (this.readyState == "complete") {
     init()
    }
   };
   /*@end @*/

    if (/WebKit/i.test(navigator.userAgent)) { // sniff
      safari_timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState))
          init(); // call the onload handler
      }, 10);
    }

    old_onload = window.onload;
    window.onload = function() {
      init();
      if (old_onload) old_onload();
    };
  }

    load_events.push(func);
  }
})();

if (!effects) var effects = {};

slideshow = {
	fps: 30,
	duration: 1000,
	delay: 10000,
	slides: [],
	init: function() {
    slideshow.collectSlides();
    slideshow.setupSlides();
  },
  collectSlides: function() {
    get('slideshow').style.position='relative';
    var collection = get('slideshow').childNodes;
    for( var o=0; o<collection.length; o++ ) {
      if( collection[o].nodeName == 'IMG' ) {
        this.slides.push(collection[o]);
        collection[o].id = 'slide_' + o;
      }
    }
  },
  setupSlides: function() {
    this.styleSlides();
    this.nextSlide();
  },
  styleSlides: function() {
    for( var o=0; o<this.slides.length; o++ ) {
      var slide = this.slides[o];
      slide.style.position='absolute';
      slide.style.zIndex=100 - o;
      this.setOpacity(slide.id, 0);
      slide.style.left=(slide.parentNode.style.width - slide.style.width) / 2;
      slide.style.top=(slide.parentNode.style.width - slide.style.height) / 2;
    }
  },
  nextSlide: function() {
    var slidesLength = this.slides.length-1;
    this.fade(this.slides[slidesLength].id, 0);
    var slide = this.slides.shift();
    
    this.fade(slide.id, 1);
    //get('summaries').style.height = slide.offsetHeight + 'px';
    this.slides.push(slide);
    setTimeout("slideshow.nextSlide()", this.delay);
  },
  fade: function(id, to, fps, duration) {
    if (!fps) fps = this.fps;
    if (!duration) duration = this.duration;
    if (!to) to = 0;

    var origOpacity = ( !get(id).style.opacity || get(id).style.display=='none' ? 0 : get(id).style.opacity );
    var diff = origOpacity - to;

    var frames = Math.round(fps * (duration / 1000));
    var interval = duration / frames;
    var delay = interval;
    var frame = 0;
  
    if( origOpacity == 0 ) get(id).style.display='block';
  
    while (frame <= frames) {
      var opacity = origOpacity - ((diff / frames) * frame);

      setTimeout("slideshow.setOpacity('"+id+"','"+opacity+"')", delay);
      if( frame == frames && to==0 ) setTimeout("get('"+id+"').style.display='none'", delay);

      frame++;
      var delay = interval * frame;
    }
  },
  setOpacity: function(id, to) {
    var element = get(id);
    element.style.filter = (to == 1) ? '' : 'alpha(opacity=' + to * 100 + ')';
    element.style.opacity = to;
    if( to < 0 ) element.style.display='none';
}
}

function get(id) { return document.getElementById(id) }

addDOMLoadEvent(slideshow.init);