$(document).ready( function( ){
	
	init_polls( );

});

function init_polls( )
{
	//--- poll -------------
	$("#poll_vote").click(function(){

		var sel_answerID = $("#form-poll input[@name=answerID][@checked]").val( );

		if( typeof sel_answerID != 'undefined' )
		{
			$.post( base_url+'poll/vote/'+ $("#poll_id").val( ),
				{ "answerID":sel_answerID },
				function(msg){
					$("#form-poll").html( msg );
				}
			);
		}
		else
		{
			$.get( base_url+'poll/view/'+ $("#poll_id").val( ), {},
				function( html ){
					$(".poll:first").after( html );
					$(".poll:first").remove( );
					init_polls( );
				}
			);
		}
	});
	
	$("#poll_results").click(function(){
		if( $("#poll_id").val( ) )
		{
			$("#form-poll").showLoader( loader_gif, true );
//			h = $("#form-poll").height( );
//			$("#form-poll").html( '<div style="text-align: center"><img src="'+ assets_url +'images/loader.gif" /></div>' );
//			$("#form-poll").height( h );
			$("#form-poll").load( base_url+'poll/results/'+ $("#poll_id").val( ), function(){ $(this).hideLoader( ) } );//.css( "visibility", "hidden" ).fadeIn( );
		}
	});
	//------------------------
}