var HouseHelpController = {

    CurrentItem: 0,

    Init: function() {

        $('.next-item').click(function() {
            HouseHelpController.NextItem();
        });

        $('#help_house_type').click(function() {
            HouseHelpController.Check();
        });

    },

    Start: function() {

        HouseHelpController.CurrentItem = 1;

        HouseHelpController.DisplayItem();

    },

    NextItem: function() {

        HouseHelpController.CurrentItem++;

        HouseHelpController.DisplayItem();

    },

    Check: function() {

        var $chk = $('#help_house_type');

        if (!$chk.attr('checked'))
            $(".m28-3 input:checkbox[name$='" + $chk.val() + "']").attr('checked', false).closest('span').removeClass('checked');
        else
            $(".m28-3 input:checkbox[name$='" + $chk.val() + "']").attr('checked', true).closest('span').addClass('checked');

    },

    DisplayItem: function() {

        var count = 0;

        $.each(HouseHelp, function(key, value) {

            count++;

            if (HouseHelpController.CurrentItem == count) {

                $('.typetitle .heading1').html(value['title']);

                $('.typedesc img').attr('src', value['image']);
                $('.typedesc p').html(value['description']);

                $('.typelists .pros').html(value['pros']);

                $('.typelists .cons').html(value['cons']);

                $('#help_house_type').val(key);

                if (!$(".m28-3 input:checkbox[name$='" + key + "']").attr('checked'))
                    $('#help_house_type').attr('checked', false).closest('span').removeClass('checked');
                else
                    $('#help_house_type').attr('checked', true).closest('span').addClass('checked');

            }

        });

        $('.typetitle .current').html(HouseHelpController.CurrentItem);
        $('.typetitle .total').html(count);

        if (HouseHelpController.CurrentItem == count)
            $('.next-item').hide();
        else
            $('.next-item').show();

    }

}

$(document).ready(function() {

    HouseHelpController.Init();

});