var curInfo = 0;

function getLeftOffset(obj)
{
	var off = 0;

	while (obj)
	{
		if (parseInt(obj.offsetLeft)){
			off += obj.offsetLeft;
		}else{
			off += 0;
		}
		if (obj.parentElement){
			obj = obj.parentElement;
		}else if (obj.parentNode){
			obj = obj.parentNode;
		}else{
			obj = null;
		}
	}
	
	return (off);
	
}

function getTopOffset(obj)
{
	var off = 0;

	while (obj)
	{
		if (obj.tagName != 'TABLE' && obj.tagName != 'TR' && obj.tagName != 'A'){
			if (parseInt(obj.offsetTop)){
				off += obj.offsetTop;
			}else{
				off += 0;
			}
		}
		if (obj.parentElement){
			obj = obj.parentElement;
		}else if (obj.parentNode){
			obj = obj.parentNode;
		}else{
			obj = null;
		}
	}

	return (off);
	
}


function showInfo(id)
{
	if (! document.getElementById) return;

	var info = document.getElementById('inf'+id);
	var pic  = document.getElementById('pic'+id);
	var browser = navigator.appName;
	var l = 0, t = 0;

	info.style.display = 'block';
	if (info && pic)
	{
		l = getLeftOffset(pic);
		t = getTopOffset(pic) - 30;


		if (id % 3 != 0){
			if (browser == "Microsoft Internet Explorer"){
				l += pic.offsetWidth + 45;
			}else{
				l += pic.offsetWidth + 50 - 40;
			}
		}
		else
		{
			l -= parseInt(info.clientWidth);
			l -= 50;
        }
	}

	info.style.left = l+'px';
	info.style.top = t+'px';
	
	img = pic.firstChild;
	if (img != null)
	{
		switch (id)
		{
			case 1: img.style.backgroundPosition = "0px 135px"; break;
			case 2: img.style.backgroundPosition = "0px 167px"; break;
			case 3: img.style.backgroundPosition = "0px 154px"; break;
			case 4: img.style.backgroundPosition = "0px 115px"; break;
			case 5: img.style.backgroundPosition = "0px 152px"; break;
			case 6: img.style.backgroundPosition = "0px 116px"; break;
			case 7: img.style.backgroundPosition = "0px 129px"; break;
			case 8: img.style.backgroundPosition = "0px 112px"; break;
			case 9: img.style.backgroundPosition = "0px 128px"; break;
		}
	}
	curInfo = id;
}

function hideInfo(id)
{
	if (! document.getElementById) return;

	var info = document.getElementById('inf'+id);
	var pic = document.getElementById('pic'+id);
	info.style.display = 'none';
	img = pic.firstChild;
	if (img != null)
	{
		img.style.backgroundPosition = "0 0";
	}
	curInfo = 0;
}


/*
isParent
http://www.gotdotnet.ru/Forums/Web/460064.aspx
*/

function isParent(child, parent) {
	if (!child || !parent) {
		return false;
	}
	while (true) {
		if (child == parent) {
			return true; 
		}
		if (child.parentElement) {
			child = child.parentElement;
		} else if (child.parentNode) {
			child = child.parentNode;
		} else { 
			return false;
		}
	}
}

function checkTarget(id,event)
{
	if (navigator.appName == "Microsoft Internet Explorer"){
		e = window.event;
	}else{
		e = event;
	}
	var elTo = e.relatedTarget || e.toElement;
	if (elTo && elTo.parentNode.id == 'td'+id)
	{
		hideInfo(id);
		return false;
	}else{
		return false;
	}
	/*
	var elFrom = e.relatedTarget || e.fromElement;
	if (elTo==null || elFrom==null || elTo.firstChild==null || elFrom.firstChild==null)
	{
		return false;
	}
	if (elTo.firstChild.id=="inf" && elFrom.firstChild.id=="pic"+id)
	{
		return false;
	}
	if (elTo.id=="inf" && elFrom.id=="leftBlock"+id)
	{
		return false;
	}
	if (elTo.id=="inf"+id)
	{
		return false;
	}
	var node = document.getElementById('leftBlock'+id);
	var target = e.relatedTarget || e.toElement;
	if (!target)
	{
		return false;
	}
	if(!isParent(target, node)) {
		hideInfo(id);
	}
	*/
}

function checkTargetBlock(id,event)
{
	if (navigator.appName == "Microsoft Internet Explorer"){
		e = window.event;
	}else{
		e = event;
	}
	var node = document.getElementById('inf'+id);
	var target = e.relatedTarget || e.toElement;
	if (!target)
	{
		return false;
	}
	if(!isParent(target, node)) {
		hideInfo(id);
	}
}

function hideAll(){
	hideInfo(1);
	hideInfo(2);
	hideInfo(3);
	hideInfo(4);
	hideInfo(5);
	hideInfo(6);
	hideInfo(7);
	hideInfo(8);
	hideInfo(9);
}
