/**
 * Playlist Application - loads the app
 *
 * Copyright: (c)2007 CK Web Technologies
 * Author:    Chris Knowles <chris.knowles@ckweb.com.au>
 * Version:   $Id: App.js 22 2007-11-13 04:31:39Z Chris $
 */

var PlaylistApp = function()
{
    /**
     * Initialises the app components 
     */
    this.load = function(songlistCacheSize, autoSaveInterval)
    {
        var self = this; 
        
        // build the app
        this.build(songlistCacheSize, autoSaveInterval);
        
        // load the palyer
        //this.Player.load();
                
        // set initial messages
        this.Songlist.setMessage(this.Content.songlistIntro);
        this.Playlist.setMessage(this.Content.playlistIntro);

        // set listeners
        $E.listen('playlist', 'click', function(e){self.Playlist.moveRow(e)});
        $E.listen('saveButton', 'click', function(){self.Storage.save()});
        $E.listen('clearButton', 'click', function(){self.Playlist.clear()});
        $E.listen('printButton', 'click', function(){self.Printer.print()});
        $E.listen('menu', 'click', function(e){self.Songlist.fetch(e)});
        $E.listen('artist', 'click', function(e){self.Songlist.fetchArtist(e)});
        $E.listen('title', 'click', function(e){self.Songlist.fetchTitle(e)});
        $E.listen('searchButton', 'click', function(e){self.Songlist.search(e)});
        $E.listen('introLogin', 'click', function(){self.User.showChallenge("login")});
        $E.listen('introPwd', 'click', function(){self.User.showChallenge("forgottenPassword")});
        $E.listen('songlist', 'click', function(e){self.Songlist.handleClick(e)});
        $E.listen('playlist', 'click', function(e){self.Playlist.handleClick(e)});
        $E.listen(window, 'unload', function(){self.Storage.autoSave()});
         
    };
    
    /**
     * Creates all the components of the app 
     */
    this.build = function(songlistCacheSize, autoSaveInterval)
    {
        this.Menu     = new $W.Menu('menu');
        this.User     = new User(this);
        this.Player   = new Player(this);
        this.Songlist = new Songlist(this, songlistCacheSize);
        this.Playlist = new Playlist(this);
        this.Printer  = new Printer(this);
        this.Storage  = new Storage(this, autoSaveInterval);
        this.Content  = new Content;
    };
    
}
