$(document).ready(function(){
	$("div.scrollable").scrollable({size: 1, clickable: false, keyboard: false, speed: 600}).circular().autoscroll({interval: 5000});
//	$("div.jokes").scrollable({vertical:true, size: 1, loop: true, clickable: true, speed: 600}).circular().autoscroll({interval: 4800});
});

function ff_vote(ff, f, jump) {

	if (jump == 0) {
		api = $("div.scrollable").scrollable({api: true}).stop();
	}

	var v_button = $('.virtual_vote_button_'+ff+'_'+f);
	v_button.css('display', 'none');
 
	$('.virtual_vote_loading_'+ff+'_'+f).html("<img src='img/vote_loading.gif' width='32' height='32' alt='im loading'>");
 
	var url = '?a=ajax';
	$.post(
		url,
		'sa=ff_vote&ff='+ff+'&f='+f,
 
		function(data, textStatus) {
			if (textStatus == 'success') {
				ar = data.split('|');
				if (ar[0] == 'OK') {
					$('.virtual_vote_loading_'+ff+'_'+f).html(ar[1]);
					$('.virtual_label-votes-'+ff+'-'+f).html(ar[2]+' глас'+(ar[2] == '1' ? '' : 'а'));

					if (jump) {
						$(document).wait(500, 
						function () {
								//$.scrollTo($('#scroll_here'), 400, { axis:'y' });
								$(document).wait(800, 
								function () {
									$('.virtual_radio').attr('checked', false);
									$('.r_choice_'+f).attr('checked', true);

									//f_name = $('#f_name_'+f).html();
									//$('#comment_for_f').html(f_name);

									//$('#comment_h2').tooltip('#versus-tip');
									//$('#comment_h2').tooltip().show();
								});
								
						});
					}
				}
			}
			else {
				alert('PROBLEM: '+textStatus);
			}
		},
		'text'
	);
}

function c_vote(c_id, vote) {
	var c_id2 = c_id;
	var vote2 = vote;

	$('#c_vote_box_'+c_id).hide();
	$('#c_vote_box_i_'+c_id).html("<img src='img/comment-loading.gif' width='27' height='20' alt='im loading'>");
	$('#c_vote_box_i_'+c_id).show();

	var url = '?a=ajax';
	$.post(
		url,
		'sa=c_vote&c='+c_id2+'&v='+vote2,

		function(data, textStatus) {
			if (textStatus == 'success') {
				ar = data.split('|');
				if (ar[0] == 'OK') {
					$('#c_vote_box_i_'+c_id2).html('');
					$('#c_mark_'+c_id2).html(ar[1]);
					if (ar[2] != '') {
						$(".votes_"+ar[2]).html(ar[3]);
					}
				}
			}
			else {
				alert('PROBLEM: '+textStatus);
			}
		},
		'text'
	);
}
