/**
  *
  *  Copyright 2005 Sabre Airline Solutions
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  *  file except in compliance with the License. You may obtain a copy of the License at
  *
  *         http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software distributed under the
  *  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  *  either express or implied. See the License for the specific language governing permissions
  *  and limitations under the License.
  **/
  


  var startX = 812,	startY = 359;
  var curY = startY;
  var destY = curY;
  var timerID, ton = 0;
  initMenu();
  window.onscroll = floatMenu;


  function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
      //Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      //DOM compliant
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
      scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
  }

  function initMenu()
  {
    var el = document.getElementById("cart");
    if (el) {
	    el.style.left = startX + 'px';
	    el.style.top = startY + 'px';
    }
  }   

  function startFloat()
  {
    var el = document.getElementById("cart");
  
    if(curY == destY)
    {
      clearInterval(timerID);
      ton = 0;
    }
    else if(curY < destY)
    {
      curY += Math.floor((destY-curY)/10);
      if (el) {
      	el.style.top = curY + 'px';
      }
      if(ton == 0)
      {
         timerID = setInterval("startFloat()", 2);
         ton = 1;
      }
    }
    else if(curY > destY)
    {
      curY -= Math.ceil((curY-destY)/10);
      if (el) {
      	el.style.top = curY + 'px';
      }
      
      if(ton == 0)
      {
         timerID = setInterval("startFloat()", 2);
         ton = 1;
      }
    }
  }

  function floatMenu()
  {
    clearInterval(timerID);
    res = getScrollXY();
    scY = res[1];
    ton = 0;
    destY = scY + startY;
    destY = Math.max(scY+15, startY)
    startFloat();
  }
