var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

container = "ContentMASK"
present = "ContentTEXT";

//Tempo festlegen fuer Scrollfunktion
if (dom) speed = 1
if (iex) speed = 1
if (ns4) speed = 1

onResize = loadAgain;

function loadAgain() {
	if (ns4) 
		self.location.reload();
}

/********************************** Initialisieren der Scrollcontainer und -inhalte ************************************/

function getElement(name,nest){
	nest = nest ? "document."+nest+"." : "";
	var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+"document."+name) : false;
	el.css = ns4 ? el : el.style;
	el.hideVis = function(){el.css.visibility="hidden"};
	el.showVis = function(){el.css.visibility="visible"};
	el.getTop = function(){return parseInt(el.css.top) || 0};
	el.setTop = function(y){el.css.top = ns4 ? y: y+"px"};
	el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
	el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
	return el;
}

function scrollInit() {
	if (dom) { 
		 layer = document.getElementById("ContentMASK").getElementsByTagName("div");
		 layer["ContentTEXT"].style.visibility = "visible";
		 layer["ContentTEXT"].style.top = 0;
	 }
 	 else if (iex) {
		 document.all["ContentTEXT"].style.visibility = "visible";
		 document.all["ContentTEXT"].style.top = 0;
	 }
	 else if(ns4) {
		 layer = "document['ContentMASK'].document";
		 eval(layer + "['ContentTEXT']" + '.visibility = "visible"');
		 eval(layer + "['ContentTEXT']" + '.top = 0');
	 }
	 
	 upObj = getElement("up"); // Reference to the up arrow div
	 downObj = getElement("down"); // Reference to the down arrow div
	 	 
	 contentObj = getElement("ContentTEXT","ContentMASK");
	 contentHeight = contentObj.getHeight(); // Height of the content div
	 ContentMASKObj = getElement("ContentMASK"); // Reference to the content mask div
 	 ContentMASKHeight = ContentMASKObj.getClipHeight();// Height of the div that masks the content div
	 
	 if(contentHeight<=ContentMASKHeight){
		upObj.hideVis();
		downObj.hideVis();
	}else{
		upObj.showVis();
		downObj.showVis();
	}
}

/********************************** Die eigentliche Scrollfunktion ***********************************************/

function scroll(direction, speed) {
	 if (dom) {
		 var layertop = parseInt(layer["ContentTEXT"].style.top);
		 var scrollheight = (document.getElementById("ContentMASK").offsetHeight - layer["ContentTEXT"].offsetHeight);
	 }
	 else if (iex) {
		 var layertop = parseInt(document.all["ContentTEXT"].style.top);
		 var scrollheight = (document.all("ContentMASK").offsetHeight - document.all["ContentTEXT"].offsetHeight);
	 }
	 else if (ns4) {
		 var layertop = parseInt(document[container].document[present].top);
		 var scrollheight = (document["ContentMASK"].clip.height - document["ContentMASK"].document["ContentTEXT"].clip.height);
	 }

	 if (direction == "down" && layertop - 1 > scrollheight) {
        if (dom)
			  layer["ContentTEXT"].style.top = (layertop - speed) + "px";
	    else if(iex)
			  document.all["ContentTEXT"].style.top = (layertop - speed) + "px";
	    else if(ns4) 
			  document["ContentMASK"].document["ContentTEXT"].top = (layertop - speed);
	 }
	 else if (direction == "up" && layertop < -1 ) {
		if(dom)
			  layer["ContentTEXT"].style.top = (layertop + speed) + "px";
		else if(iex)
			  document.all["ContentTEXT"].style.top = (layertop + speed) + "px";
		else if(ns4)
			  document["ContentMASK"].document["ContentTEXT"].top = (layertop + speed);
		 }
		 
	timer = setTimeout("scroll('" + direction + "', " + speed + ")", 10);
}

function hideScrollbars(){
	if(document.getElementsByTagName){
		document.getElementsByTagName("body")[0].style.overflow = "hidden";
	}
}

function fixNetscape4(){
	if(ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(document.layers){
	ns4origWidth = window.innerWidth;
	ns4origHeight = window.innerHeight;
	window.onresize = fixNetscape4;
}

/********************************** Auf MouseOut die Funktion stoppen *******************************************/

function stop() {
    clearTimeout(timer);
}

window.onload = scrollInit;

