var isDOM,isIE,isNN4,isOpera,isIE4;

if (navigator.userAgent.indexOf('Opera')!=-1) isOpera=1;
if (document.getElementById) isDOM=1;
if (document.all && !isOpera) isIE=1;
if (document.layers) isNN4=1;
if (!isDOM && document.all) isIE4=1;

var contacts = new Array();
var t1 = 0;

function addContact(id, x, y) {
	contacts[id] = new Array();
	contacts[id].x = x;
	contacts[id].y = y;
}

function placeMarks(img_dir) {
	var parent = new getPosObj('world');
	for (var id in contacts) {
		var obj = getStyle(id+'-mark-layer');
		if (obj) {
			obj.top = parent.y + contacts[id].y;
			obj.left = parent.x + contacts[id].x;
		} else {
			document.write('<div id="'+id+'-mark-layer" style="position: absolute; top: '+(parent.y + contacts[id].y)+'px; left: '+(parent.x + contacts[id].x)+'px;">');
			document.write('<a onmouseover="over(\''+id+'\')" onmouseout="out(\''+id+'\')" href="javascript:;" onfocus="this.blur();">');
			document.write('<img id="'+id+'-mark" src="'+img_dir+'/world-mark.gif" border="0" alt="">');
			document.write('<a>');
			document.write('</div>');
		}
	}
}


function over(id) {
	clearTimeout(t1);
	hide(null, id);
	var obj = getObj(id), objStyle = getStyle(id), bg = getStyle(id+'-bg'), mark = new getPosObj(id+'-mark');
	var mouse_x = 0, mouse_y = 0, w, h;
	if (obj && mark) {
		w = obj.offsetWidth;
		h = obj.offsetHeight;
		//распологаем объект под маркером, по-центру
		objStyle.top = mark.y + 30; //отступ от маркера, что бы мышка не перекрывала контент
		objStyle.left = (mark.x + mark.w / 2) - (w / 2);
		setView(id, 1);
		if (bg) {
			bg.top = objStyle.top;
			bg.left = objStyle.left;
			bg.height = obj.offsetHeight;
			bg.width = obj.offsetWidth;
			setView(id+'-bg', 1);
		}
	}
}
function out(id) {
	t1=setTimeout("hide('"+id+"')", 700);
}

function hide(id, exclude) {
	if (null == id) {
		for (var i in contacts) {
			if (i != exclude) { setView(i, 0); setView(i+'-bg', 0); }
		}
	} else {
		setView(id, 0);
		setView(id+'-bg', 0);
	}
}

function getObj(n) {
	if(isDOM) return document.getElementById(n);
	if(isIE) return document.all[n];
	return document.layers[n];
}

function getStyle(n) {
	var obj=getObj(n);
	if(obj) {
		if(isNN4) return obj;
		return obj.style;
	}
}

function getPosObj(n) {
	if(isNN4) {
		this.x=event.pageX;
		this.y=event.pageY;
		this.w=this.h=0;
		return;
	}
	var obj=getObj(n);
	this.x=obj.offsetLeft;
	this.y=obj.offsetTop;
	this.w=obj.offsetWidth;
	this.h=obj.offsetHeight;
	while((obj=obj.offsetParent)!=null && obj.tagName!='BODY') {
		this.x+=obj.offsetLeft;
		this.y+=obj.offsetTop;
		if(isNaN(obj.border)) continue;
		this.x+=parseInt(obj.border);
		this.y+=parseInt(obj.border);
	}
}

function setView(n, s) {
	var obj=getStyle(n);
	if(obj) {
		obj.display = (s) ? 'block' : 'none';
	}
}