//
// $Id: BoatSummaries.js,v 1.1.1.1 2010/02/26 08:30:04 steve Exp $
//
var BoatSummaries = function() {

    this.init = function() {
    
        var self = this
        
        $('#boatSummariesSelector .boatSummarySelector').click( function() { self.toggleSummaries($(this)) })
    }
    
    this.toggleSummaries = function(elem) {
    
        var self = this
        
        var len
        var id = $(elem).attr('id').split('_')

        $('#boatSummariesDiv').hide()
        if (id[1] == 'All') {
            $('#boatSummariesDiv .boatSummaryDiv').show()
            len = $('#boatSummariesDiv .boatSummaryDiv').length
            $('#nBoatSummaries').html(self.nBoats(len))
        } else {
            $('#boatSummariesDiv .boatSummaryDiv').hide()
            $('#boatSummariesDiv .boatCategory_' + id[1]).show()
            len = $('#boatSummariesDiv .boatCategory_' + id[1]).length
            $('#nBoatSummaries').html(self.nBoats(len))
        }
        $('#boatSummariesDiv').slideDown()
    }
    
    this.nBoats = function(n) {
    
        if (n == 0) {
            return "No boats"
        } else if (n > 1) {
            return n + " boats"
        } else {
            return "1 boat"
        }
    }

}
