// copyright (c) 2001 by Andy V. Kasatkin (aka taker)

var roll_supported = (document.images)? true : false;
var subnav_supported = (dom || nn4 || ie4);
var timeout = 0;
var active = -1;
var target;

navbar = new Array();

function navitem(name, xpos, ypos, width, height) {
	this.name = name;
	this.xpos = xpos;
	this.ypos = ypos;
	this.width = width;
	this.height = height;
	this.subnav = new Array();
	return this;

}

function subnavitem(url, name) {
	this.name = name;
	this.url = url;
	return this;
}

// navigation init ======================

navbar[0] = new navitem('itwas', 86, 36, 164, 0);
navbar[0].subnav[0] = new subnavitem('/src/itwas/techno', 'Технические неполадки');
navbar[0].subnav[1] = new subnavitem('/src/itwas/experiment', 'Эксперимент');
navbar[0].subnav[2] = new subnavitem('/src/itwas/earthquake', 'Землетрясение');
navbar[0].subnav[3] = new subnavitem('/src/itwas/diversion', 'Диверсия');
navbar[0].subnav[4] = new subnavitem('javascript:wo3(\'/itwas/accident.html\')', 'Последствия катастрофы');
navbar[0].subnav[5] = new subnavitem('/src/itwas/chronicle', 'Хроника ликвидации');

navbar[1] = new navitem('law', 86, 73, 117, 71);
navbar[1].subnav[0] = new subnavitem('/src/law/rights', 'Права');
navbar[1].subnav[1] = new subnavitem('/src/law/laws', 'Законы');
navbar[1].subnav[2] = new subnavitem('/src/law/discussion', 'В обсуждении');

navbar[2] = new navitem('sochelp', 86, 110, 182, 71);
navbar[2].subnav[0] = new subnavitem('/src/sochelp/progress', 'Достигнуто');
navbar[2].subnav[1] = new subnavitem('/src/sochelp/culture', 'Культурные мероприятия');
//navbar[2].subnav[2] = new subnavitem('/src/sochelp/publishing', 'Издательская деятельность');

navbar[3] = new navitem('fund', 86, 187, 125, 43);
navbar[3].subnav[0] = new subnavitem('/src/fund/story', 'История создания');
navbar[3].subnav[0] = new subnavitem('/src/fund/zaslon', '&laquo;Заслон&nbsp;Чернобыля&raquo;');
navbar[3].subnav[1] = new subnavitem('/src/fund/gov', 'Участие власти');

navbar[4] = new navitem('medicine', 86, 156, 169, 43);
navbar[4].subnav[0] = new subnavitem('/src/medicine/hospital', 'Медицинские учреждения');
navbar[4].subnav[1] = new subnavitem('/src/medicine/healthcentre', 'Санатории');

navbar[5] = new navitem('face', 86, 219, 216, 71);
navbar[5].subnav[0] = new subnavitem('/src/face/liquidators', 'Ликвидаторы');
navbar[5].subnav[1] = new subnavitem('/src/face/people', 'Жители загрязненных территорий');
navbar[5].subnav[2] = new subnavitem('/src/face/children', 'Дети Чернобыля');
navbar[5].subnav[3] = new subnavitem('/src/face/gallery', 'Галерея скорби');

navbar[6] = new navitem('creative', 86, 263, 179, 71);
navbar[6].subnav[0] = new subnavitem('/src/creative/art', 'Изобразительное искусство');
//navbar[6].subnav[1] = new subnavitem('/src/creative/folkart', 'Народные поделки');
navbar[6].subnav[1] = new subnavitem('/src/creative/poem', 'Стихи');
//navbar[6].subnav[3] = new subnavitem('/src/creative/prose', 'Проза');

navbar[7] = new navitem('magazine', 86, 230, 179, 71);
navbar[7].subnav[0] = new subnavitem('/src/newspaper/barrier', 'Заслон');
navbar[7].subnav[1] = new subnavitem('/src/newspaper/publishing', 'Издательская деятельность');


// ======================================

$(document).ready(function(){
	$('div.subnav').hover(
		function(){
		},
		function(){
			$(this).hide();
		}
	);
});

function show(item) {
	$('div.subnav').hide();
	$('#'+item).show().css('visibility', 'visible');
	return;
	if (dom) { if (document.getElementById(item)) document.getElementById(item).style.visibility = "visible"; }
	if (ie4) { if (document.all[item]) document.all[item].style.visibility = "visible"; }
	if (nn4) { if (document.layers[item]) document.layers[item].visibility = "show"; }
}

function hide(item) {
	if (dom) { if (document.getElementById(item)) document.getElementById(item).style.visibility = "hidden"; } 
	if (ie4) { if (document.all[item]) document.all[item].style.visibility = "hidden"; } 
	if (nn4) { if (document.layers[item]) document.layers[item].visibility = "hide"; }
}

