﻿var count = 0;
var suppressLoading = false;
function Anthem_PreCallBack() {
    count++;
    if (count == 1) {
        
        setTimeout("CallBackStarted()", 50);

        // Stop the Magic Zoom functionality if it is on the page
        //if (typeof StopMagicZoom != "undefined") { StopMagicZoom(); }
        // Stop the Magic Zoom Plus functionality if it is on the page
        if (typeof StopMagicZoomPlus != "undefined") { StopMagicZoomPlus(); }
    } else {
        // If this is a simultaeous request, give the previous one 1
        // second to finish so we free up resources for this one.
        setTimeout("CallBackStarted()", 1000);
        if (typeof StopMagicZoomPlus != "undefined") { StopMagicZoomPlus(); }
        setTimeout("CallBackFinished()", 1000);
    }
}
function Anthem_PostCallBack() { CallBackFinished(); }
function Anthem_CallBackCancelled() { CallBackFinished(); }

function CallBackStarted() {
    if (count > 0) {
        if (!suppressLoading) {

            // check to see if Jquery is loaded
            if (typeof (jQuery) != 'undefined') {
                // load our loading images
                var $loading = jQuery('.loading');
                if ($loading.length > 0) {
                    //alert('showing:' + $loading.length);
                    $loading.removeClass('hide');
                    $loading.addClass('loadingvisible');
                }
            }
            var item = document.getElementById('wait');
            if (item) {
                if ((!window.XMLHttpRequest) && (document.documentElement)) {
                    item.style.position = 'absolute';
                    //code to make ie6 behave
                    if (document.documentElement.scrollTop) {
                        item.style.top = document.documentElement.scrollTop + 15;
                    }
                    else { item.style.top = 15; }
                    item.style.right = 15;
                }
                item.style.display = 'block';
            }
        }
  }
}
 
function CallBackFinished(){
  count--;
  if (count == 0) {
      //if (!suppressLoading) {
          var item = document.getElementById('wait');
          if (item != null) {
              item.style.display = 'none';
          }

          // check to see if Jquery is loaded
          if (typeof (jQuery) != 'undefined') {
              // load our loading images
              var $loading = jQuery('.loading');
              if ($loading.length > 0) {
                  //alert('hiding:' + $loading.length);
                  $loading.addClass('hide');
                  $loading.removeClass('loadingvisible');
              }
          }
      //}

    //Refresh the Magic Zoom tool if it is on this page
          //if (typeof RefreshMagicZoom != "undefined") { RefreshMagicZoom(); }
    //Refresh the Magic Zoom Plus tool if it is on the page
          if (typeof RefreshMagicZoomPlus != "undefined") { RefreshMagicZoomPlus(); }

    // Close up the volume discounts
    if (typeof (initializeDiscounts) == "function") { initializeDiscounts(); }

    if (typeof (callBackComplete) == "function") { callBackComplete(); }
  }
}

function StopMagicZoom() {
    if (typeof (MagicZoom_stopZooms) == "function") { MagicZoom_stopZooms(); }
}

function RefreshMagicZoom() {
    if (typeof (MagicZoom_findZooms) == "function") { setTimeout('MagicZoom_findZooms();MagicZoom.refresh();', 100); }
}

/* These functions are from the magic zoom plus support website here: http://forum.magictoolbox.com/index.php/topic,955.0.html */
function StopMagicZoomPlus() {
    if (typeof (MagicZoom_stopZooms) == "function") { MagicZoom_stopZooms(); }
}

function RefreshMagicZoomPlus() {
    if (typeof (MagicZoom_findZooms) == "function") { setTimeout('MagicZoom_findZooms();MagicThumb.refresh();', 100); }
}

