
var imageToggleCSSName = "large";

function locateObj (element, tagName, className) {
	if (element.childNodes && tagName.length) {
		for (var i = 0; i < element.childNodes.length; i++) {
			if (element.childNodes[i].tagName && element.childNodes[i].tagName == tagName) {
				if (className) {
					if (element.childNodes[i].className && element.childNodes[i].className == className) {
						return element.childNodes[i];
					}
				} else {
					return element.childNodes[i];
				}
			}
		}
	}
	return null;
}

function toggleText (element) {
	if (element) {
		var note = locateObj (element, 'DIV', 'note');
		if (note && note.firstChild && note.firstChild.nodeType == 3) {
			if (note.firstChild.nodeValue.match(/larger/i) != null) {
				note.firstChild.nodeValue = note.firstChild.nodeValue.replace(/larger/i, "smaller");
			} else if (note.firstChild.nodeValue.match(/smaller/i) != null) {
				note.firstChild.nodeValue = note.firstChild.nodeValue.replace(/smaller/i, "larger");
			}
		}
	}
}

function toggleImage (element) {
	if (element && imageToggleCSSName.length) {
		var image = locateObj (element, 'IMG');
		if (image.src) {
			if (image.src.match(/\/thumb\//) != null) {
				image.src = image.src.replace(/\/thumb\//, "/full/");
				if (element.className.search(" " + imageToggleCSSName) < 0) {
					element.className += " " + imageToggleCSSName;
				}
				toggleText(element);
			} else if (image.src.match(/\/full\//) != null) {
				image.src = image.src.replace(/\/full\//, "/thumb/");
				if (element.className.search(" " + imageToggleCSSName) >= 0) {
					element.className = element.className.replace((" " + imageToggleCSSName), "");
				}
				toggleText(element);
			}
		}
	}
}

function attachFunctions () {
	if (document && document.getElementsByTagName()) {
		var divs = document.getElementsByTagName("DIV");
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].className.match(/medical\-image/) != null) {
				divs[i].onclick = function () { toggleImage(this); }
			}
		}
	}
}

if (window.onload) {
	var currentFunction = window.onload;
	window.onload = function () { currentFunction(); attachFunctions(); };
} else {
	window.onload = attachFunctions;
}
