// Added button to "identishare" identified HTML element
document.getElementById('identishare').innerHTML = "<a href=\"http://identi.ca/index.php?action=newnotice&status_textarea="+document.title+" - " + location.href + "\" target=\"_blank\" style=\"background-image: url(\'http://tildehash.com/identishare/share.png\'); display: inline-block; background-repeat: no-repeat; width: 40px; height: 51px; padding: 12px 11px 0px 0px !important; margin: 0px !important; font-family: \'Arial\'; font-size: 11px; text-decoration: none; line-height: 1.2em; color: #000000; text-align: center;\" title=\"Share on Identi.ca\"><b id=\"dent_count\" style=\"float: none !important; margin: 0px !important;\">&middot;&middot;&middot;</b></a><br><span id=\"hidden\" style=\"display: none;\"></span>";
document.getElementById('identishare').style.cssText = 'display: inline-block; vertical-align: top; overflow: hidden;';

// Setup XMLHttpRequest for Firefox, Chrome, Opera, IE 7+, Safari, and fallback for IE 5 & 6
jsonhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

// Add request output to "hidden" identified HTML element
jsonhttp.onreadystatechange = function() {
	if (jsonhttp.readyState == '4' && jsonhttp.status == '200') {
		document.getElementById('hidden').innerHTML = jsonhttp.responseText;
	}
}

// Get and clean page URL
var referrer = location.href.replace('http://', '').replace('www.', '').replace(/#.*$/g, '');
var referrer_clean = new RegExp(referrer.replace(/\?/g, '\\?').replace(/\//g, '\\\\\\/').replace(/#.*$/g, ''), 'gi');

// Get is.gd stortened referrer URL JSON feed, clean URL
jsonhttp.open('GET', 'http://is.gd/create.php?format=json&url=' + location.href, false); jsonhttp.send(null);
var isgd = document.getElementById('hidden').innerHTML.replace('{ "shorturl": "http://', '').replace('" }', '');
var isgd_jsmatch = new RegExp(isgd.replace('/', '\\\\\\/'), 'g');

// Get Identi.ca search JSON feed for referrer URL, count notices
jsonhttp.open('GET', 'http://identi.ca/api/search.json?q=*' + referrer + '&rpp=100', false); jsonhttp.send(null);
var count_one = (document.getElementById('hidden').innerHTML.match(referrer_clean) != null) ? document.getElementById('hidden').innerHTML.match(referrer_clean).length : 0;

// Get is.gd stortened referrer URL, count notices
jsonhttp.open('GET', 'http://identi.ca/api/search.json?q=' + isgd + '&rpp=100', false); jsonhttp.send(null);
var count_two = (document.getElementById('hidden').innerHTML.match(isgd_jsmatch) != null) ? document.getElementById('hidden').innerHTML.match(isgd_jsmatch).length : 0;

var count_three = 0;

// Show notice count, clear hidden data
document.getElementById('dent_count').innerHTML = count_one + count_two + count_three;
document.getElementById('hidden').innerHTML = '';
