/**
 * This is part of a patch to address a jQueryUI bug.  The bug is responsible
 * for the inability to scroll a page when a modal dialog is active. If the content
 * of the dialog extends beyond the bottom of the viewport, the user is only able
 * to scroll with a mousewheel or up/down keyboard keys.
 *
 * @see http://bugs.jqueryui.com/ticket/4671
 * @see https://bugs.webkit.org/show_bug.cgi?id=19033
 * @see /views_ui.module
 * @see /js/jquery.ui.dialog.min.js
 *
 * This javascript patch overwrites the $.ui.dialog.overlay.events object to remove
 * the mousedown, mouseup and click events from the list of events that are bound
 * in $.ui.dialog.overlay.create
 *
 * The original code for this object:
 * $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
 *  function(event) { return event + '.dialog-overlay'; }).join(' '),
 *
 */

(function ($, undefined) {
  if ($.ui && $.ui.dialog) {
    $.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','),
                                 function(event) { return event + '.dialog-overlay'; }).join(' ');
  }
}(jQuery));
;


(function() {

  var str;
  var delay;
  function doResize() {

    jQuery(".left-3col").height("auto");
    jQuery(".mid-3col").height("auto");
    jQuery(".right-col").height("auto");
    jQuery(".extra_left").height("auto");
    jQuery(".extra_right").height("auto");
    jQuery(".mid_left").height("auto");
    jQuery(".mid_right").height("auto");
    jQuery(".right-col-left").height("auto");
    jQuery(".right-col-right").height("auto");

    if (jQuery(window).width() > 1425) {
      str = jQuery("#extra-container").html();
      if (str) {
        jQuery("#extra-content").html(str);
        jQuery("#extra-container").html("");
      }
      setActiveStyleSheet('large');

      forceheight_large(); 
    }
    else {

      str = jQuery("#extra-content").html();
      if (str) {
        jQuery("#extra-container").html(str);
        jQuery("#extra-content").html("");
      }
      setActiveStyleSheet('small');

      forceheight_small(); 

    }
    
    
  };



  jQuery(window).load(function() {
    doResize();   
  });
  jQuery(window).resize(function() {
    doResize();
  });

}) ();


function forceheight_large() {
  // we need to get the highest column and set all to that height.
  var left = jQuery(".left-3col").height();
  var mid = jQuery(".mid-3col").height();
  var right = jQuery(".right-col").height();    
  var extra = jQuery(".extra-content").height();  
  var size_array = [left,mid,right];    
  var max = Math.max.apply(0,size_array); 
  

  jQuery(".left-3col").height(max);
  jQuery(".mid-3col").height(max);
  jQuery(".right-col").height(max); 
  jQuery(".extra-content").height(max);
  
  jQuery(".extra_left").height(max+150);
  jQuery(".extra_right").height(max+150);
  jQuery(".mid_left").height(max);
  jQuery(".mid_right").height(max);
  
  
  jQuery(".node-type-blog .right-col-left").height(jQuery(".right-col").height());
  jQuery(".node-type-blog .right-col-right").height(jQuery(".right-col").height());
  
  // digital services page columns
  if (jQuery("#block-block-6").length > 0){    
    if (jQuery("#services-col-b").length > 0){      
      jQuery("#services-col-b").height(jQuery(".right-col").height() - jQuery("#block-block-6").height());
    }    
  }
};

function forceheight_small() {
  // we need to get the highest column and set all to that height.
  var left = jQuery(".left-3col").height();
  var mid = jQuery(".mid-3col").height();
  var right = jQuery(".right-col").height();    
  var size_array = [left,mid,right];    
  var max = Math.max.apply(0,size_array); 

  jQuery(".left-3col").height(max);
  jQuery(".mid-3col").height(max);
  jQuery(".right-col").height(max); 
  
  
  
  var left = jQuery(".extra_left").height();
  var right = jQuery(".extra_right").height(); 
  var size_array = [left,right];    
  var max = Math.max.apply(0,size_array); 
  jQuery(".extra_left").height(max);
  jQuery(".extra_right").height(max);
  
  var left = jQuery(".mid_left").height();
  var right = jQuery(".mid_right").height(); 
  var size_array = [left,right];    
  var max = Math.max.apply(0,size_array); 
  jQuery(".mid_left").height(max);
  jQuery(".mid_right").height(max);
  
  if (left == 0) {
    jQuery(".mid_left").height(jQuery(".mid-3col").height());
    jQuery(".mid_right").height(jQuery(".mid-3col").height());
  }
  
  
  jQuery(".node-type-blog .right-col-left").height(jQuery(".right-col").height());
  jQuery(".node-type-blog .right-col-right").height(jQuery(".right-col").height());
  
  
  // digital services page columns
  if (jQuery("#block-block-6").length > 0){    
    if (jQuery("#services-col-b").length > 0){      
      jQuery("#services-col-b").height(jQuery(".right-col").height() - jQuery("#block-block-6").height());
    }    
  }
};;

