function google_plus_callback(data)
{		
	var p_info = new Array(4);
	p_info = post_info(data['state'], data['href']);
		
	$.post('/news/'+p_info[3]+'/'+p_info[0]+'/'+p_info[1], function(data_get){
		after_post(data_get, data['state']);
	});	
}

window.fbAsyncInit = function()
{
	FB.init({appId: '156868327760110', status: true, cookie: true, xfbml: false});
	var vote_qty = $('#votes_qty').text();
	
	FB.Event.subscribe('edge.create', function(href, widget)
	{
		var p_info = new Array(4);
		p_info = post_info('on', href);
		
		$.post('/news/'+p_info[3]+'/'+p_info[0]+'/'+p_info[1], function(data){
			after_post(data, 'on');
		});		
	});
	
	FB.Event.subscribe('edge.remove', function(href, widget)
	{
		var p_info = new Array(4);
		p_info = post_info('off', href);
		
		$.post('/news/'+p_info[3]+'/'+p_info[0]+'/'+p_info[1], function(data){
			after_post(data, 'off');
		});
	});
};

function post_info(status, url)
{
	var res = new Array(4);
	
	var url_a = url.split('/');
	res[0] = url_a[url_a.length-1];

	res[1] = $('.token').text();
	
	if(status == 'on')	
		res[3] = 'insert_vote';	
	else	
		res[3] = 'delete_vote';	
	
	return res;
}

function after_post(data, status)
{
	if($.trim(data) != '')
	{
		var vote_qty = $('#vote_qty-'+data).text();
		var qty_int = 0;
		
		if(status == 'on')		
			qty_int = parseInt(vote_qty) + 1;		
		else		
			qty_int = parseInt(vote_qty) - 1;
		
		$('#vote_qty-'+data).html(qty_int);
		//$('.social_box_index').hide();
	}	
}

$(document).ready(function(){
	$('.show_social_buttons').click(function(){
		var get_id = $(this).attr('id');
		var id = get_id.split('-');		
		$('.social_box_index').hide();
		
		if(id[1] != '')
			$('#social_box_index-'+id[1]).show();				
	});
	
	$('.social_box_exit').live('click', function(){
		$('.social_box_index').hide();
	});
});

