var Bucket = Class.create();
Bucket.prototype = {
	id: '',
	name: '',
	subtitle: '',
	playlists: null,
  currentPlaylist: '',
  viewed: false,
	
	initialize: function( s_id, s_name, s_subtitle, a_playlists ){
		this.id = s_id;
		this.name = s_name;
		this.subtitle = s_subtitle;
		for( var i=0; i<a_playlists.length; i++ ){
			this.addPlaylist( a_playlists[i] );
		}
	},
		
  addPlaylist: function( o_playlist ){
    if( !this.playlists ){
      this.playlists = new Array();
    }
    this.playlists.push( o_playlist );
  },
  
  getPlaylist: function( id ){
    if( this.playlists ){
      return this.playlists.find( function(playlist){
        return( playlist.id == id );
      });
    }
  },
    
	show: function( playlistId ) {
    // turn off other nav
    currentlyOn = $('navPrimaryUL').getElementsByClassName( 'active' );
    if( currentlyOn && currentlyOn[0] ){
      currentlyOn[0].removeClassName( 'active' );
    }    
    // add 'active' style to current
    currentBucket = $( 'nav_' + this.id );
    currentBucket.addClassName( 'active' );
    // update page heading h2
		$('bucketTitle').update(this.name);
		// run the default playlist
    if( this.playlists ){
      var playlist = this.getPlaylist( playlistId );
      if( playlist ){
         this.currentPlaylist = playlist;
         this.currentPlaylist.show(); 
      }
      else {
        // clear the stage and navigation
        alert( 'invalid playlist' );
        hcom.presentation.loadStageWith( 'topics/coming_soon.htm' );
        hcom.presentation.clearPlaylistNav( );
      }
      this.markViewed();
      document.body.id = this.id;
    }
    else {
      // clear the stage and navigation
      hcom.presentation.loadStageWith( 'topics/coming_soon.htm' );
      hcom.presentation.clearPlaylistNav( );
    }
	},
  
  markViewed: function( ){
    this.viewed = true;
    li = $( 'nav_' + this.id );
    Element.extend( li );
    li.addClassName( 'viewed' ); 
  }
	
}; // end Bucket
