function slimstatAddLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

slimstatAddLoadEvent(function() {
	var sSrc = '/statisztika/set?ref=' + encodeURIComponent(document.referrer)
		+ '&url=' + encodeURIComponent(document.URL)
		+ '&res=' + encodeURIComponent(screen.width+'x'+screen.height)
		+ '&ttl=' + encodeURIComponent(document.title)
		+ '&ts='+new Date().getTime();
	
	var sImg = document.createElement('img');
	sImg.setAttribute('id', 'statisztikaimg');
	sImg.setAttribute('src', sSrc);
	sImg.setAttribute('style', 'position:absolute;top:-10px;left:0');
	sImg.setAttribute('width', '1');
	sImg.setAttribute('height', '1');
	sImg.setAttribute('alt', '');
	document.body.appendChild(sImg);
  initClickHeat();
});

var clickHeatLastIframe=-1;
var clickHeatTime=0;
var clickHeatQuota=-1;
var clickHeatDocument="";
var clickHeatWait=500;
var clickHeatLocalWait=0;
var clickHeatDebug=(window.location.href.search(/debugclickheat/)!=-1);
function showClickHeatDebug(a){
  if(clickHeatDebug==true){
    document.getElementById("clickHeatDebuggerSpan").innerHTML=a;
    document.getElementById("clickHeatDebuggerDiv").style.display="block"
    }
  }
function catchClickHeat(l){
  try{
    showClickHeatDebug("Gathering click data...");
    if(clickHeatQuota==0){
      showClickHeatDebug("Click not logged: quota reached");
      return true
    }
    if(l==undefined){
      l=window.event;
      c=l.button;
      element=l.srcElement
    }else{
      c=l.which;
      element=null
    }
    if(c==0){
      showClickHeatDebug("Click not logged: no button pressed");
      return true
    }
    if(element!=null&&element.tagName.toLowerCase()=="iframe"){
      if(element.sourceIndex==clickHeatLastIframe){
        showClickHeatDebug("Click not logged: same iframe (a click on iframe opens a popup and popup is closed => iframe gets the focus again)");
        return true
      }
      clickHeatLastIframe=element.sourceIndex
    }else{
      clickHeatLastIframe=-1
    }
    var o=l.clientX;
    var n=l.clientY;
    var p=clickHeatDocument.clientWidth!=undefined?clickHeatDocument.clientWidth:window.innerWidth;
    var k=clickHeatDocument.clientHeight!=undefined?clickHeatDocument.clientHeight:window.innerHeight;
    var j=window.pageXOffset==undefined?clickHeatDocument.scrollLeft:window.pageXOffset;
    var g=window.pageYOffset==undefined?clickHeatDocument.scrollTop:window.pageYOffset;
    if(o>p||n>k){
      showClickHeatDebug("Click not logged: out of document (should be a click on scrollbars)");
      return true
    }
    clickTime=new Date();
    if(clickTime.getTime()-clickHeatTime<1000){
      showClickHeatDebug("Click not logged: at least 1 second between clicks");
      return true
    }
    clickHeatTime=clickTime.getTime();
    if(clickHeatQuota>0){
      clickHeatQuota=clickHeatQuota-1
    }
      params="x="+(o+j)+"&y="+(n+g)+"&url="+encodeURIComponent(document.URL)+"&random="+Date();
    showClickHeatDebug("Ready to send click data...");

    if(clickHeatDebug==true){
      showClickHeatDebug("Click recorded with the following parameters:<br />x = "+(o+j)+" ("+o+"px from left + "+j+"px of horizontal scrolling)<br />y = "+(n+g)+" ("+n+"px from top + "+g+"px of vertical scrolling)<br />width = "+p+"<br />browser = "+clickHeatBrowser+"<br />click = "+c+"<br />site = "+clickHeatSite+"<br />group = "+clickHeatGroup+'<br /><br />Server answer:<br /><iframe src="'+clickHeatServer+"?"+params+'" width="700" height="60"></iframe>')
    }else{
      var q=new Image();
      q.src="/statisztika/clickheat?"+params
    }
    var b=new Date();
    clickHeatLocalWait=b.getTime()+clickHeatWait;
    while(clickHeatLocalWait>b.getTime()){
      b=new Date()
    }
  }catch(f){
    showClickHeatDebug("An error occurred while processing click (Javascript error): "+l.message)
  }
  return true
}
function initClickHeat(){
  if(clickHeatDebug==true){
    document.write('<div id="clickHeatDebuggerDiv" style="padding:5px; display:none; position:absolute; top:10px; left:10px; border:1px solid #888; background-color:#eee; z-index:99;"><strong>ClickHeat debug: <a href="#" onmouseover="document.getElementById(\'clickHeatDebuggerDiv\').style.display = \'none\'; return false">Rollover to close</a></strong><br /><br /><span id="clickHeatDebuggerSpan"></span></div>')
  }
  if(document.addEventListener){
    document.addEventListener("mousedown",catchClickHeat,false)
  }else{
    if(document.attachEvent){
      document.attachEvent("onmousedown",catchClickHeat)
    }
  }
  iFrames=document.getElementsByTagName("iframe");
  for(i=0;i<iFrames.length;i++){
    if(document.addEventListener){
      iFrames[i].addEventListener("focus",catchClickHeat,false)
    }else{
      if(document.attachEvent){
        iFrames[i].attachEvent("onfocus",catchClickHeat)
      }
    }
  }
  clickHeatDocument=(document.documentElement!=undefined&&document.documentElement.clientHeight!=0)?document.documentElement:document.body;
};

