$(function(){
    /**
    * the script should turn the second menu fixed when it reaches the top of the page
    * working on Gecko and Webkit browsers
    * Opera and MSIE don't defines window.scrollY, so we need to find an alternative for then
    */
    $(window).scroll(function () {
        //offset of div#center02 minus the body top margin
        var offsetCenter = $('.popup').offset().top - parseInt( $('body').css('marginTop') );
        var scrollY = getScrollY();
        if (scrollY >= offsetCenter) {
            $('#menu01 , #menu02, #menu03').addClass('menuFixo');
            //$('#menu01 , #menu02, #menu03').delay(50).css('top', scrollY - offsetCenter);
          $('#menu01 , #menu02, #menu03').delay(0).stop().animate({top: scrollY - offsetCenter},600);
        } else {
            $('#menu01 , #menu02, #menu03').removeClass('menuFixo');
          $('#menu01 , #menu02, #menu03').delay(0).stop().animate({top: 0},600);          
        }
    });
});

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY ;
}
