/*
+++++++++++++++++++++++++++++++++++++++++++
+ Website:                                +
+ Musikgesellschaft Schinznach Dorf       +
+ mgschinznach.ch                         +
+ (c)Patrick Carpenter, pcarpenter@gmx.ch +
+++++++++++++++++++++++++++++++++++++++++++
*/

ieMenu = function() {
	// check for IE > 5
	if(document.all && document.getElementById){
		var sub_menus = document.getElementById("nav").getElementsByTagName("ul");
		for(i=0; i < sub_menus.length; i++){
			sub_menus[i].parentNode.onmouseover = function () {
				this.className = "hover";
			}
			sub_menus[i].parentNode.onmouseout = function () {
				this.className = "";
			}
		}
	}
}
window.onload = ieMenu;

/*
Resize Content div if the screen is too small
*/

if(getInsideHeight() < 611){
	var target_height = getInsideHeight() - 261;
	document.write('<style type="text/css">');
	document.write('div#root{ margin-top: -' + (target_height+261)/2 + 'px; ');
	document.write('height: ' + (target_height+261) + 'px;} ');
	document.write('div#content{ height:' + target_height + 'px; } ');
	document.write('</style>');
}

function getInsideHeight() {
	if(window.innerHeight){ // standard
		return window.innerHeight;
	}
	if(document.documentElement.clientHeight) { // IE >= 6 standard
		return document.documentElement.clientHeight;
	}
	if(document.body) { // IE < 6
		return document.body.clientHeight;
	}
}


/*
Wheel scroll
(from http://adomas.org/javascript-mouse-wheel/)
*/


function handle(delta) {
	if (delta < 0){
		goDown(20);		
	} else{
		goUp(20);
	}
}

function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		//if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		handle(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

/* Initialization code. */
if (window.addEventListener){
	window.addEventListener('DOMMouseScroll', wheel, false);
}
window.onmousewheel = document.onmousewheel = wheel;


/*
Basic Scroll
*/

function getOffset() {
	container = document.getElementById("content").getElementsByTagName("div")[0];
	var string = container.style.marginTop;
	if(string == ""){
		return 0;
	}
	return parseInt(string);
}

function setOffset(numb) {
	container = document.getElementById("content").getElementsByTagName("div")[0];
	container.style.marginTop = numb + "px";
}

function goDown(speed) {
	if(getOffset() < 240 - container.offsetHeight){
		if(speed < 5){
			window.clearInterval(scrolling);
		}
		return;
	}
	setOffset(getOffset() - speed);
}

function goUp(speed) {
	if(getOffset() > -1){
		if(speed < 5){
			window.clearInterval(scrolling);
		}
		return;
	}
	setOffset(getOffset() + speed);
}

function goToEnd(target) {
	switch(target){
		case "top":
			setOffset(0);
			break;
		case "bottom":
			if(container.offsetHeight > container.parentNode.offsetHeight){
				setOffset(240 - container.offsetHeight);
			}
	}
}

function scrollDown() {
	document.getElementById("arrow_down").className = "over";
	scrolling = window.setInterval("goDown(3)", 2);
}

function scrollUp() {
	document.getElementById("arrow_up").className = "over";
	scrolling = window.setInterval("goUp(3)", 2);
}

function scrollStop() {
	document.getElementById("arrow_up").className = "";
	document.getElementById("arrow_down").className = "";
	window.clearInterval(scrolling);
}

