Drupal.locale = { 'pluralFormula': function ($n) { return Number(($n!=1)); }, 'strings': {"An AJAX HTTP error occurred.":"Esines AJAX HTTP viga.","HTTP Result Code: !status":"HTTP kood: !status","An AJAX HTTP request terminated abnormally.":"AJAX HTTP p\u00e4ring l\u00f5ppes tavatult.","Debugging information follows.":"J\u00e4rgneb silumise teave.","Path: !uri":"Teekond: !uri","StatusText: !statusText":"Staatus: !statusText","ResponseText: !responseText":"VastusTekst: !responseText","ReadyState: !readyState":"ValmisOlek: !readyState","(active tab)":"(aktiivne sakk)","Hide":"Peida","Show":"N\u00e4ita","Configure":"Seadista","@title dialog":"@title dialoog","Show shortcuts":"N\u00e4ita kiirviiteid","Hide shortcuts":"Peida kiirviited","Re-order rows by numerical weight instead of dragging.":"Reasta read lohistamise asemel \u00fcmber kaalude numbriliste v\u00e4\u00e4rtuste j\u00e4rgi.","Show row weights":"N\u00e4ita ridade kaalusid","Hide row weights":"Peida ridade kaalud","Drag to re-order":"Lohista j\u00e4rjestuse muutmiseks","Changes made in this table will not be saved until the form is submitted.":"Sellesse tabelisse tehtud muudatusi ei salvestata enne vormi salvestamist.","Remove":"Eemalda","Add":"Lisa","Edit":"Muuda","Default":"Vaikimisi","Key":"V\u00f5ti","Enabled":"Lubatud","Not enabled":"Ei ole sisse l\u00fclitatud","Disabled":"Keelatud","none":"puudub","Done":"Valmis","Select all rows in this table":"Vali k\u00f5ik read selles tabelis","Deselect all rows in this table":"Eemalda k\u00f5ikide ridade m\u00e4rgistus selles tabelis","Not published":"Pole avaldatud","Please wait...":"Palun oota...","By @name on @date":"Autor: @name (@date)","By @name":"Autor: @name","Not in menu":"Pole men\u00fc\u00fcs","Alias: @alias":"Alias: @alias","No alias":"Alias puudub","New revision":"Uus redaktsioon","The changes to these blocks will not be saved until the \u003cem\u003eSave blocks\u003c\/em\u003e button is clicked.":"Plokkides tehtud muudatusi ei salvestata enne \u003cem\u003eSalvesta plokid\u003c\/em\u003e nupule vajutamist.","This permission is inherited from the authenticated user role.":"See \u00f5igus tuleneb sisseloginud kasutaja rollist.","No revision":"Redaktsioonid puuduvad","@number comments per page":"@number kommentaari iga lehe kohta","Requires a title":"Vajab pealkirja","Not restricted":"Piiranguteta","Not customizable":"Pole seadistatav","Restricted to certain pages":"Piiratud teatud lehtedega.","The block cannot be placed in this region.":"Plokki ei ole v\u00f5imalik sellesse regiooni paigutada.","Customize dashboard":"Kohada t\u00f6\u00f6lauda","Hide summary":"Peida kokkuv\u00f5te","Edit summary":"Muuda kokkuv\u00f5tet","Don't display post information":"\u00c4ra kuva infot sissekande kohta","Autocomplete popup":"Automaatl\u00f5petuse h\u00fcpikaken","Searching for matches...":"Vastavuste otsimine...","Submit":"Saada"} };;
Drupal.behaviors.mediaGalleryColorbox = {};

