$(document).ready(function () {

    $("#slider").easySlider({
        auto: true,
        continuous: true,
        numeric: false,
        pause: 4000
    });


    $('.mandatory').after('<span class="mandatory-symbol">*</span>');

    $('#select-parts select').uniform({selectAutoWidth: false});
    


$('#brand').live('change', function() {
    var brand = $(this).val();
    $.get(BASE_URL+'ajax/models.php?id='+brand, function(msg) {
        $('#model').html(msg);
        $('#type').html('<option value="0"> -- V&auml;lj typ -- </option>');
        $.uniform.update("#model");
        $.uniform.update("#type");
        updateMenu();
    });
    updateMenu();
});

$('#model').live('change', function() {
    var model = $(this).val();
    $.get(BASE_URL+'ajax/types.php?id='+model, function(msg) {
        $('#type').html(msg);
        $.uniform.update("#type");
        updateMenu();
    });
    updateMenu();
});

$('#type').live('change', function() {
    updateMenu();
});

function updateMenu() {
    var brand = $('#brand').val();
    var model = $('#model').val();
    var type = $('#type').val();

    var searchString = brand+','+model+','+type;
    //var spinner = $('<img/>').attr('src', BASE_URL+'img/spinner.gif');
    //var spinnerContainer = $('<div/>').css('text-align', 'center').html(spinner);
    //$('#categories').html(spinnerContainer);
    $.get(BASE_URL+'ajax/menu.php?q='+searchString, function(msg) {
        $.get(BASE_URL+'ajax/choices.php', function(html) {
            $('#js-choice-container').html(html);
        });
        $("#category_menu").remove();
        $("#categories").html(msg);
        $('#category_menu').treeview({
            persist: "location",
            collapsed: true,
            unique: true
        });
    });
}
});

