/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    'Winners Page' Constants
*/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    'Winners Page' Variables
*/


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    'Winners Page' Dom Loaded Event
*/

document.observe('dom:loaded', function() {
    
    Stream.observe("SongProgress", function(data){ Stream.fire("SongProgress"+data.url_hash, data); });
    
    $('fp_columns').select('.fp').each( function(fp){
        if (!fp.hasClassName('fpEmpty')){
            INDABA.page.contestIndex.fps.push( new INDABA.controls.FeaturedProgramItem(fp) );
        }
    });
});

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    'Winners Page' Stream Observers
*/


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    'Winners Page' Methods
*/

timeline_jump = function(time) {
    /* Time is in format 'Nov 30 2008 GMT' */
    // INDABA.page.contestIndex.tl.getBand(0).setCenterVisibleDate(Timeline.DateTime.parseGregorianDateTime(time));
};

INDABA.page.contestIndex.initTimeline = function(args) {
    
    if (typeof(args) == 'undefined') { args == {}; }
    
    var eventSource = new Timeline.DefaultEventSource(0);
    
    var theme = Timeline.ClassicTheme.create();
    
        theme.event.bubble.width = 320;
        theme.event.bubble.height = 220;
        theme.event.bubble.orientation = 'bottom';
        
        theme.event.tape.height = 12;
        
        theme.event.label.offsetFromLine = 0;
        
        theme.event.bubble.timeSeparator = document.createTextNode(' - ');
    
    var bandInfos = [
        Timeline.createBandInfo({
            width:          "100%", 
            intervalUnit:   Timeline.DateTime.MONTH, 
            intervalPixels: 300,
            eventSource:    eventSource,
            layout:         'original',
            theme:          theme,
            timeZone:       -5,
            trackHeight:    1,
            trackGap:       0.2
        })
    ];
    
    INDABA.page.contestIndex.tl = Timeline.create(document.getElementById("tl"), bandInfos, Timeline.HORIZONTAL);
    
    INDABA.page.contestIndex.tl.loadXML(args.xml_source, function(xml, url) {
        eventSource.loadXML(xml, url);
    });
    
    if (typeof(args.onComplete) != 'undefined') {
        args.onComplete();
    }
    
};


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    'Winners Page' Classes
*/

INDABA.controls.FeaturedProgramItem = Class.create();
INDABA.controls.FeaturedProgramItem.prototype = {
    
    msOvBGOpacity: 0.90,
    msOvCloseTimeout: 0.25,
    
    initialize: function(fp_div) {
        this.el     = $(fp_div);
        this.elID   = this.el.identify();
        this.img    = this.el.down('.fp_image');
        this.msOv   = this.el.down('.fp_mouseover');
        this.cLink  = this.el.down('.fp_url');
        
        this.msOv.down('.bg').setOpacity(this.msOvBGOpacity);
        this.msOv.setOpacity(0);
        this.msOv.show();
        
        this.el.observe('click',        this.click.bind(this));
        this.el.observe('mouseover',    this.mouseOver.bind(this));
        this.el.observe('mouseout',     this.mouseOut.bind(this));
        
        INDABA.log('FP Item > Created > ' + this.elID);
        return this;
    },
    
    click: function(evt) {
        INDABA.log('FP Item > Clicked > ' + this.elID + ' > ' + this.cLink.readAttribute('href'));
        location.href = this.cLink.readAttribute('href');
        evt.stop();
    },
    
    mouseOverTimeout: undefined,
    
    clearMouseOverTimeout: function() {
        if (typeof(this.mouseOverTimeout) != 'undefined') {
            clearTimeout(this.mouseOverTimeout);
        }
    },
    
    mouseOver: function(evt) {
        this.clearMouseOverTimeout();
        if (evt.target.hasClassName('fp') || evt.target.up('.fp') != null) {
            this.showMouseOver();
        } else {
            
        }
    },
    
    mouseOut: function(evt) {
        if (evt.target.hasClassName('fp') || evt.target.up('.fp') != null) {
            this.mouseOverTimeout = setTimeout( function(){ this.hideMouseOver(); }.bind(this), this.msOvCloseTimeout * 1000);
        }
    },
    
    showMouseOver: function() {
        if ((this.msOv.getOpacity() < 1)) {
            // INDABA.log('FP Item > Show Mouse Over > ' + this.elID);
            new Effect.Opacity(this.msOv, {
                from: this.msOv.getOpacity(),
                to: 1,
                duration:0.1,
                fps: User.browser.ie ? 10 : 30,
                queue: {position:'end',limit:1,scope:this.elID+'_show'}
            });
        }
    },
    
    hideMouseOver: function() {
        if ((this.msOv.getOpacity() == 1)) {
            // INDABA.log('FP Item > Hide Mouse Over > ' + this.elID);
            new Effect.Opacity(this.msOv, {
                from: 1,
                to: 0,
                duration:0.5,
                fps:User.browser.ie ? 10 : 30,
                queue: {position:'end',limit:1,scope:this.elID+'_hide'}
            });
        }
    }
    
};