// for mootools 1.2
var slideshow = new Class({
  Implements: Options,

  options: {
    root: '/img/slideshow/',
    ext: '.jpg',
    anim: [1, 100],
    speed: 2000
  },
  
  initialize: function(root, options)
  {    
    this.setOptions(options);
    this.options.root += root+'/';
    this.currentindex = this.options.anim[0];
    
    if ($('head-logo-2')) {
      this.animate.delay(this.options.speed, this);
    }
  },
  
  nextslide: function() {
    this.currentindex++;
    
    if (this.currentindex > this.options.anim[1]) {
      this.currentindex = this.options.anim[0];
    }
    this.animate();
  },

  animate: function() {
    this.currentfile = this.options.root+this.currentindex+this.options.ext;
    this.currentimg = new Asset.image(this.currentfile, {
      title: 'img',
      onload: function() {
        $('head-logo-2').setStyles({
          'opacity': 0,
          'background-image': 'url('+this.currentfile+')'
        });
        
        new Fx.Morph($('head-logo-2'), {
          duration: 1500,
          transition: Fx.Transitions.Sine.easeOut,
          onComplete: function() {
            $('head-logo-1').setStyles({
              'opacity': 1,
              'background-image': 'url('+this.currentfile+')'
            });

            this.nextslide.delay(this.options.speed, this);
          }.bind(this)
        }).start({
          'opacity': [0, 1]
        });
      }.bind(this),
      onerror: function() {
        if (this.currentindex > 1) {
          this.currentindex = 0;
          this.nextslide();
        }
      }.bind(this)
    });
  }
});

url = window.location.href;
url = url.substr(7, url.length);

folder = url.split(/\//g);
f = folder[3];
if (!f) {
  f = 'default';
}

new slideshow(f);
