var Stat = { 
  hit: function() {
    var now = new Date();
    var host = "http://stats.avogen.com";
    var key  = "A1x666"
    var uri = host + "/stat/add_stat?key=" + key + "&";
    
    for (test in Stat.Tests) Stat.Tests[test].run();
    
    uri += this.params.join('&');
    
    // Now actually send the stats.
    var img = new Image();
    img.src = uri;
  },

  params: [],
  result: function(k,v) {
    this.params.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
  }

}

if (!Array.prototype.push) {
  Array.prototype.push = function() {
    var startLength = this.length;
    for (var i = 0; i < arguments.length; i++)
      this[startLength + i] = arguments[i];
    return this.length;
  }
}

var Engine = {
  detect: function() {
    var UA = navigator.userAgent;
    this.isKHTML = /Konqueror|Safari|KHTML/.test(UA);
    this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
    this.isOpera = /Opera/.test(UA);
    this.isMSIE  = (/MSIE/.test(UA) && !this.isOpera);
  }
}
Engine.detect();

Stat.Tests = {}

Stat.Tests.Basics = {
  title: function() {
    return (document.title==null || document.title=="")? "No title" : document.title;
  },
  run: function() {
    Stat.result('referer', document.referrer);
    Stat.result('path_info', document.URL);
    Stat.result('page_title', this.title());  
  }
}
  
Stat.Tests.SessionUser = {
  findCookie: function(name) {
    var cookies = document.cookie.split(';');
    for (var i=0; i<cookies.length; i++) {
      var c = cookies[i].split('=');
      if (c[0] == name) return(c[1]);
    }
    return '';
  },
  run: function() {
    Stat.result('user', this.findCookie('uid'));
  }
}

Stat.Tests.Flash = {
  detect: function() {
    if(Engine.isMSIE) return this.detectIE();
    if(navigator.plugins && navigator.plugins.length) {
      var f = navigator.plugins["Shockwave Flash"];
      if (f && (d = f.description)) return d.charAt(d.indexOf('.')-1);
      if (navigator.plugins["Shockwave Flash 2.0"]) return 2;
    }
    if (navigator.mimeTypes && navigator.mimeTypes.length) {
       var f = navigator.mimeTypes['application/x-shockwave-flash'];
       if (f && f.enabledPlugin) return 2;
       return 1;  
    }
    return false;
  },
  detectIE: function() {
    for (var i=7; i>0; i--) {
      try{ var f = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i); return i; }
      catch(e) {}
    }
    return false;
  },
  run: function() {
    Stat.result('flash', this.detect());
  }
}


Stat.hit();

