/**
 * @author		Johan Voeten (johan@procurios.nl)
 * @requires	Prototype.js
 * @param
 * @return
 * @description
 */

Kwalitaria = {};

Kwalitaria.WrapText = (function () {
	var init,
		textElem,
		textEndSelector;

	init = function(elemSelector, elemSubSelector) {
		// Get the text before the sub selector.
		var textElements = elemSelector ? $$(elemSelector) : [],
			textElementsLength = textElements.length,
			subSelector = elemSubSelector ? elemSubSelector : '',
			elemInnerhtml = '',
			newContent = '',
			i;

		if (textElementsLength > 0 && subSelector !== '') {
		// Wrap the selected text in a span.
			for (i = 0; i < textElementsLength; i++) {
				elemInnerhtml = textElements[i].innerHTML;
				newContent = '<span>' + elemInnerhtml.sub(subSelector, '</span><');
				textElements[i].update(newContent);
			}
		}
	};

	// Revealing public API
	return {
		init: init
	};
}());

Kwalitaria.Subnav = (function () {
	var init;

	// Next up: Private methods
	init = function() {
		var subNavUlLength = $$('#subnav ul').length,
			subNavLength = $$('#subnav').length;
		// Check if there is a sub menu.
		if (subNavUlLength === 0 && subNavLength === 1) {
			// If the subnav is empty, hide it.
			$$('body')[0].addClassName('no-submenu');
		}
	};

	// Revealing public API
	return {
		init: init
	};
}());