function move_subnav(item, xoff, yoff) {
	if (dom) {
		document.getElementById(item).style.left = xoff;
		document.getElementById(item).style.top = yoff;
	} else if (ie4) {
		document.all[item].style.left = xoff;
		document.all[item].style.top = yoff;
	} else if (nn4) {
		document.layers[item].left = xoff;
		document.layers[item].top = yoff;
	}
}

function deactivate() {
	timeout = 0;
	if (active != -1) {
		hide(navbar[active].name)
		active = -1;
	}
}

function over(item) {
	if (subnav_supported) {
		if (timeout != 0) { clearTimeout(timeout); timeout = 0; }
		if (active != item) {
			if (active != -1) hide(navbar[active].name);
			if (item != -1) show(navbar[item].name);
			active = item;
		}
	}
}

function out(item) {
	if (subnav_supported) timeout = setTimeout("deactivate()",1);
}

function inArea(checkX, checkY, areaX, areaY, areaW, areaH) {
	return ((checkX >= areaX) && (checkY >= areaY) && (checkX < areaX + areaW) && (checkY < areaY + areaH));
}

function mouseMove(e) {
	var x = (nn)? e.pageX : event.clientX;
	var y = (nn)? e.pageY : event.clientY;
	if ((ie) && (document.body.scrollTop)) y += document.body.scrollTop;
	if (active != -1) {
		if (inArea(x, y, target.x, target.y, 90, 375) || inArea(x, y, target.x + navbar[active].xpos, target.y + navbar[active].ypos, navbar[active].width, navbar[active].height)) {
			if (timeout != 0) { clearTimeout(timeout); timeout = 0; }
		} else {
			if (timeout == 0) { setTimeout("deactivate()",500); /* setTimeout("hide('"+navbar[active].name+"')",500); */ }
		}
	}
	return true;
}

// big thanx for leechy@design.ru

function relPos(which) {
	if (nn4) {
		this.x = document.layers[which].pageX;
		this.y = document.layers[which].pageY;
	} else {
		var elem = (dom)? document.getElementById(which) : document.all[which];
		this.x = elem.offsetLeft;
		this.y = elem.offsetTop;
		while (elem.offsetParent != null) {
			elem = elem.offsetParent;
			this.x += elem.offsetLeft;
			this.y += elem.offsetTop;
			if (elem.tagName == 'BODY') break;
		}
	}
	return this;
}

// end of thanx :-)

function init_subnav() {
	for (var item = 0; item < navbar.length; item++) {
		nav = navbar[item];
		document.writeln('<div id="' + nav.name + '" class="subnav"' + ((nn4) ? '>' : 'style="width:' + nav.width + 'px">'));
		document.writeln('<table cellpadding="0" cellspacing="0" border="0">');
		document.writeln('<tr>');
		document.writeln('<td><img src="/img/corner1.gif" width="7" height="7" border="0" alt=""></td>');
		document.writeln('<td background="/img/bg1.gif"><img src="/img/void.gif" width="7" height="7" border="0" alt=""></td>');
		document.writeln('<td><img src="/img/corner2.gif" width="10" height="7" border="0" alt=""></td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('<td background="/img/bg2.gif"><img src="/img/void.gif" width="7" height="7" border="0" alt=""></td>');
		document.writeln('<td bgcolor="#EDEDED">');
		for (var i = 0; i < nav.subnav.length; i++) {
			if (i != 0) document.writeln('<img src="/img/void.gif" width="100" height="2" border="0" alt=""><br>');
			if (nav.subnav[i].url == location.pathname)	
				document.writeln('<span class="disabled">' + nav.subnav[i].name + '</span><br>');
			else 
				document.writeln('<a class="DropMenu" href="' + nav.subnav[i].url + '">' + nav.subnav[i].name + '</a><br>');
		}
		document.writeln('</td>');
		document.writeln('<td background="/img/bg3.gif"><img src="/img/void.gif" width="10" height="8" border="0" alt=""></td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('<td><img src="/img/corner3.gif" width="7" height="10" border="0" alt=""></td>');
		document.writeln('<td background="/img/bg4.gif"><img src="/img/void.gif" width="8" height="10" border="0" alt=""></td>');
		document.writeln('<td><img src="/img/corner4.gif" width="10" height="10" border="0" alt=""></td>');
		document.writeln('</tr>');
		document.writeln('</table>');
		document.writeln('</div>');
	}
}

function place_subnav() {
	target = new relPos('target');
	for (var i = 0; i < navbar.length; i++)
		with (navbar[i]) move_subnav(name, target.x + xpos, target.y + ypos);
}

function init_events() {
	if (nn) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = mouseMove;
}

function init() {
	init_subnav();
	init_events();
	place_subnav();
}

function openWindow(url, name, width, height) {
	var x = (screen) ? Math.floor((screen.width - width) / 2) : 0;
	var y = (screen) ? Math.floor((screen.height - height) / 2) : 0;
	var win = window.open(url, name, 'resizable=0,left=' + x + 'px,top=' + y + 'px,width=' + width + 'px,height=' + height + 'px,scrollbars=0');
	win.focus();
	return win;
}

function openFaces() {
	openWindow('/src/face/','faces', 540, 495);
}
