﻿<!--
//
//  Rotuines to support scroll down/up/left/right scroll dropdowns
//  The routines generally rely on the timer functions provided in
//  timers.js.
//
//  DoVerticalSlide - Uses opacity and height css properties to fade in
//                    and roll down a div.  The timing to the fade in
//                    and roll down is set by OpenVerSlide using the 
//                    timer constructor in timer.js.
//
//  OpenVertSlide - Uses a timer.js timer to control the timing of the
//                  fade in and roll down of DoVertSlide
//
//  CloseVertSlide - Same as OpenVertSlide but rolls up instead of down.
//
//  PoofInSlide - Uses opacity to simulate css display:none.  a dive with
//                a value of display: none will return a height of 0px.  This
//                routine is intended to get sround this through opacity.
//
//  PoofOutSlide - Same as PoofInSlide by simulates display: block.
//            
//
function DoVertSlide(timer, DisplayMenu)
{
   var direction = DisplayMenu[1].toLowerCase();    // Retrieve direction
   var IdName = DisplayMenu[0];                     // Retrieve item name to work  with

   var HandleID;                                    // Handle for IdName
   var currentHeight;                               // Current height of IdName
   var newHeight;                                   // The height to set IdName to
   var PercentComplete                              // How close to completion are we?
   var heightPadding;                               // Sum of top/bottom padding in idName
   var borderPadding;                               // Sum of top/bottom border width
   var showPercentage;                              // Percentage of fullHeight to show
      
   var IsFirstSlice = (timer.SlicesCompleted == 0); // First time through?
   var IsLastSlice = ((timer.SlicesCompleted + 1) == timer.SlicesPerInterval);  // Last time through?
   var IsUp = (direction == "up");                  // Going Up?
   var IsDown = (direction == "down");              // Going Down?
   var IsLeft = (direction == "left");              // Going Left ?
   var IsRight = (direction == "right");            // Going Right ?
   var IsHorizonal = (IsLeft || IsRight);           // Rolling horizontally?
   var IsVertical = (IsUp || IsDown);               // rolling Vertically?

   HandleID = document.getElementById(IdName);      // Retrieve the item
   
   if (timer.fullHeight)
      HandleID.style.height = timer.fullHeight;
   
   HandleID.style.display = "block";                // Find the item
   if (document.all)
   {
      //  Get padding and border sizes for IE
      heightPadding = parseInt(HandleID.currentStyle["paddingTop"]) +
         parseInt(HandleID.currentStyle["paddingBottom"]);
      borderPadding = parseInt(HandleID.currentStyle["borderLeftWidth"]) +
         parseInt(HandleID.currentStyle["borderRightWidth"]);
   }
   else
   {
      // Get padding and border sizes in Mozilla
      heightPadding = parseInt(document.defaultView.getComputedStyle(HandleID, null).paddingTop);
      heightPadding += parseInt(document.defaultView.getComputedStyle(HandleID, null).paddingBottom);
      borderPadding = parseInt(document.defaultView.getComputedStyle(HandleID, null).borderLeftWidth);
      borderPadding += parseInt(document.defaultView.getComputedStyle(HandleID, null).borderRightWidth);
   }

   // Curent height is the fulle offheight height less the padding and border
   currentHeight = HandleID.offsetHeight - heightPadding - borderPadding;
   
   // The first time through we need to set starting and ending points:
   //   - we set fullHeight so we remember the target
   //   - Force Current height to 0 for 'down' rolls
   //
   // We create fullHeight as a timer property so that we remember it each time we as called
   //
   if (IsFirstSlice)
   {
      timer.fullHeight = currentHeight;
      dropdownRunning = true;

      if (IsDown)
         currentHeight = 0;
   }

   //  On the last time through avoid rounding erros by forcing 100% done
   //  Otherwise, use timer info to calculate completion percent
   if (IsLastSlice)
      PercentComplete = 1;
   else
      PercentComplete = (timer.SlicesCompleted + 1)/timer.SlicesPerInterval;

   // For 'down' or 'right' we need to show PercentComplet of fullHeight
   // Otherwise, show the invers of PercentComplete
   if (IsDown || IsRight)
      showPercentage = PercentComplete;
   else
      showPercentage = 1 - PercentComplete;

   //  On last time through avoid rounding erros by forcing fullHeight
   //  Otherwise, calculate height as a percentage of fullHeight
   if (IsLastSlice)
      newHeight = timer.fullHeight;
   else
      newHeight = Math.ceil(timer.fullHeight * showPercentage);   

   // Do fade by setting opacity based on showPercentage
   HandleID.style.opacity = showPercentage;
   HandleID.style.filter = "alpha(opacity=" + showPercentage * 100 + ")";
   HandleID.style.MozOpacity = "'" + showPercentage + "'";  //NS6 syntax 

   // Adjust new display height
   HandleID.style.height = newHeight + "px";

   //  For the last time through:
   //    - If disappearing avoid faint display by setting display: none
   //    - Otherwise, remove the display property so as not to 
   //          interfer with any cascade in css.
   if (IsLastSlice)
   {
      if (IsUp || IsLeft)
         HandleID.style.display = "none";
      else
         HandleID.style.display = "";
   }   
}

function OpenVertSlide(IdName)
{
   var MenuControl = new Array(IdName, "down");     // Create an array to pass to the timer
                                                    //   to be used by our customer routines.   
   var testTimer = new IntervalTimer(MenuControl);  // Get a timer, pass in the arry
   testTimer.SliceMethod = DoVertSlide;             // Tell timer to call this each TimeSlice
   testTimer.TimeSlice = 25;                        // Smallest interval of time timer will take action
   testTimer.Interval = 250;                        // Timer will repeat TimeSlice for Interval milliseconds
   testTimer.StartTimer();                          // Start timer ticking !
}

function CloseVertSlide(IdName)
{
   var MenuControl = new Array(IdName, "up");       // Create an array to pass to the timer
                                                    //   to be used by our customer routines.   
   var testTimer = new IntervalTimer(MenuControl);  // Get a timer, pass in the arry
   testTimer.SliceMethod = DoHorzSlide;             // Tell timer to call this each TimeSlice
   testTimer.TimeSlice = 25;                        // Smallest interval of time timer will take action
   testTimer.Interval = 250;                        // Timer will repeat TimeSlice for Interval milliseconds
   testTimer.StartTimer();                          // Start timer ticking !
}

function PoofOutSlide (IdName)
{
   HandleID = document.getElementById(IdName);   // Retireve the item
   HandleID.style.opacity = 0;                   // Turn opacity completely off
   HandleID.style.filter = "alpha(opacity='0')";
   HandleID.style.MozOpacity = 0; //NS6 syntax 
}

function PoofInSlide (IdName)
{
   HandleID = document.getElementById(IdName);  // Retrieve the item 
   HandleID.style.opacity = 1;                  // Turn opacity to full.
   HandleID.style.filter = "alpha(opacity='100')";
   HandleID.style.MozOpacity = 1; //NS6 syntax 
}
-->
