// JavaScript Document

var fadingTimer;
var moving = false;
var replaceTimer;

function init() {
	var slider = document.getElementById('programmSliderMiddle');
	for (var x=1;x<slider.childNodes.length; x++) {
		if (slider.childNodes[x].tagName != 'DIV') {
			slider.removeChild(slider.childNodes[x]);
		}
	}
	
	var soundPlayers = document.getElementsByTagName('LI');
	for (var x=0; x < soundPlayers.length; x++) {
		if (soundPlayers[x].className == 'soundPlayer') {
			soundPlayers[x].style.display = 'block';
		}
	}
	
	
}

function move_div(side) {
	if(!moving) {
		moving = true; 
		if (side == 'left') {
			movingTimer = move_left();
		} else if (side == 'right') {
			document.getElementById('programmSliderMiddle').style.width = '564px';
			movingTimer = move_right();
		}
	}
}

function move_left() {
	var targetDiv = document.getElementById('programmSliderLeft');
	var middleDiv = document.getElementById('programmSliderMiddle');
	if (parseInt(targetDiv.style.marginLeft) < 0) {
		targetDiv.style.marginLeft = parseInt(targetDiv.style.marginLeft) + 6 + 'px';
		movingTimer = window.setTimeout("move_left()", 1);
		return;
	}
	window.clearTimeout(movingTimer);
	targetDiv.style.marginLeft = '0px';
	targetDiv.style.width = '700px';
	middleDiv.style.width = '564px';
	document.getElementById('slider').removeChild(document.getElementById('programmSliderRight'));
	middleDiv.id = 'programmSliderRight';
	targetDiv.id = 'programmSliderMiddle';
	moving = false;
}

function move_right() {
	var targetDiv = document.getElementById('programmSliderRight');
	var middleDiv = document.getElementById('programmSliderMiddle');
	if (parseInt(middleDiv.style.marginLeft) > -564) {
		middleDiv.style.marginLeft = parseInt(middleDiv.style.marginLeft) - 6 + 'px';
		//targetDiv.style.marginRight = parseInt(targetDiv.style.marginRight) - 8 + 'px';
		movingTimer = window.setTimeout("move_right()", 1);	
		return;
	}
	window.clearTimeout(movingTimer);
	middleDiv.style.marginLeft = '-564px';
	targetDiv.style.width = '700px';
	document.getElementById('slider').removeChild(document.getElementById('programmSliderLeft'));
	middleDiv.id = 'programmSliderLeft';
	targetDiv.id = 'programmSliderMiddle';
	
	moving = false;
	return;
}


function display_login() {
	var login = document.getElementById('login');
	if (login.style.display == 'block') {
		login.style.display = 'none';
	} else {
		login.style.display = 'block';
	}
}

function display_guestform() {
	var guestform = document.getElementById('guestform');
	if (guestform.style.display == 'block') {
		guestform.style.display = 'none';
	} else {
		guestform.style.display = 'block';
	}
}

var RecaptchaOptions = {
    theme : 'white',
	lang : 'de'
};

var activeSpotlightId = 0;

function change_spotlight() {
	id = activeSpotlightId+1;
	var button = document.getElementById('spotlight_button_'+id);
	if (button != null) {
		load_spotlight(id, true);
	} else {
		load_spotlight(0, true);
	}
}

function load_spotlight(id, automatic) {
	if (id != activeSpotlightId) {
		var button = document.getElementById('spotlight_button_'+activeSpotlightId);
		var spotlight = document.getElementById('spotlight_'+activeSpotlightId);
		var text = document.getElementById('spotlight_text_'+activeSpotlightId);
		
		button.src = 'images/spotlight_deselected.png';
		spotlight.style.display = 'none';
		text.style.display = 'none';
		
		button = document.getElementById('spotlight_button_'+id);
		spotlight = document.getElementById('spotlight_'+id);
		text = document.getElementById('spotlight_text_'+id);
		
		button.src = 'images/spotlight_selected.png';
		spotlight.style.display = 'block';
		text.style.display = 'block';
		
		activeSpotlightId = id;
		
	}
	if (automatic == null) {
		window.clearInterval(spotlightTimer);	
	}
	return;
}

function display_months(target) {
	var monthSelect = document.getElementById('programmMonth');
	if (target.value == 'fullList') {
		monthSelect.style.display = 'none';
	} else {
		monthSelect.style.display = 'inline';		
	}
}

window.onclick = function (ev) {
	if (ev.target.className == 'styleBox') {
		ev.target.previousSibling.checked = !ev.target.previousSibling.checked;
	}
}

