
var ImageLinkCrossFader = Class.create();
ImageLinkCrossFader.prototype = {

  interval: 8, // interval for changing crossfader (in seconds)
  
  divs_to_fade: [],
  currentItemIndex: 0,
  currentItem:null,
  timer: null,

  initialize: function(items_to_fade, interval){
    this.container = $('navigation_highlight_container');
    this.container.style.visibility = 'visible';
		this.interval = interval;
    for (var i=0, arg; arg = items_to_fade[i]; i++){
      var item = $(arg);
			item.style.visibility = 'visible';
			this.container.appendChild(item.remove());
			this.divs_to_fade.push(item.hide());
			
    }
    
    // on init, show first one
    this.reveal(this.divs_to_fade[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.divs_to_fade.length) this.currentItemIndex = 0;
    this.reveal(this.divs_to_fade[this.currentItemIndex]);
  },
  
  reveal: function(item){
	  // before revealing, we must hide if applicable
    if (this.currentItem){ this.hide(item); return }
        
    new Effect.Appear(item,{duration: 2});    
        
    this.currentItem = item;
  },
  
  hide: function(itemToShow){    
	  var after_finish = function(){
      this.currentItem = null;
      this.reveal(itemToShow);
    }.bind(this);   
		
    new Effect.Fade(this.currentItem, {afterFinish: after_finish, duration: 1});
  }
}



var ImageLinkPicker = Class.create();
ImageLinkPicker.prototype = {
  
  divs_to_fade: [],
  currentItemIndex: 0,
  currentItem:null,

  initialize: function(items){
    this.container = $('navigation_highlight_container');
    this.container.style.visibility = 'visible';
		for (var i=0, arg; arg = items[i]; i++){
      var item = $(arg);
			item.style.visibility = 'visible';
			this.container.appendChild(item.remove());
			this.divs_to_fade.push(item.hide());
			
    }
    
    // on init, pick and show
		var rand_no = Math.random();
		
		var sel_item = Math.round((items.length-1) * Math.random());
    this.reveal(this.divs_to_fade[sel_item]);
    
    
  },
  
  reveal: function(item){
	  
        
    new Effect.Appear(item,{duration: .1});    
        
    this.currentItem = item;
  }
}
