/*	Emulate the CSS :target Pseudo-Class in IE
	Copyright 2005 Mark Wubben <http://novemberborn.net/colophon>

	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

// Simple normalization function to clean extra white-space.
String.prototype.normalize = function(){
	return this.replace(/\s+/g, " ");
};

/*	The hack: this function gets executed on load. It'll set `.target` on the element who's ID matches the fragment identifier of the URI.
	It then monitors this identifier every 200 ms for changes. Originally I wanted to use the propagation of the `focus` event so I could 
	check it every time an element got focus, but unfortunately this is not supported in IE.
*/
function emulateCSSPseudoClassTarget(){
	var sCurrentTargetID = getFragmentID();
	
	function setClass(sID){
		var node = document.getElementById(sID);
		if(node == null){
			return;
		};
		var sClassName = node.className;
		if(sClassName == null){
			sClassName = "target";
		} else {
			sClassName = sClassName.normalize() + (sClassName == "" ? "" : " ") + "target";
		};
		node.className = sClassName;
	};
	
	function removeClass(sID){
		var node = document.getElementById(sID);
		if(node == null){
			return;
		};
		node.className = node.className.replace(/\btarget\b/, "");
	};
	
	function getFragmentID(){
		return document.location.hash.replace(/^#(.*)$/, "$1");
	};
	
	function monitor(){
		var sNewTargetID = getFragmentID();
		if(sNewTargetID != sCurrentTargetID){
			removeClass(sCurrentTargetID);
			setClass(sNewTargetID);
			sCurrentTargetID = sNewTargetID;
		};
	};
	
	setClass(sCurrentTargetID);
	
	// Your brain (well, the conscious part) won't notice a change if it happens inside a time-frame of 200 ms. Therefore this is a safe interval.
	setInterval(monitor, 150);
};

window.attachEvent("onload", emulateCSSPseudoClassTarget);

/*
########################################################################################################################
*/

// Mailcrypt
function mailsend(mail,p1,p2,p3) {
	var ca;
	ca = "mailto:" + p2 + "\@" + p3 + "." + p1;
	mail.href = ca;
	return (1);
}

/*
########################################################################################################################
*/

// Analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17050935-10']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

