// onclick="showPosterPage('Know Now Poster Series', 'images/ContentImages/Know', 1, 4)"

function showPosterPage(title, urlFrag, pg, ct) {
	var loader = document.getElementById("loaderBG");
	loader.innerHTML = "";

	var p = addElement(loader, "p", null, "// " + title + " | ");

	for (var i = 1; i <= ct; i++) {
		addPageNumber(i);
		addText(p, " | ");
	}

	var img = addElement(loader, "img");
	img.src = urlFrag + pg + ".jpg";


	function addPageNumber(n) {
		if (pg == n) {
			addText(p, n);
		}
		else {
			var a = addElement(p, "span", "pagelink", n);
			a.onclick = function() { showPosterPage(title, urlFrag, n, ct); };
		}
	}
}


function transitionElement(elem, delay) {
	if (delay == null)
		delay = 60;
	includeClass(elem, "transition");
	setTimeout(function() { excludeClass(elem, "transition"); }, delay);
}


/// Creates and adds a child element to a parent element.
/// @param parent : The parent element.
/// @param name : The name of the child element to create.
/// @param clazz : The CSS class to apply to the element. (optional)
/// @param content : The HTML content for the child element. (optional)
/// @returns The new element object.
function addElement(parent, name, clazz, content) {
	var child = parent.ownerDocument.createElement(name);
	if (clazz != null)
		child.className = clazz;
	if (content != null)
		child.innerHTML = content;
	return parent.appendChild(child);
}


/// Adds text to an element. This function is useful when you don't want the
/// text to be interpreted as markup.
/// @param parent : The node where the text element is added.
/// @param text : The text to be added.
/// @returns The new text element.
function addText(parent, text) {
	var doc = parent.ownerDocument;
	var child = doc.createTextNode(text);
	return parent.appendChild(child);
}


function hasClass(elem, clazz) {
	return (clazz && (" " + elem.className + " ").indexOf(" " + clazz + " ") != -1);
}


function includeClass(elem, clazz) {
	if (clazz && (" " + elem.className + " ").indexOf(" " + clazz + " ") == -1)
		elem.className += " " + clazz;
}


function excludeClass(elem, clazz) {
	if (clazz) {
		var className = elem.className;
		var index = (" " + className + " ").indexOf(" " + clazz + " ");
		if (index != -1)
			elem.className = className.substring(0, index) + className.substring(index + clazz.length + 1);
	}
}
