var Spotlight = Class.create();

Spotlight.prototype = {
    initialize:function(pre, ct, delayTime){
        if(delayTime <= 0 || delayTime == "" || delayTime == undefined){
            delayTime = 5;
        }
        
        this.spotlight_timing = delayTime;
        this.spotlight_prefix = pre;
        this.spotlights = ct;
        
        this.initializeDimensions();
         
        if(this.spotlights > 0){
            for(i=1;i<this.spotlights+1;i++)
            {
                this.setDimensions(this.spotlight_prefix + 'spotlight_' + i);
                $(this.spotlight_prefix + 'spotlight_' + i).hide();
            }
        }
        
        this.currentspotlight = 0;
        this.applyDimensions();
        this.showNextSpotlight();
    },

    showNextSpotlight:function(){
        el = this.spotlight_prefix + "spotlight_" + this.currentspotlight;
        e = $(el);
        if(e != undefined){
            e.hide();
        } 
        this.currentspotlight = this.currentspotlight + 1;
        if(this.currentspotlight > this.spotlights){
            this.currentspotlight = 1;
        }
        //show it over time
        el = this.spotlight_prefix + "spotlight_" + this.currentspotlight;
        new Effect.Appear(el, {duration:1,  afterFinish : this.hideCurrentSpotlight.bindAsEventListener(this)})
    },

    hideCurrentSpotlight:function(){           
         el = this.spotlight_prefix + "spotlight_" + this.currentspotlight;
         this.setDimensions(el);
         this.applyDimensions();
         new Effect.Appear(el, {duration:1, afterFinish : this.showNextSpotlight.bindAsEventListener(this), from:1, to:0, delay:this.spotlight_timing})
    },
    
    setDimensions:function(pocket){
        this.dimensions.width = Math.max(this.dimensions.width, $(pocket).getWidth());
        this.dimensions.height = Math.max(this.dimensions.height, $(pocket).getHeight());
                   
    },
    
    applyDimensions:function(){
        var outer = this.spotlight_prefix + 'outer_spotlight';
        $(outer).setStyle({'height': this.dimensions.height + 'px', 
                           'width': this.dimensions.width + 'px'});        
    },
    
    initializeDimensions:function(){
        var outer = this.spotlight_prefix + 'outer_spotlight';
        this.dimensions = $(outer).getDimensions();
        this.dimensions.width = 0;
        this.dimensions.height = 0;       
    }
}