    (function ($) {
    $(document).ready(function() {
      var timeout			= Drupal.settings.megamenu.timeout;
      var sizewait		=  Drupal.settings.megamenu.sizewait;
      var hoverwait		=  Drupal.settings.megamenu.hoverwait;
      var hovertimer		= null;
      var sizetimer		= null;
      var closetimer		= null;
      var hoverParent		= null;
      var hoverBin		= null;
      var hoverSlots		= null;
      var megaSlots		= null;
      var megaParents		= null;
      var hideOffset		= -9000;
      var showOffset = 20;
      var megaParents = $('.megamenu-menu').find('.megamenu-parent');
      var megaParentTitles = $('.megamenu-menu').find('.megamenu-parent-title');
      var megaBins = $('.megamenu-menu').find('.megamenu-bin');
      var megaDiv = $('.megamenu-parent').children('.item-list');
      megaDiv.addClass ('megamenu-divback');
      var megaDiv = $('.megamenu-parent').find('.megamenu-divback');
      megaDiv.css ('display','none');
      
      var oldParentIdx = -1;
      var hoverParentIdx = -2;

      var activeParent	 		= megaParents.index($(megaParents).has('.active'));
      if(activeParent != -1)
      {
        megaParents.eq(activeParent).addClass('active');
      }
      
      function megamenu_open(){
        megamenu_canceltimer();

        if ($(this).hasClass('megamenu-parent-title')) {
          hoverParentIdx = megaParentTitles.index($(this));
        }
        else if ($(this).hasClass('megamenu-bin')) {
          hoverParentIdx = megaParents.index($(this).parents('.megamenu-parent'));
        }
        
        hoverParent = megaParents.eq(hoverParentIdx);

        if (hoverParentIdx != oldParentIdx) {
          megamenu_close();
          megamenu_hovertimer();
        } else {
          megamenu_display();
        }
      }

      function megamenu_display() {
        if (hoverParent) {
          // If the display doesn't have hover yet - trigger event
          if (!hoverParent.hasClass('hovering')) {
            hoverParent.trigger('megamenu_open');
          }
          hoverParent.addClass('hovering');
          hoverBin = hoverParent.find('.megamenu-bin');
          /* display position */

          hoverdiv = hoverParent.find('.item-list');
          hoverdiv.css('display', 'block'); 
        /* display position end */
        }
      }

      function megamenu_close(){
        if (hoverParent) {
          oldParentIdx = $('.megamenu-parent').index(hoverParent);
        }
        for ( var i=0 ; i < megaParents.length ; i++ ) {
          megaParents.trigger('megamenu_close');
          megaParents.eq(i).removeClass('hovering');
          megaParents.eq(i).find('.item-list').css('display', 'none');
        }


      }

      function megamenu_closeAll(){
        if(hoverBin) megaDiv.css ('display','none');
        for ( var i=0 ; i < megaParents.length ; i++ ) {
          megaParents.trigger('megamenu_close');
          megaParents.eq(i).removeClass('hovering');
        }
        oldParentIdx = -1;
      }

      function megamenu_stopPropagation(event){
        event.stopPropagation();
      }

      function megamenu_timer(){
        megamenu_canceltimer();
        megamenu_cancelhovertimer();
        closetimer = window.setTimeout(megamenu_closeAll, timeout);
      }

      function megamenu_canceltimer(){
        if (closetimer) {
          window.clearTimeout(closetimer);
          closetimer = null;
        }
      }

      function megamenu_hovertimer(){
        megamenu_cancelhovertimer();
        hovertimer = window.setTimeout(megamenu_display, hoverwait);
      }

      function megamenu_cancelhovertimer(){
        if (hovertimer) {
          window.clearTimeout(hovertimer);
          hovertimer = null;
        }
      }



      // Open Mega Menu Function - bound
      function megamenu_open_progress() {
        if ($(this).find('ul.megamenu-bin').get(0)) {
          $(this).find('h2').addClass('megamenu-active');
        }
      }
      function megamenu_close_progress() {
        $(this).find('h2').removeClass('megamenu-active');

      }

      $('.megamenu-parent').bind('megamenu_open', megamenu_open_progress);
      $('.megamenu-parent').bind('megamenu_close', megamenu_close_progress);

      $('.megamenu-parent-title').bind('mouseover', megamenu_open);
      $('.megamenu-parent-title').bind('mouseout', megamenu_timer);

      $('.megamenu-bin').bind('mouseover', megamenu_open);
      $('.megamenu-bin').bind('mouseout', megamenu_timer);

      $("body").bind('click', megamenu_closeAll);
      $(".megamenu-menu").bind('click', megamenu_stopPropagation);

      /*$(window).bind('resize', megamenu_sizer);*/
      /*megamenu_sizetimer();*/
    });
    })(jQuery);;
(function ($) {

$(document).ready(function() {

  // Accepts a string; returns the string with regex metacharacters escaped. The returned string
  // can safely be used at any point within a regex to match the provided literal string. Escaped
  // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded
  // in this function as it's used to separate the domains names.
  RegExp.escapeDomains = function(text) {
    return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : '';
  }

  // Attach onclick event to document only and catch clicks on all elements.
  $(document.body).click(function(event) {
    // Catch the closest surrounding link of a clicked element.
    $(event.target).closest("a,area").each(function() {

      var ga = Drupal.settings.googleanalytics;
      // Expression to check for absolute internal links.
      var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
      // Expression to check for special links like gotwo.module /go/* links.
      var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
      // Expression to check for download links.
      var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
      // Expression to check for the sites cross domains.
      var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i");

      // Is the clicked URL internal?
      if (isInternal.test(this.href)) {
        // Is download tracking activated and the file extension configured for download tracking?
        if (ga.trackDownload && isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
        else if (isInternalSpecial.test(this.href)) {
          // Keep the internal URL for Google Analytics website overlay intact.
          _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
        }
      }
      else {
        if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
          // Mailto link clicked.
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }
        else if (ga.trackOutbound && this.href) {
          if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
            // Top-level cross domain clicked. document.location is handled by _link internally.
            _gaq.push(["_link", this.href]);
          }
          else if (ga.trackOutboundAsPageview) {
            // Track all external links as page views after URL cleanup.
            // Currently required, if click should be tracked as goal.
            _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
          }
          else {
            // External link clicked.
            _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          }
        }
      }
    });
  });
});

})(jQuery);
;

