jQuery(document).ready(function (){
	update();
	setInterval("update()", 10000);
});

function view_statistics(data) {
	var top = parseInt(data.top);
	var flop = parseInt(data.flop);
	var sum = top + flop;
	if(jQuery('#song_vote').html()=='<ul><li class="itemza"><a href="#" onclick="vote_yes();return false;"><span>За</span></a></li><li class="itempro"><a href="#" onclick="vote_no();return false;"><span>Против</span></a></li></ul>')
	{
		jQuery('#song_vote').html('<p class="danke">Vielen Dank!</p>');
		setTimeout('change_class()',5000);
	}
}

function change_class()
{
	jQuery('#song_vote').html('<div class=\"noactive\"></div>');
}
function update() {
	jQuery.ajax({
		url: 'radio/ajax.php',
		type: 'post',
		dataType: 'json',
		data: {
			action: 'update'
		},
		success: function (data){
			if (data !== false) {
				jQuery('#song_name').html(data.song_name);
				//alert(data.statistics);
				if (data.statistics == false) {
					jQuery('#song_vote').html('<ul><li class="itemza"><a href="#" onclick="vote_yes();return false;"><span>За</span></a></li><li class="itempro"><a href="#" onclick="vote_no();return false;"><span>Против</span></a></li></ul>');
				}else
				{
					jQuery('#song_vote').html('<div class=\"noactive\"></div>');
				}
			} else {
				jQuery('#song_name').html('error');
			}
		}
	});
}
function vote_yes() {
	jQuery.ajax({
		url: 'radio/ajax.php',
		type: 'post',
		dataType: 'json',
		data: {
			action: 'vote_yes',
			song_name: jQuery('#song_name').html()
		},
		success: function (data){
			if (data !== false) {
				view_statistics(data.statistics);
			} else {
				jQuery('#song_vote').html('error');
			}
		}
	});
}
function vote_no() {
	jQuery.ajax({
		url: 'radio/ajax.php',
		type: 'post',
		dataType: 'json',
		data: {
			action: 'vote_no',
			song_name: jQuery('#song_name').html()
		},
		success: function (data){
			if (data !== false) {
				view_statistics(data.statistics);
			} else {
				jQuery('#song_vote').html('error');
			}
		}
	});
}
