/**
 * 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));
;
/**
 * navigation.js
 *
 * crazy ajaxification of the main navigation
 *
 * TODO: exclude some agents (iPhone, Android)
 */


(function ($) {
  Drupal.behaviors.drspitzerNavigation = {
    attach: function(context, settings) {


      var loader = '<div class="loading" style="margin-top:16px;"></div>';


      $('#navigation a').each(function () {
        $(this).attr('x-orig-href', $(this).attr('href'));
        $(this).attr('href', '#');
      });


      $('#navigation a').click(function () {
        // alert($(this).attr('x-orig-href'));
        var a = $(this);
        var href = a.attr('x-orig-href');

        $('#navigation ul#main-menu li').removeClass('active-trail').removeClass('active');
        $('#navigation a').removeClass('active-trail').removeClass('active');
        a.parent('li').addClass('active-trail').addClass('active');
        a.addClass('active-trail').addClass('active');

        if ($('.node .content').html().replace(/^\s+/,"") == '') {
          $('#content').prepend($(loader).fadeIn(600));
        }
        else {
          $('#content .section').fadeOut(200).delay(400).queue(function () {
            $('#content').prepend($(loader).fadeIn(600));
          });
        }

        $('#content').load(href + ' #content .section', function (responseText, textStatus, XMLHttpRequest) {
          $('#content .section').stop(true, true);
          $('#content .section').fadeOut(0, function () {

            $('#content .section').fadeIn(200);

            a.blur();

            Drupal.behaviors.googlemapScaling.attach();

          });
        });

      });


    }
  }
})(jQuery);
;
/**
 * googlemap-scaling.js
 */


(function ($) {
  Drupal.behaviors.googlemapScaling = {
    attach: function(context, settings) {

      // pfusch! sorry

      function resizeMap () {
        map.width(Math.max(255, Math.min(1000, $(window).width() - map.offset().left - 16)));
        map.height(Math.max(180, ( $(window).height() - map.offset().top) - 32));
      }


      function startScaling() {

        if (map.width() != null) {
          $(window).resize(resizeMap);
          resizeMap();
        }
      }


      var map = $('iframe#googlemap');
      startScaling();


    }
  }
})(jQuery);
;