Drupal.behaviors.mediaGalleryColorbox.attach = function (context, settings) {
  var $ = jQuery, $galleries, $gallery, href, $links, $link, $dummyLinksPre, $dummyLinksPost, i, j;
  if ($.fn.colorbox) {
    // Add a colorbox group for each media gallery field on the page.
    $galleries = $('.field-name-media-gallery-media');
    for (i = 0; i < $galleries.length; i++) {
      $gallery = $($galleries[i]);
      $links = $('a.cbEnabled', $gallery);
      $dummyLinksPre = $gallery.parent().find('ul:has(a.colorbox-supplemental-link.pre)');
      $dummyLinksPost = $gallery.parent().find('ul:has(a.colorbox-supplemental-link.post)');
      $dummyLinksPost.appendTo($gallery);
      $links = $links.add('a', $dummyLinksPre).add('a', $dummyLinksPost);
      $links.attr('rel', 'colorbox-' + i);
      for (j = 0; j < $links.length; j++) {
        // Change the link href to point to the lightbox version of the media.
        $link = $($links[j]);
        href = $link.attr('href');
        $link.attr('href', href.replace(/\/detail\/([0-9]+)\/([0-9]+)/, '/lightbox/$1/$2'));
      }
      $links.not('.meta-wrapper').colorbox({
        slideshow: true,
        slideshowAuto: false,
        slideshowStart: 'Slideshow',
        slideshowStop: '[stop slideshow]',
        slideshowSpeed: 4000,
        current: "Item {current} of {total}",
        innerWidth: 'auto',
        // If 'title' evaluates to false, Colorbox will use the title from the
        // underlying <a> element, which we don't want. Using a space is the
        // officially approved workaround. See
        // http://groups.google.com/group/colorbox/msg/7671ae69708950bf
        title: ' ',
        transition: 'fade',
        preloading: true
      });
    }
    $('a.meta-wrapper').bind('click', Drupal.mediaGalleryColorbox.metaClick);
    // Subscribe to the media_youtube module's load event, so we can pause
    // the slideshow and play the video.
    $(window).bind('media_youtube_load', Drupal.mediaGalleryColorbox.handleMediaYoutubeLoad);
  }
};

Drupal.mediaGalleryColorbox = {};

/**
 * Handles the click event on the metadata.
 */
Drupal.mediaGalleryColorbox.metaClick = function (event) {
  event.preventDefault();
  jQuery(this).prev('.media-gallery-item').find('a.cbEnabled').click();
};

/**
 * Handles the media_youtube module's load event.
 *
 * If the colorbox slideshow is playing, and it gets to a video, the video
 * should play automatically, and the slideshow should pause until it's done.
 */
Drupal.mediaGalleryColorbox.handleMediaYoutubeLoad = function (event, videoSettings) {
  var $ = jQuery;
  var slideshowOn = $('#colorbox').hasClass('cboxSlideshow_on');
  // Set a width on a wrapper for the video so that the colorbox will size properly.
  $('#colorbox .media-gallery-item').width(videoSettings.width + 'px').height(videoSettings.height + 'px');
  if (slideshowOn) {
    videoSettings.options.autoplay = 1;
    $('#cboxSlideshow')
      // Turn off the slideshow while the video is playing.
      .click() // No, there is not a better way.
      .text('[' + Drupal.t('resume slideshow') + ']');
      // TODO: If YouTube makes its JavaScript API available for iframe videos,
      // set the slideshow to restart when the video is done playing.
  }
};
;
/*jslint bitwise: true, eqeqeq: true, immed: true, newcap: true, nomen: false,
 onevar: false, plusplus: false, regexp: true, undef: true, white: true, indent: 2
 browser: true */

/*global jQuery: true Drupal: true window: true ThemeBuilder: true */

