;(function(exports) {
	"use strict";
	/* globals define, utils */
	// export the class if we are in a Node-like system.
	if (typeof module === 'object' && module.exports === exports) {
		exports = module.exports/* = SemVer*/;
	}
	var helpers = {};
	helpers.displayMenuItem = function(data, index) {
		var item = data.navigation[index];
		if (!item) {
			return false;
		}
		var properties = item.properties;
		if (properties) {
			if ((properties.loggedIn && !data.config.loggedIn) ||
				(properties.globalMod && !data.isGlobalMod && !data.isAdmin) ||
				(properties.adminOnly && !data.isAdmin) ||
				(properties.installed && properties.installed.search && !data.searchEnabled)) {
				return false;
			}
		}
		if (item.route.match('/users') && data.privateUserInfo && !data.config.loggedIn) {
			return false;
		}
		if (item.route.match('/tags') && data.privateTagListing && !data.config.loggedIn) {
			return false;
		}
		return true;
	};
	helpers.buildMetaTag = function(tag) {
		var name = tag.name ? 'name="' + tag.name + '" ' : '',
			property = tag.property ? 'property="' + tag.property + '" ' : '',
			content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : '';
		return '\n\t';
	};
	helpers.buildLinkTag = function(tag) {
		var link = tag.link ? 'link="' + tag.link + '" ' : '',
			rel = tag.rel ? 'rel="' + tag.rel + '" ' : '',
			type = tag.type ? 'type="' + tag.type + '" ' : '',
			href = tag.href ? 'href="' + tag.href + '" ' : '',
			sizes = tag.sizes ? 'sizes="' + tag.sizes + '" ' : '';
		return '\n\t';
	};
	helpers.stringify = function(obj) {
		// Turns the incoming object into a JSON string
		return JSON.stringify(obj).replace(/&/gm,"&").replace(//gm,">").replace(/"/g, '"');
	};
	helpers.escape = function(str) {
		if (typeof utils !== 'undefined') {
			return utils.escapeHTML(str);
		} else {
			return require('../utils').escapeHTML(str);
		}
	};
	helpers.stripTags = function(str) {
		if (typeof S !== 'undefined') {
			return S(str).stripTags().s;
		} else {
			var S = require('string');
			return S(str).stripTags().s;
		}
	};
	helpers.generateCategoryBackground = function(category) {
		if (!category) {
			return '';
		}
		var style = [];
		if (category.bgColor) {
			style.push('background-color: ' + category.bgColor);
		}
		if (category.color) {
			style.push('color: ' + category.color);
		}
		if (category.backgroundImage) {
			style.push('background-image: url(' + category.backgroundImage + ')');
			if (category.imageClass) {
				style.push('background-size: ' + category.imageClass);
			}
		}
		return style.join('; ') + ';';
	};
	helpers.generateChildrenCategories = function(category, relative_path) {
		var html = '';
		category.children.forEach(function(child) {
			if (!child) {
				return;
			}
			var link = child.link ? child.link : ('/category/' + child.slug);
			html += '' +
					'' +
					'' +
					'' +
					'' + child.name + ' ';
		});
		html = html ? ('
' + html + '') : html;
		return html;
	};
	helpers.generateTopicClass = function(topic) {
		var style = [];
		if (topic.locked) {
			style.push('locked');
		}
		if (topic.pinned) {
			style.push('pinned');
		}
		if (topic.deleted) {
			style.push('deleted');
		}
		if (topic.unread) {
			style.push('unread');
		}
		return style.join(' ');
	};
	helpers.getBookmarkFromIndex = function(topic) {
		return (topic.index || 0) + 1;
	};
	helpers.displayUserSearch = function(data, allowGuestUserSearching) {
		return data.loggedIn || allowGuestUserSearching === 'true';
	};
	// Groups helpers
	helpers.membershipBtn = function(groupObj) {
		if (groupObj.name === 'administrators') {
			return '';
		}
		if (groupObj.isMember) {
			return '';
		} else {
			if (groupObj.isPending) {
				return '';
			} else if (groupObj.isInvited) {
				return '';
			} else if (!groupObj.disableJoinRequests) {
				return '';
			} else {
				return '';
			}
		}
	};
	helpers.spawnPrivilegeStates = function(member, privileges) {
		var states = [];
		for(var priv in privileges) {
			if (privileges.hasOwnProperty(priv)) {
				states.push({
					name: priv,
					state: privileges[priv]
				});
			}
		}
		return states.map(function(priv) {
			return '