$.links = {
    vote_up: function(id) { return $.links.vote(id, true); },
    vote_down: function(id) {return $.links.vote(id, false); },
    vote: function(id, up) {
        $('#rating_'+id).fadeTo(500, 0.01, function() {
            $.post('/links/vote/'+id+'/'+(up?'up':'down')+'/', {}, function(data) {
                $('#rating_'+id).html(data).fadeTo(500, 1.00);
            }, 'html');    
        });
            
        return false;
    },
    
    submit_msg: function() {
        $.prompt('You must <a href="/signup/">signup</a> or <a href="/login/">login</a> to submit a link.',
                    {'buttons': {}});
        return false;
    },
    
    vote_msg: function() {
        $.prompt('You must <a href="/signup/">signup</a> or <a href="/login/">login</a> to vote.',
                    {'buttons': {}});
        return false;
    }
}

$(document).ready(function() {
    $('.deletr').mouseover(function() {
        $(this).fadeTo(500, 1.0);
    });
    $('.deletr').mouseleave(function() {
        $(this).fadeTo(500, 0.25);
    });
    $('.deletr').click(function() {
        var id = $(this).attr('id').substring(7);
        $.prompt('Are you sure you want to delete this link?',
					{buttons: { 'Yes!': true, 'No!': false }, focus: 1,
					callback: function(v, m, f) {
			if(v) {
				location.href = '/delete_link/'+id+'/';
			}
		}});
    });
});

