var FacebookConnect =
{
    "fbButtonClass" : '.fb_cbutton',
    "AppId" : null,

    "_init" : function(appId)
    {
        FacebookConnect.AppId = appId;

        // add FB script only if not loaded on current page
        if (! window.FB)
        {
            var js, id = 'facebook-jssdk', d = document;

            if (d.getElementById(id)) {return;}

            js = d.createElement('script');js.id = id;js.async = true;
            js.src = "//connect.facebook.net/en_US/all.js";
            d.getElementsByTagName('head')[0].appendChild(js);
        }

        FB.init(
        {
            "appId"      : appId,
            "status"     : true,
            "cookie"     : true,
            "xfbml"      : true,
            "oauth"      : true
        });

        FB.Event.subscribe('auth.authResponseChange', function(response)
        {
            // need to wait few seconds for fb login status to work in FireFox
            setTimeout('window.location.reload()', 3000);
        });

    },  // end of _init

    "showConnect" : function()
    {
        FB.getLoginStatus(function(response) {
            response.authResponse ? FacebookConnect.removeConnectButton() : FacebookConnect.assignConnectHandler();
        });

    },  // end of showConnect

    "showConnectPopUp" : function()
    {
        var exp = new Date();
        var currentTime = exp.setTime( exp.getTime() );

        if( NS_COOKIE.checkCookie( 'expireTime' ) )
        {
            var cookieExpireTime = NS_COOKIE.getCookie( 'expireTime' );
            cookieExpireTime = parseInt( cookieExpireTime, 10 );
            var timeToExpire = cookieExpireTime - currentTime;
        }

        if (! timeToExpire || typeof timeToExpire == NaN)
            timeToExpire = 30000;
        
        setTimeout(showLightBox, timeToExpire);
        //console.log('Time to expire = ' + timeToExpire);
    },  // end of showConnectPopUp

    "showMyPagesDropDown" : function()
    {
        //implement this later.

    },  // end of showMyPagesDropDown

    "assignConnectHandler" : function()
    {
        $(FacebookConnect.fbButtonClass).bind('click', function()
        {
            FB.login(function(response)
            {
                if (response.authResponse) { }
                else
                {
                    //console.log('User cancelled login or did not fully authorize.');
                }

            }, {"scope":"email,manage_pages"});
        });

    },  // end of assignConnectHandler

    "removeConnectButton" : function()
    {
        $(FacebookConnect.fbButtonClass).parent().remove();
        
    } // end of removeConnectButton

};
