function sendNotifications(urlName, button) {
    $.ajaxSetup({ cache: false });
    $.getJSON("/api/1/sendNotifications?urlName=" + urlName, function(data) { });
    button.value = "Message Sent";
}

function confirmNotification(urlName, button) {
    if (confirm("Are you sure you want to send a notification to all your friends?")) {
        sendNotifications(urlName, button);
    }
    return false;
}

function displayInviteDialog(facebookUserId, host, causeUrlName, causeTitle) {
    FB.ensureInit(function() {
        var dialog = new FB.UI.FBMLPopupDialog('Invite', '');
        var fbml = $("#inviteSelector").html();
        dialog.setFBMLContent(fbml);
        dialog.setContentWidth(630);
        dialog.setContentHeight(510);
        dialog.show();
    });
}

$(document).ready(function() {
    $(".facebookAlbumSelector").live("click", function() {
        var id = $(this).attr("id");
        var page = 0;
        updateAlbum(id, page);
        $(this).addClass("selected");
    });

    $("#nextPage").live("click", function() {
        var id = $("#currentAlbum").val();
        var page = parseInt($("#currentPage").val()) + 1;
        updateAlbum(id, page);
    });

    $("#previousPage").live("click", function() {
        var id = $("#currentAlbum").val();
        var page = parseInt($("#currentPage").val()) - 1;
        updateAlbum(id, page);
    });

    $(".facebookPhoto").live("click", function() {
        var src = $(this).children(".largePhoto").val();
        $("#ProfileB").attr("src", src);
        $("#userImageSrc").val(src);
    });

    function updateAlbum(id, page) {
        var photoAlbum = $(".photoAlbum");
        photoAlbum.html($("#facebookLoading").html());
        $.ajaxSetup({ cache: false });
        $.getJSON("/api/1/GetFacebookAlbum?albumId=" + id + "&page=" + page, function(data) {
            if (data != null) {
                photoAlbum.html(data.albumHtml);
            }
        });
    }
});


function savePermissionChoice(x, permission) {
    var status = x != null && x != "" && x.toString().indexOf(permission, 0) != -1 ? "Allowed" : "Disallowed";
    $.ajaxSetup({ cache: false });
    $.getJSON("/api/1/UpdatePermissions?" + permission + "=" + status, function(data) { });
}