/*
 * DrivingSales jQuery Library
 * File:	jquery.ds.voting.js
 * Purpose: voting functions
 *
 * Copyright (c) 2010 DrivingSales, Inc.
 *
 * Date: 4/16/2010
 */

function vote(content_type, vote_type, content_id)
{
	var id = 'vote-box-'+content_id;
	
	if(!$('#'+id+' .vote-actions .'+vote_type).hasClass('active'))
	{
		// Set status
		$('#'+id+' .status').html("Saving...").show('fast');
	
		// Add vote
		$.post(baseUrl+'ajax/calls_voting/vote', { vote: vote_type, cid: content_id, type: content_type }, function(json){
			if(json.success == 1)
			{
				$('#'+id+' .vote-actions a').removeClass('active');
				$('#'+id+' .vote-actions .'+vote_type).addClass('active');
				
				$('#'+id+' .vote-totals .like .num').html(json.new_likes);
				$('#'+id+' .vote-totals .dislike .num').html(json.new_dislikes);
				$('#'+id+' .vote-count').html(json.new_total);
				
				if(vote_type == "like")
				{
					$('#'+id+' .like_this a.like').hide();
					$('#'+id+' .like_this a.dislike').show();
				}
				else if(vote_type == "dislike")
				{
					$('#'+id+' .like_this a.dislike').hide();
					$('#'+id+' .like_this a.like').show();
				}
				
				$('#like-summary-'+content_id).html(json.like_summary);
				
				$('#'+id+' .status').html("Thanks!").delay(1000).hide('fast');
			}
		}, "json");
	
	}
}
