window.myParts = {};
function linkShingle() {
	this.readVars();
	this.setTitle();
	this.configLinks();
	this.deferFooter();
}

linkShingle.prototype.configLinks = function() {
	this.pg = this.pathEnd(window.location.toString());
	if (this.pg.indexOf('.html') == -1) this.pg = 'index.html';
	this.el = document.getElementById('linkShingle');
	this.ls = this.el.getElementsByTagName('li');
	for (var i=0;i<this.ls.length;i++) {
		var aa = this.ls[i].getElementsByTagName('a')[0];
		if (aa) {
			var nn = this.pathEnd(aa.href);
			if (nn == this.pg) {
				this.ls[i].className = 'thisLink';
			}
			else this.ls[i].className = 'anotherLink';
		}
	}
}

linkShingle.prototype.readVars = function() {
	var hh = document.getElementsByTagName('head')[0];
	var hm = hh.getElementsByTagName('meta');
	var mm = null;
	for (var i=0;i<hm.length;i++) if (hm[i].name == 'vars') mm = hm[i].content;
	if (mm) window.myMetaVars = eval('({'+mm+'})');
	else window.myMetaVars = {};
}

linkShingle.prototype.setTitle = function() {
	this.titleEl = document.getElementById('pageTitle');
	if (this.titleEl && myMetaVars.title) {
		this.titleEl.innerHTML = myMetaVars.title;
		document.title = document.title.replace(/^\s+|\s+$/g,'') + ' - ' + myMetaVars.title;
	}
}

linkShingle.prototype.pathEnd = function(p) {
	var n = p.split('?')[0].split('#')[0].split('/');
	return n[n.length-1];
}

linkShingle.prototype.deferFooter = function() {
	window.onload = function() {myPageLinks.onload()};
}

linkShingle.prototype.onload = function() {
	this.footer = document.getElementById('pageFooter');
	if (this.footer && myParts.footer) {
		this.footer.innerHTML = myParts.footer;
	}
}

window.myPageLinks = new linkShingle();

