﻿google.setOnLoadCallback(function () {

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-5936717-1']);
    _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);
    })();

    $("#logout a").click(function () {
        $.ajax({
            url: '/Login/Logout',
            dataType: 'json',
            type: 'POST',
            success: function (response) {
                $("#userInfo").hide();
            }
        });
    });

    $("#popPosts").load("/Home/LoadPopular", null, null);
    $("#recComments").load("/Home/LoadRecentComments", null, null);
    $.ajax({
        url: '/Login/GetUserData',
        dataType: 'json',
        type: 'POST',
        success: function (response) {
            if (response.IsAuthd == "True") {
                $(".username").text(response.LastName + ", " + response.FirstName);
                $(".Email").text(response.UserName);
                $(".gravatar").attr("src", response.Gravatar);
            }
            else {
                $("#userInfo").hide();
            }
        }
    });
    $('#tweets').jTweetsAnywhere({
        username: 'matthewgoodrich',
        count: 5,
        showTweetFeed: {
            showTimestamp: {
                refreshInterval: 15
            },
            autorefresh: {
                mode: 'trigger-insert',
                interval: 30
            },
            paging: { mode: 'more' }
        },
        onDataRequestHandler: function (stats, options) {
            if (stats.dataRequestCount < 11) {
                return true;
            }
            else {
                stopAutorefresh(options);
            }
        }
    });
});
