﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("BandSite");

BandSite.Biography = function(element) {
    BandSite.Biography.initializeBase(this, [element]);
}

BandSite.Biography.prototype = {
    initialize: function() {
        BandSite.Biography.callBaseMethod(this, 'initialize');
        
        // Add custom initialization here
        var that = this;
        
        $addHandlers(this._bandBioDiv, { click: this._bandBioDivClicked }, this);
        
        this._biographyListView.add_itemClicked(
            function(sender, e) {
                that._biographyViewPanelSet.showPanel('LoadingPanel');
//                setTimeout(function() {
//                    that._biographyViewPanelSet.showPanel('BandMemberBioPanel');
//                }, 1000);        
            
                that._biographyDetails.set_itemID(e.id);
                that._biographyDetails.loadItem();                
            }
        );
        
        // If biography item does not have a picture,
        // show display panel once item has loaded
        // (with a slight delay)
        this._biographyDetails.add_itemLoaded(
            function(sender, e) {
                if (! e.item.ImageFileName) {
                    setTimeout(function() {
                        that._biographyViewPanelSet.showPanel('BandMemberBioPanel');
                    }, 600);                        
                }                
            }
        );

//        if (this._biographyCount > 0) {
//            // this.loadBiography(this._biography1ID);
//            this._biographyDetails.set_itemID(this._biography1ID);
//            this._biographyDetails.loadItem();
//            
//            // this._biographyViewPanelSet.showPanel('BiographyViewPanel');
//        } else {
//            // this._biographyViewPanelSet.showPanel('NoBiographyPanel');
//        }

        // Call a function when the image has fully loaded in the browser...
        this._biographyImage.get_element().onload = function(evt) {
            that._biographyViewPanelSet.showPanel("BandMemberBioPanel");
        };
        
    },
    dispose: function() {        
        //Add custom dispose actions here
        BandSite.Biography.callBaseMethod(this, 'dispose');
    },
    
    _bandBioDivClicked: function() {
        var that = this;
        this._biographyViewPanelSet.showPanel('LoadingPanel');
        setTimeout(function() {
            that._biographyViewPanelSet.showPanel('BandBioPanel');
        }, 1000);
    }
        
}
BandSite.Biography.createProperty("bandID");
BandSite.Biography.createProperty("biographyViewPanelSet");
BandSite.Biography.createProperty("biographyListView");
BandSite.Biography.createProperty("bandBioImage");
BandSite.Biography.createProperty("biographyDetails");
BandSite.Biography.createProperty("biographyImage");
//BandSite.Biography.createProperty("biographyCount");
//BandSite.Biography.createProperty("biography1ID");
BandSite.Biography.createProperty("bandBioDiv");
BandSite.Biography.registerClass('BandSite.Biography', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
