jQuery.noConflict();
jQuery(document).ready(function($){
    $("ul.sf-menu").supersubs({
        minWidth:     12,                                // minimum width of sub-menus in em units
        maxWidth:     27,                                // maximum width of sub-menus in em units
        extraWidth:   1                                  // extra width can ensure lines don't sometimes turn over
                                                         // due to slight rounding differences and font-family
    }).superfish({ 
        delay:        400,                               // delay on mouseout
        animation:    {opacity:'show',height:'show'},    // fade-in and slide-down animation
        speed:        'fast',                            // faster animation speed
        autoArrows:   false,                             // disable generation of arrow mark-up
        dropShadows:  false,                             // disable drop shadows
        onBeforeShow: function() {
         this.css('display', 'block');
         var menuPosition = this.offset();
         // The offset of the header tells us how much space we have on the side of the site
         var headerPosition = $('#header').offset();
         var edgeCheck = menuPosition.left + headerPosition.left + this.width();
         this.css('display','none');

         if ( edgeCheck > $(window).width() + headerPosition.left ) {
          var newPosition = this.width();
          if (this.parent().parent().attr('id') == 'menu-primary-navigation') {
           newPosition -= this.parent().width();
          } else {
           newPosition -= 1;
          }
          this.css('left', newPosition * -1 + 'px');
         }
        }
    }); 
});

