﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("BandSite");

BandSite.Shows = function(element) {
    BandSite.Shows.initializeBase(this, [element]);
    
    this._showID = null;
}

BandSite.Shows.prototype = {
    initialize: function() {
        BandSite.Shows.callBaseMethod(this, 'initialize');
        
        // Add custom initialization here
        var that = this;

        this._futureShowGrid.add_itemClicked(
            function(sender, e) {
                that._pastShowGrid.deselectRow();
                that.showSelected(e.id);
//                if (e.id == that._nextShowID) {
//                    that._nextShowDiv.style.display = '';
//                } else {
//                    that._nextShowDiv.style.display = 'none';
//                }
            }
        );
        
        this._pastShowGrid.add_itemClicked(
            function(sender, e) {
                that._futureShowGrid.deselectRow();
                that.showSelected(e.id);
                // that._nextShowDiv.style.display = 'none';
            }
        );
        
        if (this._commentList) {
            this._commentList.add_constructingNewComment(
                function(sender, e) {
                    if (! that._showID) {
                        programError("ShowID must be set to construct new show comment");
                    }
                    e.item.ShowID = that._showID;
                
                }
            );
        }
        
        if (this._nextShowID) {
            this._futureShowGrid.loadGrid(this._nextShowID);
            this.showSelected(this._nextShowID);            
            this._nextShowDiv.style.display = '';
        } else {
            this._nextShowDiv.style.display = 'none';        
        }
      
    },
    dispose: function() {        
        //Add custom dispose actions here
        BandSite.Shows.callBaseMethod(this, 'dispose');
    },
    
    showSelected: function(showID) {
        var that = this;
        this._showDetailsPanelSet.showPanel("LoadingPanel");
        setTimeout(function() {
            that._showDetailsPanelSet.showPanel("DetailsPanel");
        }, 1000);
    
        if (showID == this._nextShowID) {
            this._nextShowDiv.style.display = '';
        } else {
            this._nextShowDiv.style.display = 'none';        
        }
        
        this._showID = showID;
        this._showDetails.set_itemID(showID);
        this._showDetails.loadItem();
        if (this._commentList) {
            this._commentList.set_foreignID(showID);
            this._commentList.loadList();        
        }
    },
    
    resetSection: function() {
        if (this._nextShowID) {
            this._futureShowGrid.loadGrid(this._nextShowID);
            this.showSelected(this._nextShowID);            
            this._nextShowDiv.style.display = '';
        } else {
            this._nextShowDiv.style.display = 'none';        
        }    
    },
    
    // Used by home section...
    selectFutureShow: function(showID) {
        this._pastShowGrid.deselectRow();
        this._futureShowGrid.set_selectedID(showID);
        this.showSelected(showID);
    }
}
BandSite.Shows.createProperty("bandID");
BandSite.Shows.createProperty("futureShowGrid");
BandSite.Shows.createProperty("pastShowGrid");
BandSite.Shows.createProperty("showDetailsPanelSet");
BandSite.Shows.createProperty("showDetails");
BandSite.Shows.createProperty("commentList");
BandSite.Shows.createProperty("nextShowID");
BandSite.Shows.createProperty("nextShowDiv");
BandSite.Shows.registerClass('BandSite.Shows', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
