﻿FB.init({
    appId: '165521300190529', cookie: true,
    status: true, xfbml: true
});
$(function () {
    $('#aLogOut').click(function () {
        $.cookie('userid', null, { expires: -7, domain: '.findahood.com', path: '/' });
        $.cookie('username', null, { expires: -7, domain: '.findahood.com', path: '/' });
        FB.logout(function (response) {
            ShowLoggedOut();
        });
        return false;
    });
    FB.getLoginStatus(function (response) {
        if (response.status == 'connected') {
            ShowLoggedIn();
        }
    });
});

function ShowLoggedIn() {
    FB.api('/me', function (user) {
        if (user) {
            $('#divLoggedOut').hide();
            $.cookie('userid', decodeURIComponent(user.id), { domain: '.findahood.com', path: '/' });
            $.cookie('username', decodeURIComponent(user.name), { domain: '.findahood.com', path: '/' });
            $('#spnUsername').html(user.name);
            $('#imgAvatar').attr('src', 'http://graph.facebook.com/' + user.id + '/picture');
            $('#divLoggedIn').show();
        }
    });
}

function ShowLoggedOut() {
    $('#divLoggedOut').show();
    $('#divLoggedIn').hide();
}

//analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-15428301-2']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//!analytics
