// (c) Radek HULAN, http://hulan.cz/
// This work is licensed under the Creative Commons Attribution License.
//
// TOPLIST.cz statistics that works under XHTML 1.1 served with
// MIME type application/xhtml+xml as well as text/html MIME type.
//
//
// Usage - place this in your XHTHML 1.1 code:
// <a id='toplist' title='64941'></a>
// <script type='text/javascript' src='toplist.js'></script>
// <noscript> <div>
// <a href='http://www.toplist.cz/'>
//  <img src='http://toplist.cz/count.asp?id=64941&amp;logo=bc' alt='TOPLIST.cz' />
// </a>
// </div> </noscript>

// helper functions
var isXHTML;
function createNewEle(ele){
 if(isXHTML)
  return document.createElementNS('http://www.w3.org/1999/xhtml', ele);
 else
  return document.createElement(ele);
};

function toplist(){
 var ele=document.getElementById('toplist');
 if (!ele) return;
 isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
 // toplist.cz id from title
 var id=parseInt(ele.getAttribute('title'));
 if (!id) alert('TITLE attribute does not contain your TOPLIST.cz ID!');
 var img=ele.getElementsByTagName('img');
 // set new A attributes
 ele.href='http://toplist.cz/stat/'+id;
 ele.setAttribute('title','TOPLIST.cz');
 // create IMG
 var img=ele.appendChild(createNewEle('img'));
 img.setAttribute('alt','TOPLIST.cz');
 img.setAttribute('src','http://toplist.cz/dot.asp?id='+id
  +'&http='+escape(document.referrer)
  +'&wi='+escape(window.screen.width)
  +'&he='+escape(window.screen.height)
  +'&cd='+escape(window.screen.colorDepth)
  +'&t='+escape(document.title));
}
toplist();

