/*	Copyright 2006 Siorre.ru
	Designed for www.bmstu.ru	*/

function startNav() {

	var nodes = document.getElementById("nav")

	/*	Skip if page has not menu (td with id nav)	*/
	if (nodes) {
		nodes = nodes.getElementsByTagName("td")

		for (var i=0; i<nodes.length; i++) {

			nodes[i].onmouseover = function()
			{
				this.className = "itemOver"
			} 
			nodes[i].onmouseout = function()
			{
				var name = this.className;
				this.className = "";
			}
		}
	}

	/*	Flash VideoPlayer */
	cacheVideo()

	/*	Adapts text output areas
		to screen resolution	*/
	//var stubs = adaptScreen()
	//if (!stubs)
	//	return
	
	/*	Increase text output areas and pads between areas:
		History, Events and Actual areas.	*/
	var n2 = new Array(3)
	n2[0] = document.getElementById("menu")
	n2[1] = n2[0].nextSibling
	
	n2[1] = getElem(n2[1], "tr")	//	Excepts text nodes in Mozilla
	n2[1] = getElem(n2[1], "td")
	n2[0] = getElem(n2[0], "td")
	
	/*	Events or news page	*/
	if (n2[1].className!="h")
		return
	
	/*

	nodes = document.getElementById("content")
	nodes = nodes.getElementsByTagName("td")

	var n = new Array()

	for (i=0; i<nodes.length; i++)
		if (nodes[i].className=="stub")
			n.push(nodes[i])
		else if (nodes[i].className=="news")
			n2[2] = nodes[i]

	for (i=0; i<2; i++)
		n[i].width = stubs[i]+"%";

	if (stubs[0]==3)
	{
		n2[0].width = "31%"
		n2[1].width = "31%"
		n2[2].width = "64%"
	}
	else if (stubs[0]==5)
	{
		n2[0].width = "33%"
		n2[1].width = "33%"
		n2[2].width = "64%"
	}
	*/
}
/*	Uses by startNav (Only for history area html code)	*/
function getElem(node, elemName)
{
	/*	elemName : tr or td */
	if (elemName.match(/td/))
		node = node.firstChild

	while (node && node.nodeName.toLowerCase()!=elemName)
		node = node.nextSibling
	
	return node
}

/*	Uses by startNav	
function adaptScreen() {

	var w = 0
	var h = 0

	w = screen.width
	h = screen.height

	if (w!=0) {

		if (w==1280) {

			return [3,2]
		}
		else if (w > 1280) {

			return [5,2]
		}
	}
	
	return false
}
*/

/*	Flash VideoPlayer	*/
var mem = new Object()
mem.opened = new Array()
mem.num = -1

function cacheVideo() {

	mem.movies = new Array()
	mem.videobg = new Array()

	var n = document.getElementById("movie_holder")
		
	if (!n || !n.firstChild)	/*	No any movies	*/
		return false
	else
		n = n.firstChild
	
	while(n) {
		if (n.nodeName.toLowerCase().match(/object/))
			mem.movies.push(n.cloneNode(true))
		
		n = n.nextSibling
	}

	var j = 0
	var n = true

	while (n) {

		n = document.getElementById("videobg"+j)
		if (n)
			mem.videobg.push(n)
		j++
	}
	
	return true
}

function video(num) {

	var node = document.getElementById("videobg"+num)
	mem.h = parseInt(node.style.height.replace(/px/, ""))
	mem.n = node

	if (mem.opened[num]!=1)	{

		node.style.display = "block"
		
		mem.num = num;
		setTimeout(stretch, 5)
		mem.n.previousSibling.firstChild.firstChild.nodeValue = "Закрыть"
		mem.opened[num] = 1
	}
	else {

		setTimeout(deStretch, 5)
		mem.n.previousSibling.firstChild.firstChild.nodeValue = "Видеорепортаж"
		mem.opened[num] = 0
	}
}

function stretch() {

	if (mem.h < 250) {

		mem.h += 50
		mem.n.style.height = mem.h+"px"
	
		setTimeout(stretch, 10)
	}
	else {
		mem.h += 34
		mem.n.style.height = mem.h+"px"

		var n = document.getElementById("mov"+mem.num)
		mem.videobg[mem.num].appendChild(
			n.parentNode.removeChild(n) )
	}
}
function deStretch() {

	if (mem.h==284)
		mem.n.removeChild(mem.n.firstChild)

	if (mem.h > 34) {

		mem.h -= 50
		mem.n.style.height = mem.h+"px"
		setTimeout(deStretch, 10)
	}
	else {

		mem.h = 0
		mem.n.style.height = mem.h+"px"
		mem.n.style.display = "none"

		var n = document.getElementById("movie_holder")
		n.appendChild(mem.movies[mem.num].cloneNode(true))
	}
}

function windowFormCentered( name, open, winwidth, winheight, param )
{
    var win = null;
    tp=Math.ceil((screen.height-winheight)/2);
    lf=Math.ceil((screen.width-winwidth)/2);
    window.open( open, name, "width="+winwidth+",height="+winheight+",top="+tp+",left="+lf+param+'location=no,status=no,resizable=yes,toolbar=no,scrollbars=1,menubar=no' )
}

