$(document).ready(function(){
	var url = window.location.href;//+'vote_handler.php';
	//var url = 'http://www.bmwland.ru/';
	url = url.substring(0,url.lastIndexOf('/')+1)+'vote_handler.php';
	
	//vote 
	$('a.vote').click(function(e){
		e.preventDefault();
		$(':radio').each(function(idx, item){
			if(item.checked) {
				item.checked=false;
				$.post(url, { vote: $(item).attr('_id') },
					function(data){
						var summa = 0;
						var text = "<table><td>";
						$.each(data, function(i,val){
							summa += parseInt(val.vote);
						})
						$.each(data, function(i,val){
							text+='<tr><td class=\"vote_style\" colspan=\'3\' scope=\"col\">'+val.answer+'</td></tr>';
							text+='<tr><td width=\"80\"><div align=\"left\"><img src="images/vote_line.jpg" width=\''+Math.ceil((parseInt(val.vote)/summa)*150)+'\' height=\'10\'></div><td>'
							text+='<td class=\"vote_style\" width=\"70\"><div align=\"center\">'+val.vote+'</div></td></tr>'
						})
						text+='</td></table><p class=\"left-menu\" align=\"center\"><a href=\"2index.php?vr=0\" style=\"text-decoration:none;\" >Результаты</a></p>';
						$('td.ui-vote').html(text);
				}, "json");
			}
		})
		return false; 
	}
	
	)
	
	
	$("a.resultvote").toggle(function () {
		$('a.vote').trigger('click');
    });
	//end vote
})