Ext.namespace('Card');
Card.Instance = function(state){
    this.state = state;
    this.init();
};

Ext.apply( Card.Instance.prototype, {
    
    init : function(){
        
        if( this.state.music.length > 0 ){
            this.createBoombox();
        }
        if( this.state.images.length > 1 ){
            this.createSlideshow();
        }
    },
    
    createBoombox :function(){
        this.player = new Fabs.boombox.Player({
            autoPlay    :true,
            shuffle     :false,
            volume      :80
        });
        this.player.getPlaylist().addTracks(this.state.music);
        this.boombox = new Fabs.boombox.ui.FullPlayer({
            player: this.player,
            renderTo: 'boombox',
            width: 300,
            maxListHeight: 150,
            draggable: true,
            resizeable: true
        });
    },
    
    createSlideshow : function(){
        // prepare the image data.
        var data=[];
        Ext.each( this.state.images, function(image){
            data[data.length] = {
                thumb : {
                    url: image.small,
                    width: image.small_x,
                    height: image.small_y
                },
                large : {
                    url: image.large,
                    width: image.large_x,
                    height: image.large_y
                }
            };
        });
        MYG.Gallery.create('gallery-ct',{images:data,autoPlay:true});
    }
})


Card.make = function(state){    
    Card.inst = new Card.Instance(state);
};
