var noScript = {
	init: function () {
		var noScriptAnchor, parent;
		noScriptAnchor = Base.byId('noscript');
		if (noScriptAnchor) {
			parent = noScriptAnchor.parentNode;
			parent.removeChild(noScriptAnchor);
		}
	}
};
var newWindowLinks = {
	init: function () {
		var anchors, n, i;
		anchors = Base.getElementsByClass('new-window');
		n = anchors.length;
		for (i=0; i < n; i++) {
			Base.addEventListener(anchors[i], 'click', newWindowLinks.open);
			anchors[i].title += (anchors[i].title == '') ? '(N.B. external web link, opens in a new window.)' : ' (N.B. external web link, opens in a new window.)';
		}
	},
	open: function (event) {
		var return_value = true;
		if (window.open(this.href)) {
			Base.preventDefault(event);
			return_value = false;
		}
		return return_value;
	}
};
var googleSearchForm = {
	init: function () {
		var element = Base.byId('google-search-sidebar');
		if (element) {
			Base.addEventListener(element, 'submit', googleSearchForm._setSearchValues);
		}
		element = Base.byId('google-search-content');
		if (element) {
			Base.addEventListener(element, 'submit', googleSearchForm._setSearchValues);
		}
	},
	_setSearchValues: function () {
		this.q.value='site:www.laydominicansuk.com ' + this.searchtermlist.value;
	}
};
var siteBookmarkIE = {
	init: function () {
		if (typeof window.external !== 'undefined' && typeof window.external.AddFavorite !== 'undefined') {
			var element = Base.byId('IE-Bookmark-h2');
			if (element) {
				Base.addEventListener(element, 'click', siteBookmarkIE._addBookmarkIE);
				element = Base.byId('IE-Bookmark-p');
				if (element) {
					Base.addEventListener(element, 'click', siteBookmarkIE._addBookmarkIE);
				}
			}
		}
	},
	_addBookmarkIE: function (event) {
		window.external.AddFavorite('http://www.laydominicansuk.com/', 'Lay Dominicans of England &amp; Scotland');
		Base.preventDefault(event);
		return false; 
	}
};
var setWidthBlockCentredWithImage = {
	init: function () {
		var block, img, width, caption;
		block = Base.byId('block-centred-with-image');
		if (block) {
			img = block.getElementsByTagName('img');
			if (img) {
				width = img[0].getAttribute('width');
				block.style.width = width + 'px';
				if (typeof isMSIE6 !== 'undefined') {
					/*	kludgeroony for IE6, which takes the width of the child element block-centred-caption as the width 
						for the parent element block-centred-with-image despite explicitly being set above */
					caption = Base.byId('block-centred-caption');
					if (caption) {
						caption.style.width = width + 'px';
					}
				}
			}
		}
	}
};
var tooltips = {
	init: function () {
		var tips, count, i, tip, title;
		tips = Base.getElementsByClass('title-tooltip');
		count = tips.length;
		for (i = 0; i < count; i++) {
			tip = tips[i];
			title = tip.getAttribute('title');
			if(title && title.length > 0) {
				Base.addEventListener(tip, 'mouseover', tooltips.show);
				Base.addEventListener(tip, 'focus', tooltips.show);
				Base.addEventListener(tip, 'mouseout', tooltips.hide);
				Base.addEventListener(tip, 'blur', tooltips.hide);
			}
		}
	},
	show: function(event) {
		var cPos = Base.getCursorPosition(event);
		var sPos = Base.getScrollingPosition();
		var vSize = Base.getViewportSize();
		var xMax = vSize[0] - 25;
		var yMax = vSize[1] - 25;
		var tip = document.createElement('div');
		var content = this.getAttribute('title');
		this.tooltip = tip;
		this.setAttribute('title', '');
		Base.addClass(tip, 'tooltip');
		tip.appendChild(document.createTextNode(content));
		tip.style.visibility = 'hidden';
		tip.style.left = cPos[0] + 10 + 'px';
		tip.style.top = cPos[1] + 10 + 'px';
		document.getElementsByTagName('body')[0].appendChild(tip);
		var offW = tip.offsetWidth;
		var offH = tip.offsetHeight;
		if ((cPos[0] - sPos[0] + 10 + offW) > xMax) {
			tip.style.left = sPos[0] + xMax - offW + 'px';
		}
		if ((cPos[1] - sPos[1] + 10 + offH) > yMax) {
			if (event.clientX > (xMax - offW)) {
				// reposition tooltip so that it will not be placed directly above the cursor, causing a mouseout
				tip.style.top = cPos[1] - offH - 10 + 'px';
			} else {
				tip.style.top = sPos[1] + yMax - offH + 'px';
			}
		}
		tip.style.visibility = 'visible';
		Base.preventDefault(event);
	},
	hide: function(event) {
		t = this.tooltip;
		if (typeof t !== 'undefined') {
			this.setAttribute('title', t.childNodes[0].nodeValue);
			t.parentNode.removeChild(t);
		}
		this.tooltip = null;
	}
};
Base.start(noScript);
Base.start(tooltips);
Base.start(googleSearchForm);
Base.start(siteBookmarkIE);
Base.start(newWindowLinks);
Base.start(setWidthBlockCentredWithImage);

