﻿Depend.ProductSelector = function(serverVars) {
    this.ServerVars = serverVars;
    this.Initialize();
};
Depend.ProductSelector.prototype = {
    Initialize: function() {
        var psContainer = this.ServerVars.container;
        var psSelection = null;

        var updateContinueState = function() {
            var next = $('.NavigationNext', psContainer)[0];
            if (next !== null) {
                if ($('input[@type=radio]:checked', psContainer).length == 1) {
                    $(next).removeClass('NavigationDisabled');
                    $(next).removeAttr("disabled");
                } else {
                    $(next).addClass('NavigationDisabled');
                    $(next).attr("disabled", true);
                }
            }
        };

        var updateSelectionState = function(source) {
            var success = false;
            $('input[@type=radio]', psContainer).each(function() {
                if (this.checked) {
                    $(this).parent().addClass('Selected');
                } else {
                    $(this).parent().removeClass('Selected');
                }
            });
            updateContinueState();
        };

        $('li > a', psContainer).click(function() {
            var radio = $('input[@type=radio]', this)[0];
            if (radio !== null) {
                radio.checked = !radio.checked;
            }
            updateSelectionState(this);
            return false;
        });

        updateSelectionState();
    }
};
Depend.Extend(Depend.ProductSelector, Depend.Core);
