

window.fbAsyncInit = function () {
	FB.init({ appId: '160359930687570', status: true, cookie: true, oauth: true,
        xfbml: true
    });



};
function fblogin() {
    $('#fbloginlink').hide();
    FB.login(function (response) {
    	if (response.authResponse) {
            FB.api('/me', function (response) {
                if (response.id) {
                    $.cookie("fullname", response.name, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("firstname", response.first_name, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("facebookid", response.id, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("lastname", response.last_name, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("fbemail", response.email, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    window.location = "https://www.barry.edu/mybarry/credentials.aspx?fbid=" + response.id;
                }
                else {
                    fblogin2();

                }
            });
        } else {
            window.location.reload();
        }
    });
}
function fblogin2() {
    FB.login(function (response) {
    	if (response.authResponse) {
            FB.api('/me', function (response) {
                if (response.id) {
                    $.cookie("fullname", response.name, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("firstname", response.first_name, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("facebookid", response.id, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("lastname", response.last_name, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    $.cookie("fbemail", response.email, { expires: 1, path: '/', domain: 'barry.edu', secure: true });
                    window.location = "https://www.barry.edu/mybarry/credentials.aspx?fbid=" + response.id;
                }
                else {
                    //                    window.location = "http://www.facebook.com/connect/uiserver.php?app_id=" + encodeURIComponent("160359930687570") + "&next=" + encodeURIComponent("http://apps.facebook.com/barryuniversity/") + "&display=page&fbconnect=1&method=permissions.request";
                }
            });
        } else {
            window.location = 'http://www.barry.edu/mybarry';
        }
    });
}
(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);
} ());
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
                      

