


// GLOBAL INIT
$(document).ready(function() {
	
	Content.init();
	
});



/***********************************************
	PAGE NAVIGATION COLLAPSE
************************************************
	call Content.init()
	when document is ready
***********************************************/
var Content = {

	// IMAGES
	externalLinksImage : "resources/images/external.png",
	emailImage         : "resources/images/email.png",
	
	
	// INIT
	init: function () {
		
		this.externalLinks();
		this.spamProtection();
		
	},


	// EXTERNAL LINKS
	externalLinks: function() {

		var myAnchors = document.getElementsByTagName("A");
		for (var i = 0, n = myAnchors.length; i < n; i++) {
			var urlhref = myAnchors[i].href;
			var urlexternal = (
				(!urlhref.indexOf("http://") || !urlhref.indexOf("https://"))
				&& urlhref.indexOf("http://" + document.location.host)
				&& urlhref.indexOf("https://" + document.location.host)
			);
			if (urlhref && urlexternal) {
				myAnchors[i].className = "External " + myAnchors[i].className;
				myAnchors[i].target = "_blank";
				var currclass = " " + myAnchors[i].className + " ";
				if (currclass.indexOf(" NoExternalImage ") < 0) {
					var myImg = document.createElement("IMG");
					myImg.src = this.externalLinksImage;
					myAnchors[i].appendChild(document.createTextNode("\u00a0"));
					myAnchors[i].appendChild(myImg);
				}
			}
		}

	},


	// SPAM PROTECTION
	spamProtection: function() {

		var collection = document.getElementsByTagName("SPAN");
		for (var ccnt = 0; ccnt < collection.length; ccnt++) {
			var myElem = collection[ccnt];
			if (myElem.className != "Protection") continue;
			var mailImg = myElem.firstChild;
			var mySrc = mailImg.src;
			var myExp = /e=(.*)&n=(.*)&d=(.*)&c=(.*)$/;
			var myMatch = mySrc.match(myExp);
			if (!myMatch) { alert("spam protection error"); continue; }
			var to = myMatch[1] + "." + myMatch[3] + "@" + myMatch[2];
			to = to.rot13().reverse();
			var myLink = document.createElement("A");
			myLink.href = "mailto:" + to;
			var myImg = document.createElement("IMG");
			myImg.src = this.emailImage;
			myLink.appendChild(document.createTextNode(to + "\u00a0"));
			myLink.appendChild(myImg);
			myElem.replaceChild(myLink, mailImg);
		}
		
	}


};



