var CrossFader = Class.create();
CrossFader.prototype = {
  // settings
  interval: homeImageInterval, // interval for changing crossfader (in seconds)
  
  items: [],
  currentItemIndex: 0,
  currentItem:null,
  timer: null,
  
  initialize: function(){
  
    this.container = $('crossfade');
    this.container.style.visibility = 'visible';
    
    for (var i=0, arg; arg = arguments[i]; i++){
      var item = $(arg);
      this.container.appendChild(item.remove());
      this.items.push({
        image: item.down('.image').hide(),
        text: item.down('.text').hide()
      });
    }
    
    // on init, show first one
    this.reveal(this.items[0]);
    
    // then set up an interval
    setInterval(this.poll.bind(this), this.interval*1000);
  },
  
  // timer function
  poll: function(){
    // reset to beginning if at end
    if (++this.currentItemIndex >= this.items.length) this.currentItemIndex = 0;
    this.reveal(this.items[this.currentItemIndex]);
  },
  
  reveal: function(item){
    // before revealing, we must hide if applicable
    if (this.currentItem){ this.hide(item); return }
    
    var show_text = function(){ 
      new Effect.Appear(item.text);
    }
    item.image.style.zIndex = 2;
    new Effect.Appear(item.image, {afterFinish:show_text});
        
    this.currentItem = item;
  },
  
  hide: function(itemToShow){
    var after_finish = function(){
      this.currentItem.image.style.zIndex = 1;
      new Effect.Fade(this.currentItem.image);
      this.currentItem = null;
      this.reveal(itemToShow);
    }.bind(this);
    
    new Effect.Fade(this.currentItem.text, {afterFinish: after_finish, duration:0.5});
  }
}

/*
var CrossFader = Class.create();
CrossFader.prototype = {
  // settings
  interval: homeImageInterval, // interval for changing crossfader (in seconds)
  
  items: [],
  currentItemIndex: 0,
  currentItem:null,
  timer: null,
  
  initialize: function(){
  
    this.container = $('crossfade');
    this.container.style.visibility = 'visible';
    
    for (var i=0, arg; arg = arguments[i]; i++){
      var item = $(arg);
      this.container.appendChild(item.remove());
      this.items.push({
        image: item.down('.image').hide(),
        text: item.down('.text').hide()
      });
    }
    
    // on init, show first one
    this.reveal(this.items[0]);
    
    // then set up an interval
    setInterval(this.poll.bind(this), this.interval*1000);
  },
  
  // timer function
  poll: function(){
    // reset to beginning if at end
    if (++this.currentItemIndex >= this.items.length) this.currentItemIndex = 0;
    this.reveal(this.items[this.currentItemIndex]);
  },
  
  reveal: function(item){
    // before revealing, we must hide if applicable
    if (this.currentItem){ this.hide(item); return }
    
    var show_text = function(){ 
      new Effect.Appear(item.text);
    }
    item.image.style.zIndex = 2;
    new Effect.Appear(item.image, {afterFinish:show_text});
        
    this.currentItem = item;
  },
  
  hide: function(itemToShow){
    var after_finish = function(){
      this.currentItem.image.style.zIndex = 1;
      new Effect.Fade(this.currentItem.image);
      this.currentItem = null;
      this.reveal(itemToShow);
    }.bind(this);
    
    new Effect.Fade(this.currentItem.text, {afterFinish: after_finish, duration:0.5});
  }
}
*/

function goto(element) {
	document.location='calculator.php?pid=$photo&print=' + element.options[element.selectedIndex].value;
}