// JavaScript Document

// JavaScript Document
window.fbAsyncInit = function () {
 
    FB.init({
        appId: '144300658943324',
        status: true,
        cookie: true,
        xfbml: true
    });
 
 
 
    /* All the events registered */
 
    FB.Event.subscribe('auth.login', function (response) {
 
        // do something with response
        login();
 
    });
 
    FB.Event.subscribe('auth.logout', function (response) {
 
        // do something with response
        logout();
 
    });
 
 
 
    FB.getLoginStatus(function (response) {
 
        if (response.session) {
 
            // logged in and connected user, someone you know
            login();
 
        }
 
    });
 
};
 
(function () {
 
    var e = document.createElement('script');
 
    e.type = 'text/javascript';
               
                e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
 
    e.async = true;
 
    document.getElementById('fb-root').appendChild(e);
 
}()); 
 
function login() {}
 
function logout() {}
 
 
 
//stream publish method
 
function streamPublish() {
 
    FB.ui(
 
    {
 
        method: 'stream.publish',
 
        message: '',
 
        attachment: {
 
            name: 'Martin O\'Malley',
 
            caption: '{*actor*} is supporting Martin O\'Malley for Governor',
 
            description: 'Join the O\'Malley Brown campign to help move Maryland forward!',
 
            href: 'http://martinomalley.com',
 
            properties: {
 
                category: {
                    'text': 'politics',
                    'href': 'http://martinomalley.com'
                },
 
                ratings: '5 stars'
 
            },
 
            media: [{
 
                type: 'image',
 
                src: 'http://www.martinomalley.com/page/-/site3/mmf_image.jpg',
 
                href: 'http://martinomalley.com'
            }],
 
        },
 
        action_links: [
 
        {
            text: 'O\'Malley Brown - Moving Maryland Forward',
            href: 'http://martinomalley.com'
        }
 
        ],
 
        user_prompt_message: 'Share on Facebook'
 
    },
 
    function (response) {
 
 
 
    });
 
 
 
}
 
function showStream() {
 
    FB.api('/me', function (response) {
 
        //console.log(response.id);
        streamPublish(response.name, 'Join Martin O\'Malley\'s campign to help move Maryland forward', 'http://martinomalley.com', "Help spread the word about the campaign.");
 
    });
 
}
 
 
 
function share() {
 
    var share = {
 
        method: 'stream.share',
 
        u: 'http://martinomalley.com/'
 
    };
 
 
 
    FB.ui(share, function (response) {
        console.log(response);
    });
 
}
 
 
 
function graphStreamPublish() {
 
    var body = 'Join Martin\'s campaign to nove Maryland forward';
 
    FB.api('/me/feed', 'post', {
        message: body
    }, function (response) {
 
        if (!response || response.error) {
 
            alert('Error occured');
 
        } else {
 
            alert('Post ID: ' + response.id);
 
        }
 
    });
 
}
 
 
function setStatus() {
 
    status1 = document.getElementById('status').value;
 
    FB.api(
 
    {
 
        method: 'status.set',
 
        status: status1
 
    },
 
    function (response) {
 
        if (response == 0) {
 
            alert('Your facebook status not updated. Give Status Update Permission.');
 
        }
 
        else {
 
            alert('Your facebook status updated');
 
        }
 
    }
 
    );
 
}
