﻿function vote() {
	PageMethods.Vote(storyid, voted);
	//AfterVote();
	return false;
}

function voted(result) {
    if (!result.error) {
        $(".votebutton").addClass("feedback");
        $(".votemessage").html("Thanks for your vote");
        $(".votebutton").html("Vote<span class='votesuffix'></span>");
        if (result.count == 1) {
            $(".votesuffix").html("");
        } else {
            $(".votesuffix").html("s");
        }
        $(".count").html(result.count);
        AfterVote();
    } else {
        $(".votemessage").html(result.error);
    }
	return false;
}

function AfterVote() {
    $.fancybox($("#AfterVote").html(),
		    {
		        'autoDimensions': false,
		        'width': 600,
		        'height': 'auto',
		        'transitionIn': 'none',
		        'transitionOut': 'none',
		        'overlayOpacity': 0.7
		    }
	    );        
}


function follow() {
    PageMethods.Follow(storyid, followed)
    return false;
}

function followed(result) {
    if (!result.error) {
        $(".followmessage").html("You are now following this future");
    } else {
        $(".followmessage").html(result.error);
    }
    return false;
}

function unfollow() {
    PageMethods.UnFollow(storyid, unfollowed)
    return false;
}

function unfollowed(result) {
    if (!result.error) {
        $(".followmessage").html("You are no longer following this future");
    } else {
        $(".followmessage").html(result.error);
    }
    return false;
}


