$(function() {
    
    $("#scrollUpArrow").click(function(){
        $('html, body').animate({scrollTop: '0px'}, 300);
    });
    
    var selectedCategories = [];

    $(".categorySelect-categories").click(function(event){
        console.log(event);
        var categoryName = $(this).text().trim();
        console.log(categoryName);

        var categoryId = parseInt($(this).find("input").val());

        if(selectedCategories.indexOf(categoryId) === -1){
            if(selectedCategories.length < 4){
                selectedCategories.push(categoryId);
                $(this).addClass('selected');
            }else{
                swal("You may only select up to 4 categories at once", "", "error");
            }
        } else {
            var index = selectedCategories.indexOf(categoryId);

            var removed = selectedCategories.splice(index, 1);
            $(this).removeClass('selected');
        }

        $("#selectedCategories").val(selectedCategories);
        console.log(selectedCategories);
        if(selectedCategories.length > 0){
            $("#next_button").attr("disabled", false);
        }else{
            $("#next_button").attr("disabled", true);
        }
        
        // auto submit on click 
        $("#findVideosForm").submit();
        
    });


    $('#career_request').submit(function(event){
        event.preventDefault();

        var parameters = {
            career: $( "input[name='career']").val(),
            action: "career_request"
        };

        $.ajax({
            url: 'ajax',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if(data.success == true){
                    swal("Thank You","Your career request has been received :) ","success");
                }else if(data.error == "not_logged"){
                    swal({
                        title: "Not Logged In",
                        text: "Please login first before requesting a category",
                        buttons: true,
                        type: 'warning',
                        showCancelButton: true,
                        cancelButtonText: 'Cancel',
                        confirmButtonText: 'Login'
                    },function(){
                        window.location = "login-signup"
                    })
                }else{
                    swal({
                        title: "Error",
                        text: data.error,
                        type: 'error'
                    });
                }
            },
            data: parameters
        });
    })

    // $("#findVideosForm").submit(function(event){
    // 	// event.preventDefault();

    // 	console.log(selectedCategories);




    // });
});
