// JavaScript Document
var currentDoc = 'index'

function changeDoc(doc) {
	currentDoc = doc;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function play() {
	play1();
	play2();
	play3();
	play4();
	play5();
	play6();
}

function move(badge, down, left) {
	var windowHeight = getWindowHeight();
	var windowWidth = getWindowWidth();
	var el = document.getElementById(badge)
	var elTop = el.style.top;
	var elTopString = elTop.substr(0,elTop.length-2);
	var elLeft = el.style.left;
	var elLeftString = elLeft.substr(0,elLeft.length-2);
	var nummer = badge.substr(8,1)
	//menubalk
	if (currentDoc == 'index') {
		if (Number(elLeftString) > windowWidth/2-485 && Number(elLeftString) < windowWidth/2+355 /*&& Number(elTopString) < 300*/) {
			color(nummer);
		} else {
			grey(nummer);
		}
	}
	if (Number(elTopString) < windowHeight) {
		elTopString = Number(elTopString) + down + "px";
		el.style.top = elTopString;
	} else {
		el.style.top = -300 + "px";
	}
	if (Number(elLeftString) > -300) {
		elLeftString = Number(elLeftString) - left + "px";
		el.style.left = elLeftString;
	} else {
		el.style.left = windowWidth + 300 + "px";
	}
	//document.getElementById('badgebox').width = windowWidth;
	//document.getElementById('badgebox').height = document.getElementById('page').height;
}

function grey(nummer) {
		document.getElementById('badge'+nummer).src = "http://www.dirkvis.net/bestseller/new/wp-content/themes/default/images/badge" + nummer + "zw.png";	
}

function color(nummer) {
		document.getElementById('badge'+nummer).src = "http://www.dirkvis.net/bestseller/new/wp-content/themes/default/images/badge" + nummer + ".png";
}

function play1() {
	move('newbadge1', 1, 1);
	mytime=setTimeout('play1()',100)
}

function play2() {
	move('newbadge2', 1, 2);
	mytime=setTimeout('play2()',60)
}

function play3() {
	move('newbadge3', 2, 3);
	mytime=setTimeout('play3()',47)
}

function play4() {
	move('newbadge4', 4, 2);
	mytime=setTimeout('play4()',40)
}

function play5() {
	move('newbadge5', 3, 5);
	mytime=setTimeout('play5()',50)
}

function play6() {
	move('newbadge6', 2, 1);
	mytime=setTimeout('play6()',32)
}

function poll() {
	document.getElementById('poll').innerHTML = "<p class='vraag'>Uitslag</p><p class='antwoord'><img src='http://www.bestbestseller.nl/wp-content/themes/default/images/uitslag.png' /></p>";
}