Drupal.behaviors.backtotop = {
  attach: function(context) {
      (function($) {
      $("body").append("<div id='backtotop'>"+Drupal.t("Back to Top")+"</div>");
      $(window).scroll(function() {
        if($(this).scrollTop() != 0) {
          $('#backtotop').fadeIn();	
        } else {
          $('#backtotop').fadeOut();
        }
      });
  
      $('#backtotop').click(function() {
        $('body,html').animate({scrollTop:0},1200,'easeOutQuart');
      });	
    })(jQuery);
  }
};
;
/**
 * @file
 * Loads report blocks via ajax.  This is done because the API requests to Google
 * Analytics can add signifigant latency to page loads otherwise.
 */
(function ($) {

Drupal.behaviors.googleAnalyticsReports = {
  attach: function (context, settings) {
    $('#block-google-analytics-reports-path-mini,#block-google-analytics-reports-dashboard', context).show();

    if ($('.google-analytics-reports-path-mini', context).length) {
      $.ajax({
        url: Drupal.settings.basePath + 'google-analytics-reports/ajax/path-mini',
        dataType: 'json',
        data: ({ path: window.location.pathname + window.location.search }),
        success: function(data) {
          $('.google-analytics-reports-path-mini', context).html(data.content).hide().slideDown('fast');
        },
        error: function(data) {
          // @TODO
        }
      });
    }

    if ($('.google-analytics-reports-dashboard', context).length) {
      $.ajax({
        url: Drupal.settings.basePath + 'google-analytics-reports/ajax/dashboard',
        dataType: 'json',
        success: function(data) {
          $('.google-analytics-reports-dashboard', context).html(data.content).hide().slideDown('fast');
        },
        error: function(data) {
          // @TODO
        }
      });
    }
  }
}

})(jQuery);;

