var balk;
var speed = -1;
var scrollID;

function scroll() {
	balk.style.left = balk.offsetLeft + speed + "px";
	if (balk.offsetLeft < -balk.offsetWidth) {
		balk.style.left = balk.parentNode.offsetWidth+"px";
	}
	setCookie("g2kscroll", balk.style.left);
	startScroll();
}

function stopScroll() {
    if (scrollID) clearTimeout(scrollID);
}
function startScroll() {
	scrollID = setTimeout("scroll()", 25);
}

function scrollinit() {
  if (document.getElementsByTagName("body")[0].id == "home") {
    // center text
    balk = document.getElementById("rotatingnews");
    balk.style.left = (500 - parseInt(balk.offsetWidth/2)) + "px";
  } else {
	balk = document.getElementById("rotatingnews");
	if (balk) {
		balk.style.left = getCookie("g2kscroll") || balk.parentNode.offsetWidth+"px";
		for (i=0; (a = balk.getElementsByTagName("A")[i]); i++) {
			if (a.addEventListener) {
				a.addEventListener("mouseover", stopScroll, false);
				a.addEventListener("mouseout", startScroll, false);
			} else {
				a.attachEvent("onmouseover", stopScroll);
				a.attachEvent("onmouseout", startScroll);
			}
		}
	
		scroll();
	}
  }
}
AddToInitArray(scrollinit);

AddToInitArray(function() {
  if (/page.cgi/.test(location.href)) return;
  // resize: make page less heigh if it doesn't fit
  var wh, ph;
  if (self.innerHeight) { // all except Explorer
    wh = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    wh = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    wh = document.body.clientHeight;
  }
  ph = document.getElementById("header").offsetHeight;
  if (wh < ph) {
    var diff = ph - wh + 20;
    if (diff > 90) diff = 90;
    var org_diff = diff;
    diff -= 25;

    // footer
    var elem = document.getElementById("footer");
    var pos = getPosition(elem);
    elem.style.top = pos[1]-diff+"px";
    elem.style.height = elem.offsetHeight-50+"px";

    // tekst
    elem = document.getElementById("content");
    if (elem) {
    	pos = getPosition(elem);
    	elem.style.top = pos[1]-diff+"px";
    }

    // menu 
    elem = document.getElementById("navigationbg");
    if (elem) {
	    elem.style.height = elem.offsetHeight-diff+"px";
	    elem= document.getElementById("navigation");
	    elem.style.height = elem.offsetHeight-diff+"px";
	}
	
    // sitewide
    elem = document.getElementById("sitewide");
    if (elem) {
    	elem.style.paddingTop = 522-diff+"px";
    }

    // page
    elem = document.getElementById("inner");
    elem.style.height = elem.offsetHeight-org_diff-1+"px";
  }
});

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth=0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	} else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		} else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

/*
BrowserDetect.init();
if (BrowserDetect.browser == "Explorer") {
  function myScrollbars() {
    var wh = getWindowHeight();
    var ww = getWindowWidth();
    if (ww < 980 || wh < parseInt(document.getElementById("inner").style.height)) {
      document.getElementsByTagName("html")[0].style.overflow = "auto";
    } else {
      document.getElementsByTagName("html")[0].style.overflow = "hidden";
    }
  }
  AddToInitArray(myScrollbars);
  window.onresize = myScrollbars;
}
*/