
 var name = "#leftMenu";
 var pageTurnName = "#pageTurn";
 var menuYloc = null;
 var pageFlipYloc = null;
 var lastScrollTop = 0;
 
 $(document).ready(function(){
  
  if (top.location != location) {top.location.href = document.location.href; }
  
  //jQuery.easing.def = "easeOutBounce";
  //$(name).animate({top:"17px"},{duration:1,queue:false});
  $(name).animate({top:"17px"},1,function(){$(name).show();});
  //$(name).css("top","17px");
  menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));
  //pageTurnYloc = parseInt($(pageTurnName).css("top").substring(0,$(pageTurnName).css("top").indexOf("px")));
  
  //alert($(window).width());
  //$(pageTurnName).css("left",$(window).width() - $(pageTurnName).width());

  if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
   $(pageTurnName).css("left","1100px");
  }   

  $(window).scroll(function () { 
   //$(name).html("<br><br>debug: "+lastScrollTop+" , "+$(document).scrollTop());
   offset = menuYloc+$(document).scrollTop();
   if (lastScrollTop < $(document).scrollTop()){
    if ($(name).height()>$(window).height()){
     offset=offset - ($(name).height()-$(window).height());
    }
   }
   if (offset<17){offset=17;}
   offset = offset+"px";
   $(name).animate({top:offset},{duration:1000,easing:'easeOutExpo',queue:false});

   //offset = pageTurnYloc+$(document).scrollTop();
   //offset = offset+"px";
   //$(pageTurnName).animate({top:offset},{duration:1000,easing:'easeOutExpo',queue:false});
   
  
   if (lastScrollTop > $(document).scrollTop()){lastScrollTop = $(document).scrollTop()+1;}
   if (lastScrollTop < $(document).scrollTop()){lastScrollTop = $(document).scrollTop()-1;}
  });
  
  $("#subListGoButton").click(function(){
   window.location = $("#subListSelect :selected").val();
  });
  $('div#backToTop').click(function(){     //was: a[href=#top]
   $('html, body').animate({scrollTop:0}, 'fast');
   return false;
  });
  $("#searchButton").click(function(){
   $("#searchForm").submit();
   return false;
  });
  
 }); 


