(function ($) {
  

})(jQuery);;
/**
 * jQuery Masonry v2.1.0
 * A dynamic layout plugin for jQuery
 * The flip-side of CSS Floats
 * http://masonry.desandro.com
 *
 * Licensed under the MIT license.
 * Copyright 2011 David DeSandro
 */
(function(a,b,c){var d=b.event,e;d.special.smartresize={setup:function(){b(this).bind("resize",d.special.smartresize.handler)},teardown:function(){b(this).unbind("resize",d.special.smartresize.handler)},handler:function(a,b){var c=this,d=arguments;a.type="smartresize",e&&clearTimeout(e),e=setTimeout(function(){jQuery.event.handle.apply(c,d)},b==="execAsap"?0:100)}},b.fn.smartresize=function(a){return a?this.bind("smartresize",a):this.trigger("smartresize",["execAsap"])},b.Mason=function(a,c){this.element=b(c),this._create(a),this._init()};var f=["position","height"];b.Mason.settings={isResizable:!0,isAnimated:!1,animationOptions:{queue:!1,duration:500},gutterWidth:0,isRTL:!1,isFitWidth:!1},b.Mason.prototype={_filterFindBricks:function(a){var b=this.options.itemSelector;return b?a.filter(b).add(a.find(b)):a},_getBricks:function(a){var b=this._filterFindBricks(a).css({position:"absolute"}).addClass("masonry-brick");return b},_create:function(c){this.options=b.extend(!0,{},b.Mason.settings,c),this.styleQueue=[],this.reloadItems();var d=this.element[0].style;this.originalStyle={};for(var e=0,g=f.length;e<g;e++){var h=f[e];this.originalStyle[h]=d[h]||""}this.element.css({position:"relative"}),this.horizontalDirection=this.options.isRTL?"right":"left",this.offset={x:parseInt(this.element.css("padding-"+this.horizontalDirection),10),y:parseInt(this.element.css("padding-top"),10)},this.isFluid=this.options.columnWidth&&typeof this.options.columnWidth=="function";var i=this;setTimeout(function(){i.element.addClass("masonry")},0),this.options.isResizable&&b(a).bind("smartresize.masonry",function(){i.resize()})},_init:function(a){this._getColumns(),this._reLayout(a)},option:function(a,c){b.isPlainObject(a)&&(this.options=b.extend(!0,this.options,a))},layout:function(a,b){for(var c=0,d=a.length;c<d;c++)this._placeBrick(a[c]);var e={};e.height=Math.max.apply(Math,this.colYs);if(this.options.isFitWidth){var f=0,c=this.cols;while(--c){if(this.colYs[c]!==0)break;f++}e.width=(this.cols-f)*this.columnWidth-this.options.gutterWidth}this.styleQueue.push({$el:this.element,style:e});var g=this.isLaidOut?this.options.isAnimated?"animate":"css":"css",h=this.options.animationOptions,i;for(c=0,d=this.styleQueue.length;c<d;c++)i=this.styleQueue[c],i.$el[g](i.style,h);this.styleQueue=[],b&&b.call(a),this.isLaidOut=!0},_getColumns:function(){var a=this.options.isFitWidth?this.element.parent():this.element,b=a.width();this.columnWidth=this.isFluid?this.options.columnWidth(b):this.options.columnWidth||this.$bricks.outerWidth(!0)||b,this.columnWidth+=this.options.gutterWidth,this.cols=Math.floor((b+this.options.gutterWidth)/this.columnWidth),this.cols=Math.max(this.cols,1)},_placeBrick:function(a){var c=b(a),d,e,f,g,h;d=Math.ceil(c.outerWidth(!0)/(this.columnWidth+this.options.gutterWidth)),d=Math.min(d,this.cols);if(d===1)f=this.colYs;else{e=this.cols+1-d,f=[];for(h=0;h<e;h++)g=this.colYs.slice(h,h+d),f[h]=Math.max.apply(Math,g)}var i=Math.min.apply(Math,f),j=0;for(var k=0,l=f.length;k<l;k++)if(f[k]===i){j=k;break}var m={top:i+this.offset.y};m[this.horizontalDirection]=this.columnWidth*j+this.offset.x,this.styleQueue.push({$el:c,style:m});var n=i+c.outerHeight(!0),o=this.cols+1-l;for(k=0;k<o;k++)this.colYs[j+k]=n},resize:function(){var a=this.cols;this._getColumns(),(this.isFluid||this.cols!==a)&&this._reLayout()},_reLayout:function(a){var b=this.cols;this.colYs=[];while(b--)this.colYs.push(0);this.layout(this.$bricks,a)},reloadItems:function(){this.$bricks=this._getBricks(this.element.children())},reload:function(a){this.reloadItems(),this._init(a)},appended:function(a,b,c){if(b){this._filterFindBricks(a).css({top:this.element.height()});var d=this;setTimeout(function(){d._appended(a,c)},1)}else this._appended(a,c)},_appended:function(a,b){var c=this._getBricks(a);this.$bricks=this.$bricks.add(c),this.layout(c,b)},remove:function(a){this.$bricks=this.$bricks.not(a),a.remove()},destroy:function(){this.$bricks.removeClass("masonry-brick").each(function(){this.style.position="",this.style.top="",this.style.left=""});var c=this.element[0].style;for(var d=0,e=f.length;d<e;d++){var g=f[d];c[g]=this.originalStyle[g]}this.element.unbind(".masonry").removeClass("masonry").removeData("masonry"),b(a).unbind(".masonry")}},b.fn.imagesLoaded=function(a){function h(){--e<=0&&this.src!==f&&(setTimeout(g),d.unbind("load error",h))}function g(){a.call(b,d)}var b=this,d=b.find("img").add(b.filter("img")),e=d.length,f="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";e||g(),d.bind("load error",h).each(function(){if(this.complete||this.complete===c){var a=this.src;this.src=f,this.src=a}});return b};var g=function(a){this.console&&console.error(a)};b.fn.masonry=function(a){if(typeof a=="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var d=b.data(this,"masonry");if(!d)g("cannot call methods on masonry prior to initialization; attempted to call method '"+a+"'");else{if(!b.isFunction(d[a])||a.charAt(0)==="_"){g("no such method '"+a+"' for masonry instance");return}d[a].apply(d,c)}})}else this.each(function(){var c=b.data(this,"masonry");c?(c.option(a||{}),c._init()):b.data(this,"masonry",new b.Mason(a,this))});return this}})(window,jQuery);
;
(function ($) {

/**
 * Defines function().
 * Creates <select /> from menu block.
 */
function menuToSelect(source, destination, mainmenu) {
  // Grab current selected main menu section.
  var section = $(mainmenu).find("> .active-trail").text();
  
  // Create wrapper for mobile menu.
  $("<div />", {
    "class" : "mobile-menu"
  }).appendTo(destination);    
  
  // Create menu-title
  $("<h2 />", {
    "class" : "menu-title block-title",
    "text"  : Drupal.t('Pages within') + " " + section
  }).appendTo(".mobile-menu", $(destination));
  
  // Create the dropdown base
  $("<select />", {
  }).appendTo(".mobile-menu", $(destination));
  
  // Create default option "Go to..."
  $("<option />", {
     "selected": "selected",
     "value"   : "",
     "text"    : Drupal.t('Select page')
  }).appendTo($("select", destination));
  
  // Populate dropdown with menu items
  $(source).each(function() {
  
    var el = $(this);
  
    var hasChildren = el.find("ul"),
        children    = el.find("li");

    if (hasChildren.length) {
    
      $("<optgroup />", {
        "label": el.find("> a").text()
      }).appendTo($("select", destination));
      
      $("<option />", {
        "value" : el.find("> a").attr("href"),
        "text"  : el.find("> a").text()
      }).appendTo("optgroup:last");

      children.find("a").each(function() {

        $("<option />", {
          "value" : $(this).attr("href"),
          "text": " - " + $(this).text()
        }).appendTo("optgroup:last");

      });

    } else {

      $("<option />", {
        "value"   : el.find("a").attr("href"),
        "text"    : el.find("a").text()
      }).appendTo($("select", destination));
    }
  });

  // To make dropdown actually work
  $("select", destination).change(function() {
    window.location = $(this).find("option:selected").val();
  });
}


/**
 * Defines function().
 * Create mobile navigation.
 */
function mobilizeNav() {
  minWidth = Math.min(screen.width,screen.height)

  // Only run on smaller screens.
  if (minWidth < 501) {
    if ($('#region-menu > nav').length || $('#search-block-form').length) { 
      // Create wrapper element for mobil nav.
      var navWrapper = $("<div />", {
        "id" : "mobile-menu-wrapper",
        "class" : "clearfix"
      });
    }
    
    // If main menu(s) are present add hide menu and add toggle.
    if ($('#region-menu > nav').length) {    
      // Hide menu
      $('#region-menu > nav').hide();
      
      // Create links to toggle menu and search visibility.
      var toggleMenu = $("<a />", {
        "id" : "toggle-mobil-menu",
        "href" : '#'
      });
      
      toggleMenu.append($("<span />", {
          "text" : Drupal.t('Show menu')
        }))
        .bind('click', function() {
          $('#search-block-form').hide();
          $('#region-menu > nav').slideToggle();
        })
        .appendTo(navWrapper);
    }
    
    // If search box present add search toogle.
    if ($('#search-block-form').length) {
      var toggleSearch = $("<a />", {
        "id" : "toggle-mobil-search",
        "href" : '#'
      });
      
      toggleSearch.append($("<span />", {
        "text" : Drupal.t('Search')
        }))
        .bind('click', function() {
          $('#region-menu > nav').slideUp();
          $('#search-block-form').slideToggle();
        })
        .appendTo(navWrapper);
    
      // Move search into wrapper.
      $("#search-block-form").appendTo(navWrapper);
    }

    // Toggle classes on active links.
    navWrapper.delegate('a', 'click', function() {
      el = $(this);
      if (el.attr('class') == 'active') {
        el.toggleClass('active')
      } else {
        navWrapper.find("a.active").toggleClass('active');
        el.toggleClass('active');
      }
    });
    
    // Add wrapper to DOM
    navWrapper.prependTo('#region-menu');
  }
}


/**
 * Defines function().
 * Add link to print page.
 */
function addPrintLink() {
  // Make sure the print link does not exists.
  if ($('.block-print-share .print-link').length == '') {
    $('.block-print-share .text-content').prepend('<a href="#' + Drupal.t('Print page') + '" class="print-link button"><span>' + Drupal.t('Print') + '</span></a>');

    $('.block-print-share .print-link').click(function() {
      window.print();
      
      // Make sure this works in Chrome.
      return false;
    });
  }
}

/**
 * Defines function().
 * Change styling if user has changed value.
 */
function dateFieldUpdate() {
  var activeFilter = false;
  var startValue = 'Vælg dato';

  // Test if user has changed value.
  if ($(this).data('startValue') != $(this).attr('value') && $(this).attr('value') != '') {
    activeFilter = true;
  } 
  
  else {
    activeFilter = false;
    if ($(this).attr('value') == '') {
      $(this).attr('value',startValue);
    }
  } 
  $(this).toggleClass('active-filter',activeFilter);
}

/**
 * Defines function().
 * Add behaviors to input element with date pickers.
 */
function datePickerMod() {
  // Get objects that need to be styled.
  var parentForm = $('[id^="views-exposed-form-education-calendar"]');
  
  if (parentForm.length) {
    var inputs = $("#edit-start-wrapper").find('.form-text');
    var startValue = 'Vælg dato';
    
    // Check if input no value is present and add helper text.
    inputs.each(function() {
      var valueOnLoad = $(this).attr('value');
      if (valueOnLoad == '') {
        $(this).attr('value',startValue)
               .data('startValue',$(this).attr('value'));
      } else if (valueOnLoad != startValue) {
        $(this).addClass('active-filter');
      }
    });
    
    parentForm
      // Change styling is user changes value.
      // Reset startValue if user deletes value.
      .delegate('.form-text.hasDatepicker', 'focusout', dateFieldUpdate)
      .delegate('.form-text.hasDatepicker', 'change', dateFieldUpdate)
      .submit(function() {
        inputs.each(function() {
          // Remove startValues on form submit.
          if ($(this).attr('value') == $(this).data('startValue')) {
            $(this).attr('value','');
          }
        })
      });
  };
};


/**
 * Run functions on document ready.
 */
$(document).ready(function() {
  addPrintLink();
  $(".field-name-field-content").fitVids();
  $('.menu-block-wrapper.menu-block-3').masonry({
    itemSelector : '.level-1',
    isResizable : true
  });
  menuToSelect(".menu-block-3 > .menu > li.active-trail", "#region-content", "#block-nice-menus-1 .level-1"); 
  mobilizeNav();
  datePickerMod();
});

})(jQuery);


;

