
var Animator = {
	zone: null,
	scene: null,
	image: null,
	stage: null,
	interval: null,
	movement: null,
	opacity: 0,
	vertical: 0,
	horizontal: 0,
	origin: {x: 0, y: 0},
	final: {x: 0, y: 0}
}

function startAnimation(zone) {
	// Add links to header
	var impr = document.getElementById('impr').firstChild;
	impr.appendChild(document.createTextNode('|'));
	var link = document.createElement('a');
	link.setAttribute('href','/Wellnesshotel-Bayern/Datenschutzerklaerung.de.html');
	link.appendChild(document.createTextNode('Datenschutzerklärung'));
	impr.appendChild(link);
	impr.appendChild(document.createTextNode('|'));
	var link = document.createElement('a');
	link.setAttribute('href','/Wellnesshotel-Bayern/disclaimer.de.html');
	link.appendChild(document.createTextNode('Haftungsausschluss'));
	impr.appendChild(link);
	impr.appendChild(document.createTextNode('|'));
	var link = document.createElement('a');
	link.setAttribute('href','/Hotel-Bayern/Familienhotel.de.html');
	link.appendChild(document.createTextNode('Impressum'));
	impr.appendChild(link);

	// Animation preparation ()
	if(!navigator.userAgent.match(/MSIE [56]/)) {
		var el = document.getElementById('hedr').getElementsByTagName('img')[1];
		var ce = document.createElement('div');
		var ni = document.createElement('div');
		ce.appendChild(ni);
		ce.style.background = 'url(/images/wechsel/'+anims[zone][0].source+') top left no-repeat';
		ni.style.background = 'url(/images/wechsel/'+anims[zone][1].source+') top left no-repeat';
		ni.style.opacity = 0;
		ni.style.filter = 'alpha(opacity=0)';
		ni.style.height = '221px';
		ni.style.width = '400px';
		ni.style.position = 'static';
		el.parentNode.replaceChild(ce,el);
		Animator.zone = zone;
		Animator.scene = ce;
		Animator.image = ni;
		Animator.stage = 0;
		el.src = '/images/wechsel/'+anims[zone][1].source;
		el.onload = function () {
		//	Animator.interval = setInterval('Animator.fadeOut()',40);
			Animator.restore();
		}
	}
}

Animator.fadeOut = function () {
	if(this.opacity>=1) {
		this.opacity = 1;
		this.image.style.opacity = 1;
		this.image.style.filter = 'alpha(opacity=100)';
		clearInterval(this.interval);
		this.takeABreak();
	} else {
		this.opacity += 0.01;
		this.image.style.opacity = this.opacity;
		this.image.style.filter = 'alpha(opacity='+(this.opacity*100)+')';
	}
}

Animator.moveUp = function () {
	this.vertical = this.vertical - 1;
	this.image.style.backgroundPosition = 'left '+this.vertical+'px';
	if(this.vertical == this.final.y) {
		clearInterval(this.movement);
		this.movement = null;
	}
}

Animator.moveDown = function () {
	this.vertical = this.vertical + 1;
	this.image.style.backgroundPosition = 'left '+this.vertical+'px';
	if(this.vertical == this.final.y) {
		clearInterval(this.movement);
		this.movement = null;
	}
}

Animator.moveLeft = function () {
	this.horizontal = this.horizontal - 1;
	this.image.style.backgroundPosition = this.horizontal+'px top';
	if(this.horizontal == this.final.x) {
		clearInterval(this.movement);
		this.movement = null;
	}
}

Animator.moveRight = function () {
	this.horizontal = this.horizontal + 1;
	this.image.style.backgroundPosition = this.horizontal+'px top';
	if(this.horizontal == this.final.x) {
		clearInterval(this.movement);
		this.movement = null;
	}
}

Animator.takeABreak = function () {
	this.interval = setTimeout('Animator.restore()',10000);	
}	

Animator.restore = function () {
	if(this.movement) {
		this.interval = setTimeout('Animator.restore()',1000);
		return;
	}
	this.scene.style.background = 'url(/images/wechsel/'+anims[this.zone][this.stage].source+') '+this.horizontal+'px '+this.vertical+'px no-repeat';
	if(++this.stage>=anims[this.zone].length) this.stage = 0;
	this.image.style.opacity = 0;
	this.image.style.filter = 'alpha(opacity=0)';
	this.image.style.background = 'url(/images/wechsel/'+anims[this.zone][this.stage].source+') left top no-repeat'; 
	this.opacity = 0;
	this.interval=setInterval("Animator.fadeOut()",40);
	switch(anims[this.zone][this.stage].movement) {
		case 'up':
			this.final.x = 0;
			this.final.y = 221-anims[this.zone][this.stage].height;
			this.vertical = 0;
			this.horizontal = 0;
			this.image.style.backgroundPosition = 'left '+0+'px';
			this.movement = setTimeout('Animator.movement = setInterval("Animator.moveUp()",40)');
			break;
		case 'down':
			this.final.x = 0;
			this.final.y = 0;
			var origin = 221-anims[this.zone][this.stage].height;
			this.vertical = origin;
			this.horizontal = 0;
			this.image.style.backgroundPosition = 'left '+origin+'px';
			this.movement = setTimeout('Animator.movement = setInterval("Animator.moveDown()",40)');
			break;
		case 'left':
			this.final.x = 380-anims[this.zone][this.stage].width;
			this.final.y = 0;
			this.horizontal = 0;
			this.vertical = 0;
			this.image.style.backgroundPosition = 0+'px top';
			this.movement = setTimeout('Animator.movement = setInterval("Animator.moveLeft()",40)');
			break;
		case 'right':
			this.final.x = 0;
			this.final.y = 0;
			var origin = 380-anims[this.zone][this.stage].width;
			this.horizontal = origin;
			this.vertical = 0;
			this.image.style.backgroundPosition = origin+'px top';
			this.movement = setTimeout('Animator.movement = setInterval("Animator.moveRight()",40)');
			break;
		default:
			this.horizontal = 0;
			this.vertical = 0;
			this.final.x = 0;
			this.final.y = 0;
	}
}

