﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="XMLDom.js" />

var ns = "local.gigya.api";
if(!Type.isNamespace(ns))
{
    Type.registerNamespace(ns);
}

local.gigya.api.Configuration = 
{
    APIKey: "2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N"
    //"2_m3uHI-MsDQfGk3FsB29krxTVOIX2n7zkalvmzsH_NxdifGE9P_Wg7eqUy462xdWr"
}

/// <reference name="MicrosoftAjax.js"/>

Sys.Application.add_load(function()
{
    var conf=
    {
        siteName: local.gigya.api.Configuration.siteName,
        APIKey: local.gigya.api.Configuration.APIKey,
        enabledProviders: '*',
        language: 'Auto'
    }
    
    ///Login Event Handler
    gigya.services.socialize.addEventHandlers(conf,
    {
        onLogin: function(res)
        {
            if(pageFlag != 'Auth')
            {
                  local.gigya.socialize.ComponentApi.loginCallback(res);
            }
            else
            {
                Auth.Connect(res);
            }
        }

    });

});

/// <reference path="ComponentApi.js" />


/* 
-- Login Page UI 
Here is all the binding of the UI to the LoginAPI instance.
*/
var Auth = {
    conf:
        {
            siteName: local.gigya.api.Configuration.siteName,
            APIKey: local.gigya.api.Configuration.APIKey,
            enabledProviders: "facebook,myspace,twitter,yahoo,google,aol",
            language: 'Auto'
        }


    , loginParams:
     {
        UIConfig: '<config><body><controls><snbuttons buttonsize=\"40\"></snbuttons></controls><background background-color=\"#FFFFFF\" frame-thickness=\"0\"></background></body></config>',
        containerID: "componentDiv",
        width: 290,
        height: 100,
        hideGigyaLink: 'true',
        showTermsLink: 'false',
        useFacebookConnect: true
     }

      , Connect: function(e)
      {
          var user = e.user;
          if (!user)
              return;
          var userName = "";
          
          if (user.nickname.length > 0)
              userName = " "+user.nickname;
          else if (user.firstName.length > 0 || user.lastName.length > 0)
              userName = " "+user.firstName + " " + user.lastName;

          if ($("AUMessage"))
              $("AUMessage").innerHTML = "Hello <b>" + userName + "</b> you are now logged in"+"<center><span class='auMessage_network'>(network ID: " + user.identities[user.loginProvider].providerUID + ")</span></center>";
      }
}

var AuthPageAPI_Load = function()
{
    if (arguments[0] != undefined)
    {
        AuthPageAPI_LoadWithParams(arguments[0]);
        return;
    }
    ///Because the event handlers are global i register once at the GsAPI_globalLoad.js.
    //    gigya.services.socialize.addEventHandlers(Auth.conf,
    //    {
    //        onLogin: local.gigya.socialize.ComponentApi.LoginCallback
    //    });
    pageFlag = 'Auth';
    gigya.services.socialize.logout(Auth.conf, {

        callback: function(res)
        {
            gigya.services.socialize.showLoginUI(Auth.conf, Auth.loginParams);
        }
    });


}
var AuthPageAPI_LoadWithParams = function(loginParams)
{
    pageFlag = 'Auth';
    gigya.services.socialize.logout(Auth.conf, {

        callback: function(res)
        {
            gigya.services.socialize.showLoginUI(Auth.conf, loginParams);
        }
    });


}

/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Gigya.Site.Public.Scripts");

Gigya.Site.Public.Scripts.Socialize = function(element)
{
    Gigya.Site.Public.Scripts.Socialize.initializeBase(this, [element]);
}

Gigya.Site.Public.Scripts.Socialize.prototype = {
    initialize: function()
    {
        Gigya.Site.Public.Scripts.Socialize.callBaseMethod(this, 'initialize');

        // Add custom initialization here
    },
    dispose: function()
    {
        //Add custom dispose actions here
        Gigya.Site.Public.Scripts.Socialize.callBaseMethod(this, 'dispose');
    }
}
Gigya.Site.Public.Scripts.Socialize.ShowGSAuth = function(divToShow)
{
    if (Gigya.Site.Public.Scripts.Socialize.ShowGSExample(divToShow,null,null))
    {
        AuthPageAPI_Load();
    }

}
Gigya.Site.Public.Scripts.Socialize.ShowGSExample = function(divToShow,iframeID, iframeUrl)
{
    var exampleScreen = local.gigya.controls.LightBox.getByKey('ExampleScreen');
    if (exampleScreen != null)
    {
        exampleScreen.display();
        $(divToShow).className = "ShowContent";
        $(divToShow).setStyle({ visibility: 'visible' });
        if(iframeID != null && iframeUrl != null)
        {
            $(iframeID).src = iframeUrl;
        }
        return true;
    }
    return false;
}
Gigya.Site.Public.Scripts.Socialize.Close = function()
{
    var exampleScreen = local.gigya.controls.LightBox.getByKey('ExampleScreen');
    if (exampleScreen != null)
    {
        exampleScreen.hide();
    }
}
Gigya.Site.Public.Scripts.Socialize.registerClass('Gigya.Site.Public.Scripts.Socialize', Sys.UI.Behavior);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();