opac = 0;
step = 20;
curStep = 1;
curPage = 1;
noFade = false;
pageCount = 3;
nTop = 224;
nHeight = 18;
nWidth = 144;

function setNoFade() {
	noFade = true;
}

function setOpacity( element, alpha ) {
	var style = element.style;
	if ( style.opacity != null ) { // CSS opacity
		style.opacity = alpha/100;
	}
	else if ( style.MozOpacity != null ) { // Moz proprietary 
		style.MozOpacity = alpha/100;
	}
	else if ( style.filter != null ) { // IE proprietary
		style.filter = "alpha(opacity=0)";
		element.filters.alpha.opacity = alpha;
	}
}

function fadeIn() {
	if (opac < 100) {
		opac+= step;
		if (opac>100) 
			opac=100;
			
		setOpacity(document.getElementById("page1"), opac);
        setTimeout('fadeIn()', 100);
	}
}

function startFadeIn() {
	opac = 0;
	setOpacity(document.getElementById("page1"), 0);
	document.getElementById("page1").style.visibility='visible';
	setTimeout("fadeIn()", 1000);
}

function setStep(newStep) {
	if (curStep == newStep)
		return;
		
	curPageDiv = "page"+curPage;
	
	switch (curStep) {
		case 1:
			document.getElementById("subbg1").style.visibility="hidden";
			document.getElementById("menu").style.visibility="visible";
			break;
		case 2:
			document.getElementById("subbg2").style.visibility="hidden";
			document.getElementById("menu").style.visibility="visible";
			break;
		case 3:
			document.getElementById("subbg2").style.visibility="hidden";
			document.getElementById(curPageDiv).style.visibility="hidden";
			break;
	}
	
	switch (newStep) {
		case 1:
			document.getElementById("subbg1").style.visibility="visible";
			break;
		case 2:
			document.getElementById("subbg2").style.visibility="visible";
			document.getElementById("subbg2").style.cursor="pointer";
			break;
		case 3:
			document.getElementById("subbg2").style.visibility="visible";
			document.getElementById("subbg2").style.cursor="default";
			document.getElementById("menu").style.visibility="visible";
			if (noFade==true) {
				document.getElementById(curPageDiv).style.visibility="visible";
			} else {
				startFadeIn();
			}
			break;
	}
		
	curStep = newStep;
}

function setPage(newPage) {
        hideFloater();

	if (curPage == newPage)
		return;
		
	if (curStep != 3)
		setStep(3);
		
	curPageDiv = "page"+curPage;
	newPageDiv = "page"+newPage;

	document.getElementById(curPageDiv).style.visibility="hidden";
	document.getElementById(newPageDiv).style.visibility="visible";
	
	curPage = newPage;
}

function hideElem(elemID) {
	document.getElementById(elemID).style.visibility="hidden";
}

function showElem(elemID) {
	document.getElementById(elemID).style.visibility="visible";
}

function showLogo() {
	if (curStep>2) {
		hideElem('titel');
		showElem('alt_titel');
	}
}

function hideLogo() {
	if (curStep>2) {
		hideElem('alt_titel');
		showElem('titel');
	}
}

