

// Author: Kris Purdy
// Date: 17/04/2007
//======================================================================
var g_SupplierDirPos = 0;
var g_SupplierPages = null;
var g_SupplierHeight = 0;
var g_SupplierIncrement = 8;
if (navigator.appName.indexOf("Microsoft") >= 0) {
  g_SupplierIncrement = 0;
}

//======================================================================
function assignSourceDir () {
//pre: All <div class="SupplierSummary"> and <div class="SupplierHide">.
//pst: assigns the nextbutton and previous button event handlers.
  $("#supplierNextButton").click(
    function () {
      if (g_SupplierDirPos < g_SupplierPages) {
        g_SupplierDirPos = g_SupplierDirPos + 1;
        supplierDirButtons();
        var l_Top = (g_SupplierDirPos * (-g_SupplierHeight - g_SupplierIncrement));
        $(".supplierScroller").animate({marginTop: l_Top}, "slow",function(){
          $(".supplierScroller").css("margin-top",l_Top + "px");          
        });
      }
    }
  )
  $("#supplierPrevButton").click(
    function () {
      if (g_SupplierDirPos > 0) {
        g_SupplierDirPos = g_SupplierDirPos - 1;
        supplierDirButtons();
        var l_Top = (g_SupplierDirPos * (-g_SupplierHeight - g_SupplierIncrement));
        $(".supplierScroller").animate({marginTop: l_Top}, "slow",function(){
          $(".supplierScroller").css("margin-top",l_Top + "px");          
        });
      }
    }
  )
}

//======================================================================
function setWindowAndPageHeights() {
//pre: A HTML doc with the supplier directory HTML structure.
//pst: A HTML scroller set to the height of the tallest page.
  g_SupplierHeight = getHighestPageHeight() + 15;
  $(".supplierContainer").css("overflow","hidden");
  $(".supplierContainer").css("height",g_SupplierHeight + "px");
  $(".supplierPage").css("height",g_SupplierHeight + "px");
}

//======================================================================
function getHighestPageHeight() {
//pre: A HTML document with divs of class supplierPage.
//pst: The height of the tallest div of class supplierPage.
  var l_Pages = $(".supplierPage");
  var l_Height = 0;
  var l_TmpHeight = 0;
  for (var i = 0; i < l_Pages.size(); i++) {
    l_TmpHeight = l_Pages[i].clientHeight;
    if (!l_TmpHeight > 0) {
      l_TmpHeight = l_Pages[i].scrollHeight;
    }
    if (l_TmpHeight > l_Height) {
      l_Height = l_TmpHeight;
    }
  }
  return l_Height;
}

//======================================================================
function supplierDirButtons() {
//pre: A previous and next button for the supplier directory.
//pst: disables each button if the are no more pages in that direction.
  if (g_SupplierDirPos <= 0) {
    $("#supplierPrevButton").css("color", "#999999");
  } else {
    $("#supplierPrevButton").css("color", "#009ABC");    
  }
  if (g_SupplierDirPos >= g_SupplierPages) {
    $("#supplierNextButton").css("color", "#999999");
  } else {
    $("#supplierNextButton").css("color", "#009ABC");    
  }
}


