$(document).ready(function (){
	var barMax = 150;
	var viewVote = 0;
	var voteMsg = ['「◎」への投票状況を見る', '全ての印への投票状況を見る'];

	function toggleOdds(obj)
	{
		if (viewVote) {
			$( '#odds-table .vote' ).show();
			$( '#odds-table .vote-detail').hide();
		} else {
			$( '#odds-table .vote' ).hide();
			$( '#odds-table .vote-detail').show();
		}
		if (obj) {
			$(obj).html('<span>' + voteMsg[viewVote] + '</span>');
		}
		viewVote = viewVote ^ 1;
	}
	$( '#odds-table' ).wrap( '<div class="table-outline" />' );
	$( '#odds-table .vote div' ).append( '<span />' );

	var votes = new Array();
	$( '#odds-table .vote div' ).each( function( idx ) {
		votes.push( Number( $( this ).text() ) );
	});
	var voteMax = Math.max.apply( null, votes );
	var voteRate = (voteMax == 0) ? 0 : barMax / voteMax;
	$( '#odds-table .vote div' ).each( function( idx ) {
		var vote = Number( $( this ).text() );
		var barWidth = Math.ceil( vote * voteRate );
		$( 'span', this ).css( 'width', barWidth + 'px' ).attr( 'title', vote + '票' );
	});
	$( '#chgodds' ).click( function(){
		toggleOdds(this);
		return false;
	});
});
