if (typeof OV == "undefined" || !OV) {
    var OV = {};
}

OV.voter = {};

OV.voter.castVote = function(e, args){
	YAHOO.util.Event.preventDefault(e);
	var id = args[0];
	var type = args[1];
	if (args[2]) var update_id = args[2];
	else var update_id = "user_votable_count_" + id; 
	callback = {
		success: function(o){
			var result = YAHOO.lang.JSON.parse(o.responseText);
			if (result["count"] == null) {
			  if(result["message"] == "You must be logged in to vote.") {
			    window.location = "/session/new";
			  } else {
			    alert(result["message"]);
			  }
			} else {
			  if (result["count"] != null) {
			  	var user_vote_counts = YAHOO.util.Selector.query('strong[name='+o.argument+']');
				for (var i=0; i<user_vote_counts.length; i++) {
			  		user_vote_counts[i].innerHTML = result["count"];
				}
			  }
			}
		},
		failure: function(o){
			alert('error');
		},
		argument: update_id
	}
	
	var infoObj = YAHOO.util.Connect.asyncRequest('GET', "/user_votes/new?id="+id+"&type="+type, callback);
}
