

















(function($) {
$.ti.categories = $.prototype = {

    // Categories object for drop down option generation
    categories: {},

    // populate the categories object with all unique categories for the trip
    get: function() {
        var activity;

        // Empty the categories object before we begin
        this.categories = {};

        if($.ti.tripData.trip.tripActivities) {
            for (activity in $.ti.tripData.trip.tripActivities.activity) {
                if($.ti.tripData.trip.tripActivities.activity.hasOwnProperty(activity)) {
                    if($.ti.utils.isUnique(this.categories, $.ti.tripData.trip.tripActivities.activity[activity].actCategory)) {
                        $.ti.utils.appendToObject(this.categories, $.ti.tripData.trip.tripActivities.activity[activity].actCategory);
                    }
                }
            }
        }

        // If we have at least one category added then re-populate the select
        if(this.categories[0]) {
            this.fill();
        } else {
            $('#showMe').html('<option>non hai opzioni</option>');
        }
    },

    // Create options and populate the category select with them
    fill: function() {
        var category, li, length;

        length = $.ti.utils.objectLength($.ti.tripData.trip.tripActivities.activity);

        $('#showMe').unbind('change.filterCategories');

        $('#showMe').empty();
        li = '<option value="all">tutto (' + length + ') opzioni</option>';
        $('#showMe').append(li);

        for(category in this.categories) {
            if(this.categories.hasOwnProperty(category)) {

				optionText=this.categories[category];
				if (optionText==="Accommodation")			optionText='Alloggio';
				if (optionText==="Activities")				optionText='Attività';
				if (optionText==="Events")					optionText='Cose da fare o da vedere';
				if (optionText==="Food and Drink")			optionText='Dove mangiare';
				if (optionText==="Getting around Ireland")	optionText='Andare in giro';
				if (optionText==="Getting There")			optionText='Andare in giro';
				if (optionText==="Holiday Packages")		optionText='Pacchetti vacanza';
				if (optionText==="Sights & Culture")		optionText='Panorami & Cultura';
				if (optionText==="Things to see and do")	optionText='Cosa da fare e da vedere';
				if (optionText==="User Generated")			optionText='Creata dall&#39;utente';
				if (optionText==="Whats on")				optionText='Che cosa succede';
/*
				section.about-ireland  = About Ireland
				section.getting-there=Getting There
				section.holiday-packages=Holiday Packages
				section.ireland-places-to-go = Places to go
				section.ireland-things-to-see-and-do  = Things to see and do
				section.things-to-see-and-do  = Things to see and do
				section.ireland-plan-your-visit = Plan your visit
				section.accommodation = Accommodation
				section.ireland-travel-offers = Travel offers

				section.default = Highlights
				section.pts = Places to stay
				section.act = Activities
				section.sc = Sights & Culture
				section.pte = Places to eat
				section.wo = What's on
				section.gt = Getting Around
				section.ttsod = Things to see and do
				section.to = Travel offers
				section.offers = Offers
*/
                li = $('<option value="' + this.categories[category] + '">' + optionText + '</option>');

                length = (length + 1);
                $('#showMe').append(li);
            }
        }

        $('#showMe').val($.ti.tripData.trip.selectedCategory);

        $('#showMe').bind('change.filterCategories', function() {
            $.ti.categories.filter(this.value);
        });
    },

    // Apply category filtering to back contents
    filter: function(category) {
        $.ti.tripData.trip.selectedCategory = category;
        if(category === 'all') {
            $.ti.bag.reset();
            $.ti.bag.fill();
        } else {
            $.ti.bag.reset();
            $.ti.bag.fill(category);
        }

    }

};
})(jQuery);