(function ($) {
  /**
   * Stop the rotation in the Rotating Banner when the ThemeBuilder is open
   */
  Drupal.behaviors.RotatingBannerInThemeBuilder = {
    attach: function (context) {
      if ($('body').hasClass('themebuilder')) {
        $('.rb-slides').each(function () {
          if ($(this).cycle) {
            $(this).cycle('stop');
          }
        });
      }
    }
  };
  /**
   * Activate Superfish Pulldown menus
   */
  Drupal.behaviors.GardensFeaturesPulldownMenus = {
    attach: function (context, settings) {
      Drupal.behaviors.GardensFeaturesPulldownMenus.settings = {
        appearance: {
          gutter: 10,
          push: 2
        }
      };
      if (settings) {
        $.extend(Drupal.behaviors.GardensFeaturesPulldownMenus.settings, settings);
      }
      if ($().superfish) {
        $('.content > .menu', '#page .stack-navigation').once('pulldown', function () {
          $(this).superfish({
            hoverClass: 'menu-dropdown-hover',
            delay: 150,
            dropShadows: false,
            speed: 300,
            autoArrows: true,
            onBeforeShow: Drupal.behaviors.GardensFeaturesPulldownMenus.adjustPulldown
          });
        });
      }
    }
  };
  
  /**
   * This function is run to adjust the placement of a pulldown.
   *
   * @param {DomElement} this
   *   The pulldown (ul) that is currently being shown.
   */   
  Drupal.behaviors.GardensFeaturesPulldownMenus.adjustPulldown = function () {
    $(this).css({display: 'block', visibility: 'hidden'});
    Drupal.behaviors.GardensFeaturesPulldownMenus.adjustPulldownPlacement($(this));
    $(this).css({display: 'none', visibility: 'visible'});
  };
  
  /**
   * Progressively increases the width of the pulldown by 33% until
   * the height of each item is less than the line height 
   *
   * @param {DomElement} pulldown
   *   The pulldown (ul) to be positioned
   * @param {DomElement} item
   *   The anchor tag of an item in the list
   * @param {int} lineHeight
   *   The line height of the item's anchor tag. This is passed in 
   *   because it does not need to be calculated more than once
   * @param {int} safety
   *   A counter to prevent recursive errors. The width of the pulldown
   *   will be adjusted at most 5 times currently.
   */  
  Drupal.behaviors.GardensFeaturesPulldownMenus.adjustPulldownWidth = function (pulldown, item, lineHeight, safety) {
    var width = pulldown.width();
    var height = item.height();
    var wrapped = ((height - lineHeight) > 2) ? true : false; // Provide a little give with a 2 pixel fudge factor for IE7
    if (wrapped && (safety < 5)) {
      pulldown.animate({
          width: width * 1.2
        },
        {
          duration: 0,
          queue: true,
          complete: function () {
            safety += 1;
            Drupal.behaviors.GardensFeaturesPulldownMenus.adjustPulldownWidth(pulldown, item, lineHeight, safety);
          }
        }
      );
    }
  };
  
  /**
   * Moves a pulldown left or right, according to its alignment, after its
   * parent's width has been adjusted
   *
   * @param {DomElement} pulldown
   *   The pulldown (ul) to be positioned
   */
  Drupal.behaviors.GardensFeaturesPulldownMenus.adjustPulldownPlacement = function (element) {
    var pulldown = {};
    pulldown.el = element;

    // Wipe out any previous positioning
    pulldown.el.removeAttr('style');

    // Get the depth of the sub menu
    // 0 is first tier sub menu
    // 1 is second tier sub menu, etc
    var depth = pulldown.el.parentsUntil('.pulldown-processed').filter('.menu').length;
    pulldown.parent = {};
    pulldown.parent.el = element.prev('a');
    pulldown.parent.css = {
      lineHeight: Drupal.behaviors.GardensFeaturesPulldownMenus._stripPX(pulldown.parent.el.css('line-height')),
      padding: {
        top: Drupal.behaviors.GardensFeaturesPulldownMenus._stripPX(pulldown.parent.el.css('padding-top'))
      },
      margin: {
        top: Drupal.behaviors.GardensFeaturesPulldownMenus._stripPX(pulldown.parent.el.css('margin-top'))
      }
    };
    // Only consider pulldowns, not the main menu items
    // Basic placement without edge detection
    var root = {};
    root.el = pulldown.el.parents('.pulldown-processed li .menu');
    if (root.el && (root.el.length > 0)) {
      pulldown.el.css({
        left: root.el.width()
      });
    }
    // Get the viewport and scroll information
    var viewport = {};
    viewport.width = $(window).width(); // Width of the visible viewport
    viewport.height = $(window).height(); // Height of the visible viewport
    viewport.scroll = {};
    viewport.scroll.top = $(window).scrollTop();
    // Move the pulldown back to its origin if we moved it left because of edge correction previously
    pulldown.pos = pulldown.el.position();
    if (pulldown.pos) {
      if (pulldown.pos.left < 0) {
        pulldown.el.css({
          left: 0
        });
        pulldown.pos.left = 0;
      }
    }
    // Now check for edge collision
    pulldown.offset = pulldown.el.offset();
    if (pulldown.offset) {
      pulldown.width = pulldown.el.outerWidth(false);
      pulldown.height = pulldown.el.outerHeight(false);
      pulldown.edge = {};
      pulldown.edge.right = pulldown.offset.left + pulldown.width;
      pulldown.edge.bottom = pulldown.offset.top + pulldown.height;
      pulldown.hang = {};
      pulldown.hang.right = viewport.width - pulldown.edge.right;
      pulldown.hang.bottom = (viewport.height + viewport.scroll.top) - pulldown.edge.bottom  - Drupal.behaviors.GardensFeaturesPulldownMenus.settings.appearance.gutter;
      pulldown.hang.bottomModified = 1;
      
      // Move the pulldown left if it hangs off the edge of the screen
      if (pulldown.hang.right <= 0) {
        pulldown.el.css('left',  (pulldown.pos.left + pulldown.hang.right - Drupal.behaviors.GardensFeaturesPulldownMenus.settings.appearance.gutter));
        if (depth > 0) {
          var top = (((pulldown.parent.css.lineHeight) / 1.4545) + (pulldown.parent.css.padding.top) + (pulldown.parent.css.margin.top));
          pulldown.el.css('top', top);
          pulldown.hang.bottomModified = pulldown.hang.bottom - top;
        }
      }
      // Move the pulldown up if it hangs off the bottom
      if (pulldown.hang.bottom <= 0 || pulldown.hang.bottomModified <= 0) {
        pulldown.el.css('top', (pulldown.pos.top + pulldown.hang.bottom));
      }
    }
  };
  
  /**
   * Utility function to remove 'px' from calculated values.  The function assumes that
   * that unit 'value' is pixels.
   *
   * @param {String} value
   *   The String containing the CSS value that includes px.
   * @return {int}
   *   Value stripped of 'px' and casted as a number or NaN if 'px' is not found in the string.
   */  
  Drupal.behaviors.GardensFeaturesPulldownMenus._stripPX = function (value) {
    if (value) {
      var index = value.indexOf('px');
      if (index === -1) {
        return NaN;
      }
      else {
        return Number(value.substring(0, index));
      }
    }
    else {
      return NaN;
    }
  };
  
  /**
   * Gardens version of Drupal contextual links
   * Override the default behavior and style by moving the edit gear to the left
   * of the element and outside the content area.
   * 
   * Gardens also adds edge detection so that the links aren't displaying off screen
   */ 
   
  Drupal.gardensContextualLinks = Drupal.gardensContextualLinks || {};
  
  /**
   * UI interaction delay timeout IDs are stored in the delayTimeouts array
   */
  Drupal.gardensContextualLinks.delayTimeouts = [];
  
  
  Drupal.behaviors.gardensContextualLinks = {
    attach: function (context) {
      // Set up contextual links for logged in users, but not when the themebuilder is open
      if ($('body').hasClass('logged-in') && !$('body').hasClass('themebuilder')) {
        // Create the proxy links overlay
        // This will contain the contextual links and be placed over the 
        // active contextual links region
        var $proxy = $('<div class="contextual-links-region-proxy" style="display:none;"></div>')
          .prependTo('body')
          .bind('mouseleave.gardens_features', 
            {
              'functions': [ 
                { 'action': Drupal.behaviors.gardensContextualLinks.deactivateProxy, 'delay': 300 } 
              ]
            }, Drupal.behaviors.gardensContextualLinks.createDelay);
        var $boxTop = $('<div>').addClass('contextual-links-region-proxy-outline outline-top').insertAfter($proxy);
        var $boxRight = $('<div>').addClass('contextual-links-region-proxy-outline outline-right').insertAfter($boxTop);
        var $boxBottom = $('<div>').addClass('contextual-links-region-proxy-outline outline-bottom').insertAfter($boxRight);
        $('<div>').addClass('contextual-links-region-proxy-outline outline-left').insertAfter($boxBottom);
        
        // Process each instance of a contextual link set
        $('div.contextual-links-wrapper', context).once('gardens-contextual-links', function () {
          var $wrapper = $(this),
              $region = $wrapper.closest('div.contextual-links-region'),
              $trigger = $('<a class="contextual-links-trigger" href="#" />').text(Drupal.t('Configure'));
          $wrapper.prepend($trigger);
          Drupal.behaviors.gardensContextualLinks.establishBindings($region, $wrapper);
        });
      }
    },
    establishBindings: function ($region, $wrapper) {
      var $proxy = $('.contextual-links-region-proxy');

      // Listen for events
      $region.bind('mouseenter.gardens_features', 
        {
          'region': $region, 
          'wrapper': $wrapper, 
          'functions': [ 
            {'action': Drupal.behaviors.gardensContextualLinks.activateProxy, 'delay': 150 }
          ]
        }, Drupal.behaviors.gardensContextualLinks.createDelay);
      $region.bind('mouseleave.gardens_features', 
        {
          'region': $region, 
          'wrapper': $wrapper, 
          'functions': [ 
            {'action': Drupal.behaviors.gardensContextualLinks.deactivateProxy, 'delay': 350 }
          ]
        }, Drupal.behaviors.gardensContextualLinks.createDelay);
    },
    activateProxy: function (event) {
      // Get the contextual links proxy and empty it of any links already in it
      var $proxy = $('.contextual-links-region-proxy');
      $proxy.hide().empty();
      
      // Clone the current contextual links and add them to the proxy region
      var $contextLinks = event.data.wrapper.clone();
      $contextLinks.appendTo($proxy);
      
      // Get the trigger and the links to bind events to them.
      var $trigger = $('.contextual-links-trigger', $proxy),
          $links = $('.contextual-links', $proxy);
      
      // Get the offset of the original region and position the proxy over it
      var $region = event.data.region,
          offset = $region.offset(),
          regionWidth = $region.width(),
          regionHeight = $region.height();
      
      // Place the proxy element
      $proxy
        .css({
          'left' : offset.left,
          'top' : offset.top,
          'width' : $region.width(),
          'height' : 0
        });
      
      // Place the dotted outlines. The 'spacing' and 'adjust' add a little
      // space between the dotted lines and the content.
      var spacing = 3,
          adjust = 1;
      $('.contextual-links-region-proxy-outline.outline-top').css({
        'left': (offset.left - adjust),
        'height': '1px',
        'top': (offset.top - adjust),
        'width': (regionWidth + spacing)
      });
      $('.contextual-links-region-proxy-outline.outline-right').css({
        'left': (offset.left + regionWidth + adjust),
        'height': (regionHeight + spacing),
        'top': (offset.top - adjust),
        'width': '1px'
      });
      $('.contextual-links-region-proxy-outline.outline-bottom').css({
        'left': (offset.left - adjust),
        'height': '1px',
        'top': (offset.top + regionHeight + adjust),
        'width': (regionWidth + spacing)
      });
      $('.contextual-links-region-proxy-outline.outline-left').css({
        'left': (offset.left - adjust),
        'height': (regionHeight + spacing),
        'top': (offset.top - adjust),
        'width': '1px'
      });
        
      // Establish bindings
      // Close the proxy if a contextual action link is clicked
      $('a', $links).bind('click.gardens_features', 
        {}, 
        Drupal.behaviors.gardensContextualLinks.deactivateProxy);
      // Show the links when the gear is hovered
      $trigger.bind('mouseenter.gardens_features', 
        {
          'functions': [ 
            { 'action': Drupal.behaviors.gardensContextualLinks.showLinks, 'delay': 150 } 
          ]
        }, Drupal.behaviors.gardensContextualLinks.createDelay);
      // Hide the links when the user mouses out
      $links.bind('mouseleave.gardens_features', 
        {
          'functions': [ 
            { 'action': Drupal.behaviors.gardensContextualLinks.hideLinks, 'delay': 50 } 
          ]
        }, Drupal.behaviors.gardensContextualLinks.createDelay);
        
      // Show the proxy and dotted lines
      $proxy.nextAll('.contextual-links-region-proxy-outline').andSelf().show();
      
      // Check for collision of the gear icon with the viewport edge
      event.data.element = $trigger;
      Drupal.behaviors.gardensContextualLinks.queueEdgeCollisionCorrection(event);
    },
    deactivateProxy: function (event) {
      $('.contextual-links-region-proxy').nextAll('.contextual-links-region-proxy-outline').andSelf().hide();
    },
    showLinks: function (event) {
      var $links = $(event.currentTarget).next();
      event.data.element = $links;
      $links.slideDown(125);
      // Check for collision of the links with the viewport edge
      Drupal.behaviors.gardensContextualLinks.queueEdgeCollisionCorrection(event);
    },
    hideLinks: function (event) {
      $(event.currentTarget).slideUp(200);
    },
    createDelay: function (event) {
      // Clear the existing timeouts first
      Drupal.behaviors.gardensContextualLinks.destroyDelay();
      // Go through the functions passed in the event and call them with their
      // designated delay.
      for (var i = 0; i < event.data.functions.length; i++) {
        var delay = event.data.functions[i].delay || 500;
        var action = event.data.functions[i].action;
        // @todo This implementation suffers from improper handling of closures
        // when calling the setTimeout function. It works now because only
        // one function is ever called, even though the loop is present to
        // support more than one function being passed in on event.data.functions.
        // A more robust approach that deals with the function closure is needed.  
        Drupal.gardensContextualLinks.delayTimeouts.unshift(setTimeout(function () {
            action(event); 
            event = null;
          }, delay)
        );
      }
    },
    destroyDelay: function () {
      // Go through the timeout IDs and clear them
      while (Drupal.gardensContextualLinks.delayTimeouts.length > 0) {
        clearTimeout(Drupal.gardensContextualLinks.delayTimeouts.pop());
      }
    },
    queueEdgeCollisionCorrection: function (event) {
      // Queue the collision detection after any animations that may be 
      // associated with the links
      event.data.element.queue(function (next) {
        // If the object was just hidden, we don't need to act on it further. Just return out.
        if (event.data.element.is(':hidden')) {
          // Call the next animation in the fx queue and return
          next();
          return false;
        }
        // If the element is visible, attempt to correct any edge collision
        Drupal.behaviors.gardensContextualLinks.correctEdgeCollision(event);
        // Call the next animation in the fx queue
        next();
        return true;
      });
    },
    correctEdgeCollision: function (event) {
      // Check for RTL setting
      var isRTL = ($('html').attr('dir') === 'rtl'),
          isLinks = event.data.element.is('.contextual-links'),
          isTrigger = event.data.element.is('.contextual-links-trigger');
      // Remove the edge-collision class if it exists before we determine a collision
      if (isTrigger) {
        event.data.element.parent().removeClass('edge-collision');
      }
      if (isLinks) {
        event.data.element.removeClass('edge-collision');
      }
      // Get the dimensions of the element and the viewport
      var element = {
          offset: event.data.element.offset(),
          dimensions: {
            width: event.data.element.outerWidth(false)
          }
        },
        viewport = {
          dimensions: {
            width: $('html').width()
          }
        };
      // Determine if the element is rendered outside the viewport
      var isCollided = ((!isRTL && element.offset.left < 0) || (isRTL && ((element.offset.left + element.dimensions.width) > viewport.dimensions.width)));
      
      // If the left edge of the links is outside the viewport, move them inside the content; or,
      // If the right edge of the links is outside the viewport, move them inside the content
      if (isCollided && isLinks) {
        event.data.element.addClass('edge-collision');
      }
      // If the trigger has collided with the window edge, mark its parent as having collided
      if (isCollided && isTrigger) {
        event.data.element.parent().addClass('edge-collision');
      }
    }
  };
})(jQuery);
;