function showNeighboursInit() {
	document.getElementById("neighbourContainer").style.visibility="visible";
	document.getElementById("neighbour").style.visibility="visible";
	document.getElementById("neighbour").scrollTop="0";
}
function showNeighbours() {
	document.getElementById("neighbourContainer").style.visibility="visible";
	document.getElementById("neighbour").style.visibility="visible";
/*	document.getElementById("neighbour").style.backgroundColor="black";
	document.getElementById("neighbour").style.top="2px";
	document.getElementById("neighbour").style.width="382px";
	document.getElementById("neighbour").style.height="242px";
	document.getElementById("neighbour").style.overflow="auto";*/
}
function hideNeighbours() {
	document.getElementById("neighbourContainer").style.visibility="hidden";
	document.getElementById("neighbour").style.visibility="hidden";
/*	document.getElementById("neighbour").style.backgroundColor="transparent";
	document.getElementById("neighbour").style.top=nTop+"px";
	document.getElementById("neighbour").style.width=nWidth+"px";
	document.getElementById("neighbour").style.height=nHeight+"px";
	document.getElementById("neighbour").style.overflow="hidden";*/
}
function showmini(id) {
	if ((opac<100) && (noFade==false)) {
		hidemini();
		return;
	}

	newx = -9999;
	newy = -9999;

	mdiv = document.getElementById("minidiv");
	href = document.getElementById("HREF"+id);
	if (mdiv) {
		html = "ID: "+id;
		if (href) {
			html = html+"<br>";
			html = html+"x: "+href.offsetTop;
			
			p = href.offsetParent;
			
			html = html+"<br>parent: "+p.tagName;
			html = html+"<br>parent-x: "+p.offsetLeft;
			
			pp = p.offsetParent;
			
			html = html+"<br>pp: "+p.tagName;
			html = html+"<br>pp-y: "+p.offsetTop;
			
			ppp = pp.offsetParent;

			newx = p.offsetLeft - 166;
			newy = href.offsetTop + p.offsetTop + pp.offsetTop + ppp.offsetTop -50;
		}
		
		if ((newx!=-9999) && (newy!=-9999)) {
			if (newx<200) {
				newx = 480;
			}
			mdiv.style.left = newx+"px";
			mdiv.style.top = newy+"px";
//			html = html+"<img src=\"mini/mini_"+id+".jpg\">";
			html = "<img src=\"mini/mini_"+id+".jpg\">";
			mdiv.innerHTML = html;
			mdiv.style.visibility = "visible";
		}
	}
}
function doOnLoad() {
	InitialiseScrollableArea();
	setStep(1);
}
function doOnLoadNF() {
	InitialiseScrollableArea();
	setNoFade();
	setStep(3);
	setPage(1);
}

function hidemini() {
	mdiv = document.getElementById("minidiv");
	if (mdiv) {
		mdiv.style.visibility = "hidden";
		mdiv.innerHTML = "";
	}
}

function showFloater(x, y, bild) {
	document.getElementById("floater").style.left = x + "px";
	document.getElementById("floater").style.top = y + "px";
	document.getElementById("floater").style.backgroundImage="url("+bild+")";
	document.getElementById("floater").style.visibility="visible";
}

function hideFloater() {
	document.getElementById("floater").style.visibility="hidden";
}

/*
   Scrollable area code found somewhere in the net and adapted to special case. No URL, sorry....
*/

function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 

bw=new verifyCompatibleBrowser();

var speed=40;
 
var loop, timer;

var initialised = false; 


function ConstructObject(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=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 

function MoveArea(x,y){ 
    this.x=x;
	this.y=y;
    this.css.left=this.x+'px';
    this.css.top=this.y+'px';
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 

function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 

function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 

function PerformScroll(speed){ 
	if (!initialised) {
		InitialiseScrollableArea();
	}
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 

/*
   Mouse wheel handling adapted from: http://adomas.org/javascript-mouse-wheel/
*/

function handle(delta) {
        if (delta < 0)
			objScroller.down(20);
        else
			objScroller.up(-20);
}

function wheel(event){
	var delta = 0;
	if (!event) /* For IE. */
		event = window.event;
	if (event.wheelDelta) { /* IE/Opera. */
		delta = event.wheelDelta/120;
		/** In Opera 9, delta differs in sign as compared to IE.
		*/
		if (window.opera)
			delta = -delta;
	} else if (event.detail) { /** Mozilla case. */
		/** In Mozilla, sign of delta is different than in IE.
		* Also, delta is multiple of 3.
		*/
		delta = -event.detail/3;
	}
	/** If delta is nonzero, handle it.
	* Basically, delta is now positive if wheel was scrolled up,
	* and negative, if wheel was scrolled down.
	*/
	if (delta)
		handle(delta);
	/** Prevent default actions caused by mouse wheel.
	* That might be ugly, but we handle scrolls somehow
	* anyway, so don't bother here..
	*/
	if (event.preventDefault)
		event.preventDefault();
	event.returnValue = false;
}
 
function InitialiseScrollableArea(){ 
	if (!document.getElementById("neighbour"))
		return;

    objContainer=new ConstructObject('neighbourContainer') 
    objScroller=new ConstructObject('neighbour','neighbourContainer') 
    objScroller.MoveArea(0,0) 
    initialised=true; 
    
    elem = document.getElementById("neighbourContainer");
    
	if (elem.addEventListener)
		/** DOMMouseScroll is for mozilla. */
		elem.addEventListener('DOMMouseScroll', wheel, false);
	/** IE/Opera. */
	elem.onmousewheel = document.onmousewheel = wheel;
} 
