/*
 * Google Analytics code embedding with host filtering
 */
// Global for Google Analytics to find it
var _gaq = _gaq || [];

(function() {
  var filteredHosts = [
    'aurora',
    'aurora-neu',
    'dtele.de', // Thus do not embed this way on dtele.de!
    '217.7.249.100'
  ];
  
  // Filter local embeds
  for (var i = 0; i < filteredHosts.length; ++i) {
    // Filtered host is expected to be at the end of the hostname
    var expectedIndex = document.location.hostname.length - filteredHosts[i].length;
    // Find the actual position of the domain, if any
    var actualIndex = document.location.hostname.indexOf(filteredHosts[i]);
    
    if ((actualIndex > -1) && (actualIndex == expectedIndex)) {
      return;
    }
  }
  
  // Make sure Google Analytics account was set properly
  if (!gaAccount || !/UA-[0-9]+-[0-9]+/.test(gaAccount)) {
    alert('Bitte Google-Analytics-Account mit der Variable "gaAccount" ' +
          'im Format "UA-XXXXXXXX-X" festlegen!');
    return;
  }

  // Actual Google Analytics code
  _gaq.push(['_setAccount', gaAccount]);
  _gaq.push(['_gat._anonymizeIp']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
})();
