var timeout = null;
var activeItem = null;
var isIE = (navigator.userAgent.indexOf('MSIE') != -1) ? true: false;
var isSafari = (navigator.userAgent.indexOf('Safari') != -1) ? true: false;

function $(id) {
	return document.getElementById(id);
}

function getTop(obj) {
	if (isIE)
		return obj.offsetTop;
	var result = obj.offsetTop;
	while((obj=obj.offsetParent)!=null) {
		result+=obj.offsetTop || 0;
	}
	return result;
}

function getLeft(obj) {
	var result = obj.offsetLeft;
	while((obj=obj.offsetParent)!=null) {
		result+=obj.offsetLeft || 0;
	}
	return result;
}

function init() {
	if (isSafari)
		return;
	var i;
	var nn = [2, 8 , 19, 20, 44];
	for (j = 0; j < nn.length; j++) {
		i = nn[j];
		var p = $('p' + i);
		var obj = $('m' + i);
		if(!obj) break;
		p.style.top = parseInt(getTop(obj) + 40) + 'px';
		p.style.left = parseInt(getLeft(obj)) + 'px';
	}
}

function hide(id) {
	$('p' + id).style.visibility = 'hidden';
}

function show(id) {
	if (isSafari)
		return;
	if (activeItem)
		hide(activeItem);
	$('p' + id).style.visibility = 'visible';
	activeItem = id;
}

function clear() {
	if(timeout)
		clearTimeout(timeout);
}

function popup(id, state) {
	if(state) {	
		clear();
		timeout = setTimeout("show('" + id + "')", 200); 
	} else {	
		timeout = setTimeout("hide('" + id + "')", 300);
	}
}
window.onload = function () {
    init();
}