function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()
var loop, timer

function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	treeY -= move;
	}
}

function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	treeY -= move;
	}
}

function scrollTree(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

var scrolling_news = null;
function scrollNews(move){
	if (scrollnewsLoaded){
		if (oNews.y<-oNews.scrollHeight){
		clearTimeout(scrolling_news);
			oNews.y=oNewsCont.clipHeight;
		}
			oNews.moveIt(0,oNews.y-move)
		clearTimeout(scrolling_news);
			scrolling_news = setTimeout("scrollNews("+move+")",1)
			//scrolling_news = setTimeout("scrollNews("+move+")",5000)
	}
}
	

function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}
var scrollnewsLoaded = false

function scrollnewsInit(){
	oNewsCont = new makeObj('divScrollNewsCont')
	oNews = new makeObj('divNews','divScrollNewsCont')
	oNews.moveIt(0,0)
	oNewsCont.css.visibility = "visible"
	scrollnewsLoaded = true
	scrolling_news = setTimeout("scrollNews(0.1)",1)
}


function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//PullMenu functions by Asparuh Krastev
//Copyright Lemon Graphics
var fadeObjects = new Array();

function fadeObj(obj, s, dl, ul) {
	this.element = obj;
	this.step = s;
	this.dnLimit = dl;
	this.upLimit = ul;
	this.dir = null;
	this.running = false;
	this.objIndex = fadeObjects.push(this)-1;
	this.interval = null;
	this.opacity = this.dnLimit;

	this.fader = function() {
		if (this.dir==0) {
			if (this.opacity>this.dnLimit) this.opacity -= this.step;
			else {
				this.opacity = this.dnLimit;
				this.element.style.visibility = "hidden";
				clearInterval(this.interval);
				this.running = false;
			}
		} else {
			if (this.opacity<this.upLimit-this.step) this.opacity += this.step;
			else {
				this.opacity = this.upLimit;
				clearInterval(this.interval);
				this.running=false;
			}
		}
		this.element.style.opacity=this.opacity;
		this.element.style.filter = "Alpha(opacity="+this.opacity*100+")";
	}
	
	this.fade = function (direction, s) {
		if ((this.dir = direction)==1) this.element.style.visibility = "visible";
		this.step = s;
		if (!this.running) {
			this.interval = setInterval('fadeObjects['+this.objIndex+'].fader()', 20);
			this.running = true;
		}
	}
	this.fade(1, this.step);
}

function startFade(obj, direction, s, dl, ul) {
	var i;
	for(i=0; i<fadeObjects.length; i++) {
		if (fadeObjects[i].element===obj) {fadeObjects[i].fade(direction, s); return}
	}
	new fadeObj(obj, s, dl, ul);
}

var opened_menu = new Array("0_menu");

//document.onmouseover = hideMenuUntil;

function pullDown(button, menu_id)
{
	var menu_obj = document.getElementById(menu_id);
	hideMenuUntil(menu_id);
	if (menu_obj)
	{
			position = findPos(button);
			menu_obj.style.left = position[0]+(mainMenuVertical?button.offsetWidth*0.8:0);
			menu_obj.style.top  = position[1]+(mainMenuVertical?0:button.offsetHeight);
			
			opened_menu.push(menu_id);
			startFade(menu_obj, 1, 0.1, 0, 1)
	}
}

function hideMenuUntil(menu_id)
{
	if (!menu_id) menu_id = "0_menu";
 	for(var i=opened_menu.length-1; i; i--)
	{
		if (opened_menu[i]!=menu_id) {
			var op_menu = document.getElementById(opened_menu[i]);
			opened_menu.pop();
			startFade(op_menu, 0, 0.1, 0, 1)
		}
	}
}

onresize = initLayersPos;

function initLayersPos()
{
	var leftColumn;
 	if (leftColumn = document.getElementById("left_column")) {
		var slideBox = document.getElementById("slideBox").parentNode;
		slideBox.style.left=15+leftColumn.offsetWidth;
		slideBox.style.top=16+leftColumn.offsetHeight;
		slideBox.style.visibility = "visible";
	}
}

function initialize()
{
	if(navigator.appName == "Microsoft Internet Explorer")
		document.execCommand('BackgroundImageCache', false, true); //Fixes background flickering problem

	//initMenu()
	if (document.getElementById("divScrollNewsCont")) scrollnewsInit();
	initLayersPos();
}

onload = initialize;
var menuTop;
var menu_layer =null;

function initMenu()
{	
	//menu_layer = document.getElementById("root_menu_div");
	//menuTop = parseInt(menu_layer.style.top);
}

var scrollSpeed = 0;
var menu_scrolling = null;
var startMenu = null;
var offsetMenu = 0;
var dist_divident = 0;

function initMoveMenu()
{
	clearTimeout(startMenu);
	if (!menu_layer) initMenu();
	menu_layer_top = parseInt(menu_layer.style.top);
	dist_divident = Math.abs(-menu_layer_top +document.body.scrollTop+menu_top_limit);
	startMenu = setTimeout("moveMenu()", 200);
}

function moveMenu()
{
	clearTimeout(menu_scrolling);
	if ((y = document.body.scrollTop+menu_top_limit-menuTop) ==0) return;
	menu_layer_top = parseInt(menu_layer.style.top);
	(dist = menuTop+y - menu_layer_top)>0?sign=1:sign=-1;
	dist = Math.abs(dist);
	menu_layer_top += sign*scrollSpeed;
	if (menu_layer_top < menuTop)
	{
		scrollSpeed=0;
		menu_layer.style.top = menuTop;
	}
	else if (sign*menu_layer_top<sign*(menuTop+y))
	{
		y<0?extra=180:extra=0;
		(scrollSpeed = (dist-extra)/(dist_divident-extra)*menu_scroll_step)<1?scrollSpeed=1:0;
		menu_layer.style.top = menu_layer_top;
		menu_scrolling = setTimeout("moveMenu("+y+")", 10);
	}
	else  if (menu_layer_top>menuTop+y)
	{
		scrollSpeed=0;
		menu_layer.style.top = menuTop+y;
	}
}