function ToggleInput(input) {
    var field = $(input).data("modify-attr");
    if($(input).attr(field) == $(input).data("focused"))
    {
        $(input).attr(field, $(input).data("unfocused"));
    }
    else if($(input).attr(field) == $(input).data("unfocused"))
    {
        $(input).attr(field, $(input).data("focused"));
    }
}

function NavbarWidth() {
    parentWidth = $("#navbar").parent().width();
    $("#navbar").width(parentWidth - 73);
}

$(document).ready(function() {
    NavbarWidth();
    
    $(window).on("resize", function() {
        NavbarWidth();
    });

    $("#LoginBar form").children().each(function() {
        var field = $(this).data("modify-attr");
        if(typeof(field) != "undefined" && field != "")
        {
            var data = $(this).data("focused");
            $(this).attr(field, data);
        }
    });
    
    $(".clickable").on("click", function() {
        console.log("A clickable was clicked! :O");
        window.location.href = $(this).data("href");
    });
});

$(document).on("focus", ".LoginInput", function() {
    ToggleInput(this);
    $("#LoginBar form").children().each(function() {
        $(this).removeClass("UnfocusedInput");
        $(this).addClass("FocusedInput");
    });
});

$(document).on("blur", ".LoginInput", function() {
    ToggleInput(this);
    var AllDefaults = true;
    $(".LoginInput").each(function() {
        if($(this).attr($(this).data("modify-attr")) != $(this).data("focused"))
            AllDefaults = false;
        else {
            $(this).removeClass("FocusedInput");
            $(this).addClass("UnfocusedInput");
        }
    });
    if(AllDefaults) {
        $("#LoginButton").removeClass("FocusedInput");
        $("#LoginButton").addClass("UnfocusedInput");
    }
});
