function check_option_status ()
{
	var btn = $("#pollSidebar input.sidebarButton");
	if ( $("#pollSidebar input.sidebar_option:checked").length )
	{
		btn.removeClass ( "disabled" ).removeAttr ( "disabled" );
	} else {
		btn.addClass ( "disabled" ).attr ( "disabled", "disabled" );
	}
}

function vote_and_show_results ( poll_id, option_id )
{
	var url = "/polls/get_results/";
	url += poll_id + "/";
	url += option_id + "/";
	
	$.ajax (
		{
			url: url,
			type: "get",
			success: function ( data )
			{
				$("#pollWrapper").slideUp ( function ()
					{
						// $(this).html ( data ).slideDown ();
						$("#pollSidebar").html ( data ).slideDown ();
					}
				);
				
			}
		}
	);
}

$(document).ready ( function ()
	{
		$("#pollSidebar input.sidebar_option").click ( function ()
			{
				check_option_status ();
			}
		);
		$("#pollSidebar input.sidebarButton").addClass ( "disabled" ).attr ( "disabled", "disabled" );
		$("#pollSidebar input.sidebarButton").click ( function ()
			{
				var poll_id = $("#pollSidebar input.poll_id").val ();
				var option_id = $("#pollSidebar input.sidebar_option:checked").val ();
				vote_and_show_results ( poll_id, option_id );
				return false;
			}
		);
		
		check_option_status ();
		
	}
);