var ff_delay = 1000;
var ff_start_frame = 0;
var ff_end_frame = 0;
var ff_current_frame = 0;
var ff_rotate = 1;

function ff_slideshow_init() {
	var lis = $$('#featured_films div[class="featured_film"]')
	
	for( i=0; i < lis.length; i++){
		lis[i].style.display = 'none';
    
    var Slide = Class.create({
      
      initialize: function(slide) {
        this.slide = slide;
        this.details = slide.select('[class="featured_film_details"]')[0].id;
        
        // "hide" the details 
        startOpacity = ($(this.details).getStyle('display') == 'none' ? 0.0 : $(this.details).getOpacity() || 0.0)
        this.detailsEffect = new Effect.Opacity(this.details, { duration: 0, from: startOpacity, to: 0 });
        
        // setup the mouse over/out event listeners
        this.moverbfx = this.mover.bindAsEventListener(this);
        this.moutbfx = this.mout.bindAsEventListener(this);
        
        this.slide.observe('mouseover', this.moverbfx);
        this.slide.observe('mouseout', this.moutbfx);
        
      },
      
      mover: function(event) {        
        // stop any current effect
        try { this.detailsEffect.cancel(); } catch(err) { }
        
        startOpacity = ($(this.details).getStyle('display') == 'none' ? 0.0 : $(this.details).getOpacity() || 0.0)
        this.detailsEffect = new Effect.Opacity(this.details, { duration: 0.5, from: startOpacity, to: 1.0 });
                
        // stops the slideshow rotation
        ff_rotate = 0;
      },
      
      mout: function(event) {
        // stop any current effect
        try { this.detailsEffect.cancel(); } catch(err) { }
        
        startOpacity = ($(this.details).getStyle('display') == 'none' ? 0.0 : $(this.details).getOpacity() || 0.0)
        this.detailsEffect = new Effect.Opacity(this.details, { duration: 0.5, from: startOpacity, to: 0 });
        
        // re-enables slideshow rotation
        ff_rotate = 1;
      }
      
    })
    
    s = new Slide(lis[i]);

	}
	ff_end_frame = lis.length -1;	
}


function ff_fadeInOut(direction) {
	var lis = $$('#featured_films div[class="featured_film"]')
	
	Effect.Fade(lis[ff_current_frame]);

  if (ff_current_frame == ff_end_frame) { ff_current_frame = ff_start_frame; } else { ff_current_frame++; }
	
	lisAppear = lis[ff_current_frame];
	Effect.Appear(lisAppear);
	
}

function ff_slideshow_cycle(delay) {
	if (ff_end_frame <= 0) {return}
  if (ff_rotate == 1) {ff_fadeInOut(1)}
  setTimeout("ff_slideshow_cycle("+delay+")", delay);
}

var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=600,width=800,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

