(function( $ ) {

$.widget( "ui.songFilter", {  

    options: {
        filterTemplate: '#filter-template',
        templateName: 'filter-template',
        songArray: '#songs'
    },

    _init: function() {
        var self = this;

        this.$songArray = $(this.options.songArray);

        $(this.options.filterTemplate).template(this.options.templateName);


        this.$songArray.bind( 'arrayPageChanged.songArray.songFilter', function( event, page ) {
            $.tmpl(self.options.templateName, page).appendTo(self.element.empty());
        });
    },

    destroy: function() {
        $.Widget.prototype.destroy.apply(this, arguments);
        this.$songArray.unbind( 'arrayPageChanged.songArray.songFilter' );
    }

}); 

})( jQuery );


