/**
 * @author luis
 */
	
	function processJson(data) {
		$('#image_container').empty();
			if(data.status!="ok"){
				$('#image_container').empty().html('<strong>Ndish! Ocurrió un error - </strong>'+data.msg+'');
			}else{
				$('#file_id').val(data.file_id);	
				$("<div>").attr('id',data.file_id).css('background-image','url(/media/img/'+data.file_id+'--200-'+data.file_name+')').addClass('image_thumb').appendTo("#image_container");
			}
	}

	function processJson2(data) {
		if(data.status=='ok'){
			window.location = '/preview/'+data.candidate_id;
		}	
	}

	$(function(){
		
		$('.megusta').click(function(){
			$('#alert').show('slow').html('<img src="/icms/img/ajax-loader.gif" border="0" /> esperá un flash...');
			var context = $(this).parent().parent();
			var candidate_id = $(this).parent().attr('id');
			$('.points',context).html('<img src="/icms/img/ajax-loader.gif" border="0" />');
			$.post('/inc/ajax.php',{'action':'vote',candidate_id:candidate_id},function(data){
				if(data.status =='ok'){
					$('#alert').empty();
					$('.points',context).html(data.votes_text);
				}else{
					$('#alert').html(data.msg).delay(1000).hide('slow');
					$('.points',context).html(data.votes_text);
				}
			},'json');
			return false;
		});
		
		$('.btn_share').click(function(){
			var candidate_id = $(this).parent().attr('id');
			var share = {
			  method: 'stream.share',
			  u: 'http://apps.facebook.com/unanocheconlarissa/candidate/'+candidate_id
			};
			FB.ui(share);
			return false;
		});
		
	    $('#btn_accept').click(function(){
	    	var candidate_id = $('#candidate_id').val();
	    	$.post('/inc/ajax.php',{action:'accept-tos',candidate_id:candidate_id},function(data){
	    		if(data.status=='ok'){
	    			window.location = '/candidate/'+candidate_id;
	    		}
	    	},'json');
	    	return false;
	    });
	    
		$('#Filedata').change(function(){
			$('#image_container').empty().html('<strong>Esperá un flash- </strong><img src="img/ajax-loader.gif" /> Subiendo la foto...');
			$("#form_image").submit();
		});

	    $('#btn_submit_photo').click(function(){
	    	var file_id = $('#file_id').val();
	    	if(file_id=='0'){
	    		alert('Tenés que subir una foto!');
	    	}else{
		    	$('#form_description').submit();
	    	}
	    	return false;
	    });
	    
	});
