// ==UserScript==
// @name Advanced site signature
// @author TarquinWJ and LiteraryMoose 
// @namespace http://www.howtocreate.co.uk/ 
// @version 1.0
// @description  Adds a multiple class site signature to the HTML
//			element on all pages. This script is deprecated
//			since Opera 9.
// @ujs:category general: enhancements
// @ujs:published 2005-05-25 08:37
// @ujs:modified 2005-10-26 10:03
// @ujs:documentation http://userjs.org/scripts/general/enhancements/root-site-signature 
// @ujs:download http://userjs.org/scripts/download/general/enhancements/root-site-signature.js
// ==/UserScript==


/* 
 * Please see
 * http://www.howtocreate.co.uk/operaStuff/userJavaScript.html#terms
 * for License and Terms of Use
 */

function ujsenabledRootSignature() {
	var d=document.documentElement;
	//replace dots with space
	var locHost = location.hostname.replace(/^www\./g,'').replace(/\./g,' ');
	//remove IDN characters
	locHost = locHost.replace(/[^\w- ]/g,'');
	//prepend leading numbers with underscore
	locHost = locHost.replace(/\b(\d)/g,'_$1');
	d.className = (d.className?(d.className+' '):'') + locHost;
	//alert(document.documentElement.className); //for debugging
}

//you can choose:

  //interval timer, applies the class almost instantly - NOT recommended
  //however it is sometimes so fast the browser does not realise, and you may get minor rendering mistakes
//var mwjDoneNums = 0, mwjCheckNode = setInterval('mwjDoneNums++;if(document.documentElement){clearInterval(mwjCheckNode);ujsenabledRootSignature();}else if(mwjDoneNums>50){clearInterval(mwjCheckNode);document.addEventListener(\'load\',ujsenabledRootSignature,false);}',25);

  //onload, applies the class once the page has completed loading
  //the content will remain unstyled as the page is loading, but it is more reliable
document.addEventListener('load',ujsenabledRootSignature,false);