$(function ($) {
    var $page = $('#page'),
        $accountUtils = $('#account-utils'),
        $player = $('#player'),
        $nowPlaying = $('#now-playing');

    $player.player();

    $page.loginManager()
        .bind('loggedIn.loginManager', function (event, profile) {
            $accountUtils.accountUtils('userIsLoggedIn', profile);
        })
        .bind('loggedOut.loginManager', function (event) {
            $accountUtils.accountUtils('userIsNotLoggedIn');
        });

    $accountUtils.accountUtils({
        createAccount: function () {
            $page.loginManager('createAccount');
        },

        loginToAccount: function () {
            $page.loginManager('login');
        },

        logoutFromAccount: function () {
            $page.loginManager('logout');
        }
    });

    // Set up deep links
    $page.find('.deep-link').click(function (event) {
        var clickedHref = $(this).attr('href');

        event.preventDefault();
        $.location().update(clickedHref);
    });

    $nowPlaying.nowPlaying();
});

