// JavaScript Library for www.praxis-am-volkspark
// copyright stephanjanz.de, 2011

// variable

var mouseLoop;

// pictures

function preLoadBackground() {
	var picture = new Image();
	picture.src = 'grafik/bg_rot.jpg'
}

function preLoadIntro(filename) {
	var bg_rot = new Image();
	bg_rot.src = 'grafik/bg_rot.jpg';
	var picture = new Image();
	picture.src = 'images/'+filename+'.jpg';
	setTimeout("changePic('intro_left', '" + filename + "')", 4000);
}

function setIntro(index) {
	document.body.style.backgroundImage = 'url(images/intro_'+index+'.jpg)';
}

function changePic(id,filename) {
	document.getElementById(id).src='images/'+filename+'.jpg';
}

function replacePic(id,filename) {
	var picture = new Image();
	picture.src = 'images/'+filename+'.jpg';
	setTimeout("changePic('" + id + "', '" + filename + "')", 5000);
}

// popup window

function popWindow(inhalt,breite,hoehe) {
	var popWin;
	popWin = window.open(inhalt, 'lageplan', "width=390,height=590,resizable=yes,scrollbars=no,toolbar=no,status=no,menubar=no");
	popWin.resizeTo(breite,hoehe);
	popWin.focus();
	popWin.close;
}

// check frame
function setTopFrame() {
	if (top.location.href.lastIndexOf("index.htm")==-1)
		top.document.location.href="index.htm"
}

// scroll bar
function scrollBar() {
	if (window.frames[0].document.body.scrollHeight > 550) {
		document.getElementById("arrow_up").src="grafik/arrow_up.gif";
		document.getElementById("arrow_down").src="grafik/arrow_down.gif";
	}
}

function scrollWindow(dy) {
	window.frames[0].scrollBy(0,dy)
}

function stopScroll() {
	window.clearInterval(mouseLoop);
}

function scrollUp(){
	stopScroll();
	mouseLoop = window.setInterval('scrollWindow(-2)', 5)
}

function scrollDown(){
	stopScroll();
	mouseLoop = window.setInterval('scrollWindow(2)', 5)
}

// mouse position
function getMouseX(id){
var MouseClick = window.event;
	return MouseClick.clientX;
}

function getMouseY(id){
var MouseClick = window.event;
	return MouseClick.clientY;
}

// event handler - mouse wheel event
function handle(delta) {
	if (delta < 0)
		scrollWindow(17);
	else
		scrollWindow(-17);
}

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;
}

// Initialisation
if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

