$(document).ready(function() {
    try { prettyPrint(); } catch(e) {}
    
    $('div.button a').button({
        text: false,
        icons: {
            primary: 'icon-twitter'
        }
    });
	
    $('div.button a').click(function(e) { 
        var resource = e.currentTarget.href.split('#!')[1];
        
        $.ajax({
            cache: false,
            url: resource,
            dataType: 'JSON',
            type: 'GET',
            complete: function(xhr, status) {
                if(status == 'success') {
                    var obj = $.parseJSON(xhr.responseText);
                    
                    if(obj.success) alert('Tuitado com sucesso!');
                    else alert(obj.message + '\n\n---\nErro:\n-> ' + obj.exception);
                }
                else {
                    alert('Não foi possivel executar o twitter!')
                }
            }
        })
        
        return false; 
    });    
});
