function Clicky(id)
{
      this.img = new Image();
      this.img_base = "http://static.getclicky.com/in.php?site_id=" + id + "&srv=db8";
      if(this.isset("clicky_custom_session")) {
         for(var i in clicky_custom_session) {
            this.img_base += "&custom[" + this.enc(i) + "]=" + this.enc(clicky_custom_session[i]);
            }
         }
      if(this.isset("clicky_goal")) {
         for(var i in clicky_goal) {
            this.img_base += "&goal[" + this.enc(i) + "]=" + this.enc(clicky_goal[i]);
            }
         }
      var r = RegExp("^https?://[^/]*" + location.host.replace(/^www\./i,"")+"/","i").test(document.referrer)?"":document.referrer;
      this.img.src = this.img_base + '&title=' + this.enc((this.isset("clicky_page_title") ? clicky_page_title : document.title)) + '&href=' + this.enc(location.pathname + location.search) + '&ref=' + this.enc(r) + '&res=' + screen.width + 'x' + screen.height + '&lang=' + (navigator.language || navigator.browserLanguage).substr(0, 2) + '&x=' + Math.random();
	
      var holder = this;
      var this_clicky = holder;

      this.download = function(e) {
      this_clicky.img_src(e, "download");
      }

      this.outbound = function(e) {
      this_clicky.img_src(e, "outbound");
      }

      this.click = function(e) {
      this_clicky.img_src(e, "click");
      }

      this.advanced = function() {
      if(this_clicky.isset("clicky_advanced_disable"))return;
      var is_download = new RegExp("\\.(7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|m4a|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip)$", "i");
      var is_link = new RegExp("^(https?|ftp|telnet|mailto):", "i");
      var is_link_internal = new RegExp("^https?:\/\/(.*)" + location.host.replace(/^www\./i,""),"i");
      var a = document.getElementsByTagName("a");
      for(var i = 0; i < a.length; i++) {
         if(a[i].className.indexOf("clicky_log") >= 0) {
            if(a[i].className.indexOf("clicky_log_download") >= 0) {
               this_clicky.add_event(a[i], "mousedown", this_clicky.download);
               }
            else if(a[i].className.indexOf("clicky_log_outbound") >= 0) {
               this_clicky.add_event(a[i], "mousedown", this_clicky.outbound);
               }
            else {
               this_clicky.add_event(a[i], "mousedown", this_clicky.click);
               }
            }
         else {
            if(is_link.test(a[i].href) && a[i].className.indexOf("clicky_ignore") ==- 1) {
               if(is_link_internal.test(a[i].href)) {
                  if(is_download.test(a[i].href)) {
                     this_clicky.add_event(a[i], "mousedown", this_clicky.download);
                     }
                  }
               else {
                  this_clicky.add_event(a[i], "mousedown", this_clicky.outbound);
                  }
               }
            }
         }
      }

      this.add_event(window, 'load', this.advanced);
}
 
Clicky.prototype.isset = function(e) {
      return(typeof(window[e]) != "undefined");
}
 
Clicky.prototype.enc = function(e) {
      return encodeURIComponent ? encodeURIComponent(e) : escape(e);
}

Clicky.prototype.add_event = function(e, type, func) {
      if(e.addEventListener) {
         e.addEventListener(type, func, false);
         }
      else if(e.attachEvent) {
         e.attachEvent("on" + type, func);
         }
}

Clicky.prototype.img_src = function(e, type) {
      obj = this.get_target(e);
      this.log(this.get_href(obj), this.get_text(obj).substr(0, 60), type);
}

Clicky.prototype.log = function(href, title, type) {
      type = type || "click";
      if(type != "outbound")href = href.replace(/^https?:\/\/([^\/]+)/i,"");
      this.img.src = this.img_base + "&type=" + type + "&title=" + this.enc(title) + "&href=" + this.enc(href) + "&x=" + Math.random();
      this.pause();
}

Clicky.prototype.pause = function() {
      var t = this.isset("clicky_pause_timer") ? clicky_pause_timer : 500;
      var now = new Date();
      var stop = now.getTime() + t;
      while(now.getTime() < stop)var now = new Date();
}

Clicky.prototype.get_text = function(e) {
      do {
         var txt = e.text ? e.text : e.innerText;
         if(txt)return txt;
         if(e.alt)return e.alt;
         if(e.title)return e.title;
         if(e.src)return e.src;
         e = this.get_parent(e);
         }
      while(e);
      return"";
}

Clicky.prototype.get_href = function(e) {
      do {
         if(e.href &&!e.src)return e.href;
         e = this.get_parent(e);
         }
      while(e);
      return"";
}

Clicky.prototype.get_parent = function(e) {
      return e.parentElement || e.parentNode;
}

Clicky.prototype.get_target = function(e) {
      if(!e)var e = window.event;
      var t = e.target ? e.target : e.srcElement;
      if(t.nodeType && t.nodeType == 3)t = t.parentNode;
      return t;
}