$(function() {
  if ($(".history-main").height() < 551)
     $(".history-main").height(551);
  
  $("#menu .link").hover(
     function() {
        var sublinks = $(".sublinks", this);
        if (sublinks.get(0)) {
           var w = sublinks.outerWidth();
           var parent = sublinks.parent();
           var parent_offset = parent.offset().left;
           var parent_width = parent.width();
          
           var main_offset = $("#menu").offset().left;
           var main_width = $("#menu").width();
          
           if (w>parent_width) {
              max_w = main_width - (parent_offset - main_offset);
              if (max_w < w) {
                 sublinks.addClass('pos_right');
              } else {
                 sublinks.addClass('pos_left');
              }
           }
           sublinks.show();
        }
     },
     function() {
        $(".sublinks", this).hide();
     }
  );
     
  
  $("#menu .sublink").hover(
     function() {
        $(this).addClass('hovered');
     },
     function() {
        $(this).removeClass('hovered');
     }
  )
  
})

// getPageScroll() by quirksmode.com
function getPageScroll() {
   var xScroll, yScroll;
   if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
   } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
   } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
   }
   return new Array(xScroll,yScroll) 
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
   var windowHeight;
   if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
   } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
   } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
   }	
   return windowHeight
}
