var is = {
    ie:      navigator.appName == 'Microsoft Internet Explorer',
    java:    navigator.javaEnabled(),
    ns:      navigator.appName == 'Netscape',
    ua:      navigator.userAgent.toLowerCase(),
    version: parseFloat(navigator.appVersion.substr(21)) ||
             parseFloat(navigator.appVersion),
    win:     navigator.platform == 'Win32'
}
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0) {
    is.ie = is.ns = false;
    is.opera = true;
}
if (is.ua.indexOf('gecko') >= 0) {
    is.ie = is.ns = false;
    is.gecko = true;
}

function stopBubble(e)
{
	var ev = e || window.event;
	if (ev.stopPropagation) {
		ev.stopPropagation();
	} else {
		ev.cancelBubble = true;
	}
}

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function initImages()
{
	var imgLinks = getElementsByClass("inlineShow", document.body, "a");
	for (var i in imgLinks) {
		imgLinks[i].onclick = showSmartImg;
	}
}

var isSmartShown = false;
function showSmartImg(e)
{
	var ev = e || window.event;
	if (!ev) {
		alert (e)
		return true;}
	var obj = (!ev.target) ? ev.srcElement : ev.target;
	if (typeof document.body.removeChild == "undefined" || 
		typeof obj.parentNode == "undefined" ||
		typeof obj.parentNode.cloneNode == "undefined") {
		return true;
	}
	
	obj = (obj.tagName.toLowerCase() == "img") ? obj.parentNode : obj;

	if (isSmartShown !== false) {
		document.body.removeChild(isSmartShown);
	} else if (isSmartShown == obj.parentNode) {
		return false;
	}

	var cont = obj.parentNode.cloneNode(true);
	cont.style.display = "block";
	cont.style.position = "absolute";
	cont.style.border = "2px solid gray";
	cont.style.width = "auto";
	cont.style.height = "auto";
	cont.style.overflow = "visible";
	cont.style.padding = "0px";
	cont.style.margin = "0px";
	cont.style.cursor = "pointer";
	var t = obj.parentNode.offsetTop;
	var l = obj.parentNode.offsetLeft;
	if (is.gecko && !is.mac) {
		l = l - 150;
	}
	var fixBottom = (is.gecko || is.mac) ? " style='margin-bottom: -5px;' " : "";
	if (l < 0) {
		l = 0;
	}
	cont.style.top = (t - 50) + "px";
	cont.style.left = l  + "px";
	//cont.onmouseout = function() {bySmartImg(this);};
	cont.onclick = function(){bySmartImg(this);};
	cont.innerHTML = "<img "+ fixBottom +"alt='' src='"+ obj.href + "' />";
	document.body.onclick = function(){bySmartImg(isSmartShown);};
	document.body.appendChild(cont);
	stopBubble(e);
	isSmartShown = cont;
	return false;
}
function bySmartImg(obj)
{
	if (!obj) {
		return;
	}
	document.body.removeChild(obj);
	isSmartShown = false;
}