$(function() {
    $('#videoPlaying-interestedArrow').click(function() {
        $('.videoPlaying-interested').toggleClass('open');
        $('.videoPlaying-interestedArrowUp').toggle();
        $('.videoPlaying-interestedArrowDown').toggle();
    });

    setTimeout(function() {
        var url = $('iframe').attr('src')
        url = url+'?autoplay=1';
        $('iframe').attr('src', url)
        }, 2000); // 2000 = 2s, 10s= 10000

    $("#like_video").click(function(e){
        e.preventDefault();

        var parameters = {
            id: $(this).attr("data-id"),
            action: "like_video"
        };

        $.ajax({
            url: '../ajax',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if(data.success == true){
                    swal("Video Liked");
                }else{
                    swal({
                        title: "Not Logged In",
                        text: "Please login or signup first.",
                        buttons: true,
                        type: 'warning',
                        showCancelButton: true,
                        cancelButtonText: 'Cancel',
                        confirmButtonText: 'Login'
                        },function(){
                            window.location = "../login-signup"
                    })
                }
            },
            data: parameters
        });
    });

    $("#watch_later_video").click(function(e){
        e.preventDefault();

        var parameters = {
            id: $(this).attr("data-id"),
            action: "watch_later_video"
        };

        $.ajax({
            url: '../ajax',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if(data.success == true){
                    swal("Video Saved");
                }else{
                    swal({
                        title: "Not Logged In",
                        text: "Please login or signup first.",
                        buttons: true,
                        type: 'warning',
                        showCancelButton: true,
                        cancelButtonText: 'Cancel',
                        confirmButtonText: 'Login | Signup'
                        },function(){
                            window.location = "../login-signup"
                    })
                }
            },
            data: parameters
        });
    });

    $("#submit_job").on("click", function(){
        var parameters = {
            message: $("#message-text").val(),
            video_id: $("#video_id").val(),
            action: "job_shadow"
        };
        $.ajax({
            url: '../ajax',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if(data.success == true){
                    swal("Thanks for contacting us");
                    $("#resumeModal").modal("toggle");
                }else if(data.error !== undefined) {
                    swal({
                        title: "Error",
                        text: data.error,
                        type: 'error'
                    });
                }else{
                    swal({
                        title: "Not Logged In",
                        text: "Please login or signup first.",
                        buttons: true,
                        type: 'warning',
                        showCancelButton: true,
                        cancelButtonText: 'Cancel',
                        confirmButtonText: 'Login | Signup'
                        },function(){
                            window.location = "../login-signup"
                    })
                }
            },
            data: parameters
        });
    });

    $('.rating input[type="radio"]').click(function(){
        if ($(this).is(':checked')){
            var rating = $(this).val();
            var parameters = {
                id: $(this).attr("data-id"),
                rating: rating,
                action: "rate_video"
            };
            $.ajax({
                url: '../ajax',
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if(data.success == true){
                        swal("Thanks for rating");
                    }else if(data.error !== undefined) {
                        swal({
                            title: "Error",
                            text: data.error,
                            type: 'error'
                        });
                    }else{
                        swal({
                            title: "Not Logged In",
                            text: "Please login or signup first.",
                            buttons: true,
                            type: 'warning',
                            showCancelButton: true,
                            cancelButtonText: 'Cancel',
                            confirmButtonText: 'Login | Signup'
                            },function(){
                                window.location = "../login-signup"
                        })
                    }
                },
                data: parameters
            });
        }
    });

    $(".not-logged-in-swal").on("click", function(){
        swal({
            title: "Not Logged In",
            text: "Please login or signup first.",
            buttons: true,
            type: 'warning',
            showCancelButton: true,
            cancelButtonText: 'Cancel',
            confirmButtonText: 'Login | Signup'
            },function(){
                window.location = "../login-signup"
        })
    });



    if (typeof popupVideoLimitNotice !== 'undefined') {
        swal({
            title: "Not Logged In",
            text: "Please login or signup first to watch more videos.",
            buttons: true,
            type: 'warning',
            showCancelButton: true,
            cancelButtonText: 'Cancel',
            confirmButtonText: 'Login'
            },function(){
                window.location = "../login-signup"
        })
    }
});