if(typeof document.createStyleSheet === 'undefined') {
	document.createStyleSheet = (function() {
		function createStyleSheet(href) {
			if(typeof href !== 'undefined') {
				var element = document.createElement('link');
				element.type = 'text/css';
				element.rel = 'stylesheet';
				element.href = href;
			}
			else {
				var element = document.createElement('style');
				element.type = 'text/css';
			}

			document.getElementsByTagName('head')[0].appendChild(element);
			var sheet = document.styleSheets[document.styleSheets.length - 1];

			if(typeof sheet.addRule === 'undefined')
				sheet.addRule = addRule;

			if(typeof sheet.removeRule === 'undefined')
				sheet.removeRule = sheet.deleteRule;

			return sheet;
		}

		function addRule(selectorText, cssText, index) {
			if(typeof index === 'undefined')
				index = this.cssRules.length;

			this.insertRule(selectorText + ' {' + cssText + '}', index);
		}

		return createStyleSheet;
	})();
}

(function() {
 var handler = window.onload;
 window.onload = function() { 
	function getHeadTagQueryString(tag, file, sep) {
		if (!tag) return; tag = (''+tag).toUpperCase();
		var nodes = document.getElementsByTagName('head')[0].childNodes;
		var regexp = new RegExp('(^|/)'+file+sep);
		for (var i=0; i<nodes.length; i++) {
		  var node = nodes[i];
		  if (node.tagName == tag) {
			var url = node.src;
			if (url.match(regexp)) {
			  var arr = url.split(sep, 2);
			  if (arr.length > 1) return arr[1];
			}
		  }
		}
	}
	
	var siteSel = getHeadTagQueryString('script', 'topsitesgroup.js', '#');
	var baseUrl = 'http://www.unitedcoatingsgroup.com/';
	
	document.createStyleSheet(baseUrl + 'css/topsites.css');
	if (siteSel != 'unitedcoatingsgroup'){
		var sheet = document.createStyleSheet();
	}
	
	var theTopSites = '';
	if(!document.getElementById('topsites')) theTopSites += '<div id="topsites">';
	
	theTopSites += 	 	'<ul>' +
						'<li class="primo';
						if(siteSel=='unitedcoatingsgroup') theTopSites += ' sel';
	theTopSites += 		'"><a href="http://www.unitedcoatingsgroup.com/"><span>Unitedcoatings Group</span></a></li>' +
						'<li';
						if(siteSel=='turbocoating') theTopSites += ' class="sel"';
	theTopSites +=		'><a href="http://www.turbocoating.com/"><span>Turbocoating</span></a></li>' +
						'<li';
						if(siteSel=='eurocoating') theTopSites += ' class="sel"';
	theTopSites +=		'><a href="http://www.eurocoating.it/"><span>Eurocoating</span></a></li>' +
						'<li';
						if(siteSel=='surfacedynamics') theTopSites += ' class="sel"';
	theTopSites +=		'><a href="http://www.sdicoatings.com/"><span>Surface Dynamics Memphis - Cincinnati</span></a></li>' +
						'<li';
						if(siteSel=='eurobearings') theTopSites += ' class="sel"';
	theTopSites +=		'><a href="http://www.eurobearings.com/"><span>Eurobearings</span></a></li>' +
						'<li';
						if(siteSel=='vacuumsurtec') theTopSites += ' class="sel"';
	theTopSites +=		'><a href="http://www.vacuumsurtec.com/"><span>Vacuum Surtec</span></a></li>' +
						'<li class="ultimo';
						if(siteSel=='artec') theTopSites += ' sel';
	theTopSites +=		'"><a href="http://www.artecimpianti.it/"><span>Artec</span></a></li>' +
						'</ul>';
						
	if(!document.getElementById('topsites')) theTopSites += '</div>';

	if (jQuery){
		if(document.getElementById('topsites'))jQuery('#topsites').html(theTopSites);
		else jQuery('body').prepend(theTopSites);
	}
	else
	{
		if(document.getElementById('topsites'))document.getElementById('topsites').innerHTML = theTopSites
		else{
			var theBody = document.getElementsByTagName('body')[0];
			theBody.innerHTML = theTopSites + theBody.innerHTML;
		}
	}

	if (handler) handler();
 };
})();
