// Takes the id of the behaviorized element, an optional id of roll-over image, and optional id of a parent element to restict the behavior to.
function mouseOverToggle(id_hover, id_img, id_restrict) {
	var elHover = document.getElementById(id_hover);
	var elImg = document.getElementById(id_img);
	if ( !(id_restrict) || (elHover.parentNode.id == id_restrict) ) {
		// On mouse over
		elHover.onmouseover = function() {
			var hoverCN = elHover.className;
	
			// Change from the "nohover" class to "hover" for styling.
			if (hoverCN.search('nohover') != -1) {
				elHover.className = hoverCN.replace("nohover", "hover");
			}

			/* If an image id is passed, change src path to the hover image.
			   NOTE: expects a standardized image filename schema
			   The current schema used is _on / _off for hover/nohover */
			if (elImg) {
				var imgpathOff = elImg.getAttribute('src');
				// fixes filename for correct non-click image
				imgpathOff = imgpathOff.replace('_animated', '');
				var imgpathOn = imgpathOff.replace("_off", "_on");
				elImg.src = imgpathOn;
			}
		}

		// On mouseout
		elHover.onmouseout = function() {
			var hoverCN = elHover.className;

			/* Change from the "hover" class to "nohover" for styling.
			   Because 'nohover' contains the word 'hover', must make sure that we can differentiate. */
			if ((hoverCN.search('hover') != -1) && (hoverCN.search('nohover') == -1)) {
				elHover.className = hoverCN.replace("hover", "nohover");
			}

	                /* If an image id is passed, change src path to the hover image.
			  NOTE: expects a standardized image filename schema
			  The current schema used is _on / _off for hover/nohover */
			if (elImg) {
				var imgpathOn = elImg.getAttribute('src');
				imgpathOn = imgpathOn.replace('_animated', '');
				var imgpathOff = imgpathOn.replace("_on", "_off");
				elImg.src = imgpathOff;
			}
		}
	}
}

// Takes the id of the behaviorized element, the id of an element to expand/close, the id of an element to swap text, the id of roll-over image, and an optional parent element to restrict the behavior to.
function mouseClickToggle(id_clickon, id_expand, id_text, id_img, id_restrict) {	
	var elClickon = document.getElementById(id_clickon);
	if ( !(id_restrict) || (elHover.parentNode.id == id_restrict) ) {
		elClickon.onclick = function() {
			var elExpand = document.getElementById(id_expand);
			var elText = document.getElementById(id_text);
			var expandCN = elExpand.className;
			var elImg = document.getElementById(id_img);

			// If the expand element is closed (hidden), check for a passed image id to alter, check for the swap-text id to alter, and open(show) the expand element.
			if (expandCN.search('hide') != -1) {
		
				/* If an image id is passed, change src path to the open image.
				   NOTE: Expects a standardized image filename schema
				   Thayer schema currently used is _closed / _open */
				if (elImg) {
					var imgpath = elImg.getAttribute('src');

					if (imgpath.search('_closed_animated') != -1) {
						var imgpathOpen = imgpath.replace("_closed", "_open");
					// Makes sure to change filename to correct onclick image, which has '_animated' after the _closed / _open
					} else if (imgpath.search('_closed') != -1){
						imgpathOpen = imgpath.replace("_closed", "_open_animated");
					}

					elImg.src = imgpathOpen;
				}

				// Swap in different text, if needed.
				if (elText) {
					elText.innerHTML = "Hide Additional Pages";
				}

				// Make the closed element open
				elExpand.className = expandCN.replace('hide', 'show');

				// Otherwise the expand element must be closed, so vice versa.
				} else if (expandCN.search('show') != -1) { 

		                        /* If an image id is passed, change src path to the closed image.
       		 	                   NOTE: Expects a standardized image filename schema
                		           Thayer schema currently used is _closed / _open */
					if (elImg) {
						imgpath = elImg.getAttribute('src');

						if (imgpath.search('_open_animated') != -1) {
							imgpathClosed = imgpath.replace("_open", "_closed");
						// Makes sure to change filename to correct onclick image, which has '_animated' after the _closed / _open
						} else if (imgpath.search('_open') != -1) {
							imgpathClosed = imgpath.replace("_open", "_closed_animated");
						}
						elImg.src = imgpathClosed;
					}

	                        // Swap in different text, if needed.
				if (elText) {
					elText.innerHTML = "Show Additional Pages";
				}

				// Make the open element closed
				elExpand.className = expandCN.replace('show', 'hide');
			}
		}
	}
}

// preload open image (variable not used elsewhere)
openIcon1 = new Image();
openIcon2 = new Image();
openIcon3 = new Image();
openIcon4 = new Image();
openIcon5 = new Image();
openIcon6 = new Image();
openIcon1.src="/wp-content/themes/blogtxt_46_thayer/images/arrow_open_off_16.gif";
openIcon2.src="/wp-content/themes/blogtxt_46_thayer/images/arrow_open_animated_on_16.gif";
openIcon3.src="/wp-content/themes/blogtxt_46_thayer/images/arrow_open_on_16.gif";
openIcon4.src="/wp-content/themes/blogtxt_46_thayer/images/arrow_closed_off_16.gif";
openIcon5.src="/wp-content/themes/blogtxt_46_thayer/images/arrow_closed_animated_on_16.gif";
openIcon6.src="/wp-content/themes/blogtxt_46_thayer/images/arrow_closed_on_16.gif";
