﻿var TopAnimationsBusy = false;

function closeAnimations()
{
    $(".offScreen").addClass("inactive").removeClass("offScreen").removeClass("hidden").css("visibility", "");

    if (($("div.loginBox")) && (!$("div.loginBox").hasClass("inactive")))  //hide
    {
      $("div.loginBox").animate({height: "1px"}, 500, "swing", function(){ $(this).css("display", "").addClass("inactive"); });
    }

    if (($("div.searchBox")) && (!$("div.searchBox").hasClass("inactive")))  //hide
    {
      $("div.searchBox").animate({height: "1px"}, 500, "swing", function(){ $(this).css("display", "").addClass("inactive"); });
    }

    if (($("div.liveHelp")) && (!$("div.liveHelp").hasClass("inactive")))  //hide
    {
      $("div.liveHelp").animate({height: "1px"}, 500, "swing", function(){ $(this).css("display", "").addClass("inactive"); $("#divHelpMenu").addClass("inactive"); });
    }

    if ((window.frames.ifrFloatingDialog) && ($("#divFloatingDialog").parent().attr("class").toLowerCase().indexOf("draggable") < 0))  //Don't close if draggable...
    {
        closeDialog(window.frames.ifrFloatingDialog);
    }

    TopAnimationsBusy = false;
}

function wireUpTopAndBottomAnimationsOnPageLoad()
{            
/*    $("#mnuLogin a.loginLink").click(
      function()
      {
        if (($("div.loginBox")) && ($("div.loginBox").hasClass("inactive") && (!TopAnimationsBusy)))  //show
        {
          closeAnimations();

          TopAnimationsBusy = true;

          $("div.loginBox").animate({ height: "125px" }, 750, "swing", function() { $(this).removeClass("inactive"); TopAnimationsBusy = false; });

          if (setLoginEnter) setLoginEnter(true); // call a function on the page itself to do another thing
        }
        else  //hide
        {
            closeAnimations();
            if (setLoginEnter) setLoginEnter(false); // call a function on the page itself to do another thing
        }

        return(false);
      }
    );*/

    $("#btnSubmitForgotPassword").click(function() {  });  //Need to submit forgot password & close animation?

    $("#mnuSearch a").click(
      function()
      {
          if (($("div.searchBox")) && ($("div.searchBox").hasClass("inactive")) && (!TopAnimationsBusy))  //show
          {
              closeAnimations();

              TopAnimationsBusy = true;

              $("div.searchBox").animate({ height: "50px" }, 750, "swing", function() { $(this).removeClass("inactive"); TopAnimationsBusy = false; });

              if (setSearchEnter) setSearchEnter(true); // call a function on the page itself to do another thing
          }
          else  //hide
          {
              closeAnimations();

              if (setSearchEnter) setSearchEnter(false); // call a function on the page itself to do another thing
          }

          return (false);
      }
    );

    $("div.liveHelp").find("li a").click(function() { $("#mnuSupport a").click(); });

    $("#lnkLiveHelp").click(
        function()
        {
            if (ll_loggedIn)
            {
                //alert(llAppletStarted + ' logged in: ' + ll_loggedIn)
                if (($("div.liveHelpChat")) && ($("div.liveHelpChat").hasClass("inactive")))  //show
                {
                    //remote = new RemoteObject();
                    //details = remote.SendRequest('/WebServices/userserviceproxy.svc/json/userproxy/' +
                    //                             remote.GetCookie("user") + '/details',
                    //                             'GET', "", false).responseText;

                    //details = JSON.parse(details);

                    //if (details)
                    //{
                    //STLinksLogout();
                    //STLinksLogin(details.firstName + ' ' + details.lastName + ', ' + details.company, "", false);
                    //STLinksSetDisplayName(details.firstName + ' ' + details.lastName + ', ' + details.company, details.email);
                    //STLinksCreateIM(chatWith);
                    //There is a delay in Firefox, we need to set a timer here.
                    window.setTimeout("STLinksCreateIM(chatWith);", 500);

                    $("div.liveHelpChat").draggable().draggable('enable').fadeIn(1500, function() { $(this).removeClass("inactive").draggable('enable'); });

                    //details = null;
                    //}

                    //remote = null;
                }
            }
            else
            {
                window.setTimeout(function()
                {
                    //If Applet is not found
                    if (!llAppletFound)
                    {
                        //Do not show chat window if it is showing now.
                        if (($("div.liveHelpChat")) && ($("div.liveHelpChat").hasClass("inactive"))) 
                        {
                            document.getElementById('lnkSubmitLiveHelp').style.display = 'none';
                            $("div.liveHelpChat").draggable().draggable('enable').fadeIn(1500, function() { $(this).removeClass("inactive").draggable('enable'); });
                            //alert('Java Runtime Environment (JRE) must be installed and enabled in your browser before you can use the live chat.\nPlease try again!');
                        }
                    }
                }, 1500);
            }

            return false;

        }
    );

      $("#imgCloseChat").click(
      function()
      {
          if (($("div.liveHelpChat")) && (!$("div.liveHelpChat").hasClass("inactive")))  //hide
          {
              //STLinksLogout();
              lastOpenedImWin = null;
              lastOpenedImWinName = "";
              if (top)
              {
                  top.close();
              }

              $("div.liveHelpChat").fadeOut(750, function() { $(this).addClass("inactive"); });

              //document.getElementById('ifrLiveHelpChat').src = '/LiveHelpChat.aspx';
          }

          return (false);
      }
    );

    $("#mnuTermsOfUse a, #mnuPrivacyPolicy a, #mnuEmployment a, #mnuSiteMap a, #mnuContactUs a").click(
      function()
      {
        showFloatingDialog($(this).attr("href"), $(this).attr("itemid"), $(this).attr("title"));

        return(false);
      }
    );

    $("#btnRegister").click(
      function()
      {
        showFloatingDialog("RegistrationContent.aspx", "", "Register for My EFCO");

        return(false);
      }
    );
}