$(function () {
    $('#navbarCollapse').hide();
    $('.navbar-toggler').on('click', function () {  
        if (!$('#navbarCollapse').is(":visible") ) {
            $('#navbarCollapse').slideDown();
        } else {
            $('#navbarCollapse').slideUp();
        }
    });
});

function subHeadingData() {
    // takes cookie string and parses into json object to use below.
    // set and deleted on auth.
    var iCuroCookieData = $.parseJSON($.cookie("iCuroUser"));

    console.log(iCuroCookieData);

    var subHeaderFullName = $('#sub-header-username');
        subHeaderFullName.text(iCuroCookieData.given_name + ' ' + iCuroCookieData.family_name);

    var subHeaderUniqueId = $('#sub-header-id b');
        subHeaderUniqueId.text(iCuroCookieData.USER);

    getProgress(iCuroCookieData);
}

function getProgress(iCuroCookieData) {
    $('#sub-header-completion-content').html(iCuroCookieData.progress + '% complete');
    $('#sub-header-completion-progress span').attr('style', 'width:' + iCuroCookieData.progress + '%');
}

$(window).load(function () {
    // if cookie is set, run
    if ($.cookie('iCuroUser') != undefined) {
        subHeadingData();
    }
});

$(function () {
    // iOS fix for double clicking on hover
    $('a').on('click touchend', function(e) {
        var el = $(this);
        var link = el.attr('href');
        window.location = link;
    });
});