var Guillotine = {

      images : [],
      container : null,
      left : null,
      right : null,
      time1 : 1000,
      time2 : 100,
      step : 5,
      current : 0,
      opac : 100,
      width : 0,
      height : 0,
      
      
      add_image : function() {
        for (var i = 0, l = arguments.length; i < l; i++) {
          this.images.push(arguments[i]);
        }
      },

      set_dim : function(w, h) {
        this.width = w;
        this.height = h;
      },

      set_container : function(container_name) {
        var c = document.getElementById(container_name);
        if (c) {
          this.container = c;
          // element.currentStyle.hasLayout
          //if (!this.container.style.position) {
          /*if (!this.container.currentStyle.hasLayout) {
            this.container.style.position = 'relative';
          }*/
          this.left = document.createElement('div');
          this.left.style.position = 'absolute';
          this.left.style.top = 0;
          this.left.style.bottom = 0;
          this.left.style.left = 0;
          this.left.style.right = 0;
          this.left.style.width = this.width + 'px';
          this.left.style.height = this.height + 'px';

          this.right = document.createElement('div');
          this.right.style.position = 'absolute';
          this.right.style.top = 0;
          this.right.style.bottom = 0;
          this.right.style.left = 0;
          this.right.style.right = 0;
          this.right.style.width = this.width + 'px';
          this.right.style.height = this.height + 'px';

          this.container.appendChild(this.left);
          this.container.appendChild(this.right);
        }
      },

      start : function() {
        this.left.style.backgroundImage = "url(" + this.images[0] + ")";
        this.right.style.backgroundImage = "url(" + this.images[1] + ")";
        this.current = 1;
        this.right.style.opacity = 0;
        this.left.style.opacity = 1;
        this.to_right();
      },

      fade : function(left_opac, right_opac) {
        // IE
        this.left.style.filter = "alpha(opacity = " + left_opac + ")";
        this.right.style.filter = "alpha(opacity = " + right_opac + ")";
        // Browser
        this.right.style.opacity = right_opac / 100;
        this.left.style.opacity = left_opac / 100;
      },

      to_right : function() {
        if (this.opac >= 0) {
          this.fade(this.opac, 100 - this.opac);
          this.opac -= this.step;
          window.setTimeout('Guillotine.to_right()', this.time2);
        } else {
          this.next(this.left);
          window.setTimeout('Guillotine.to_left()', this.time1);
        }
      },

      to_left : function() {
        if (this.opac >= 0) {
          this.fade(100 - this.opac, this.opac);
          this.opac -= this.step;
          window.setTimeout('Guillotine.to_left()', this.time2);
        } else {
          this.next(this.right);
          window.setTimeout('Guillotine.to_right()', this.time1);
        }
      },

      next : function(obj) {
        this.opac = 100;
        this.current++;
        if (this.current >= this.images.length) {
          this.current = 0;
        }
        /*
        try {
        	log("current image: " + this.current);
        }
        catch(e) {}
        */
        obj.style.backgroundImage = "url(" + this.images[this.current] + ")";
      }

};
