var positionen = new Array();
/*var userWidth = window.document.documentElement.clientWidth;
var userHeight = window.document.documentElement.clientHeight;*/
var anzeige = "relative";
var nochmal = true;
var maxCount = 1000;
var count = 0;
var i = 0;
var x = 0;
var y = 0;

var eintragen;

if(unsort) {
	anzeige = "absolute";
} 


function setUserWidth() {
	if(((1280/8) * document.howMuch.anzahl.value) > userWidth) {
		userWidth = parseInt((1280/8) * document.howMuch.anzahl.value);
	}
}

function setAnzeige(dieID) {
	
	if(anzeige == "absolute") {
		if(i == 0){
			x = getRandomWidth(20);
			y = getRandomHeight(80);
			document.getElementById(dieID).style.position = anzeige;
			positionen.push(x + "|" + y);
			setRandomWidth(x, dieID);
			setRandomHeight(y, dieID);
			i++;
		} else {
			
			nochmal = true;
			while(nochmal) {
				x = getRandomWidth(20);
				y = getRandomHeight(80);
				
				eintragen = true;
				for(a = 0; a < positionen.length; a++) {
					var widthHeight = positionen[a].split("|");
					widthArray = parseInt(widthHeight[0]);
					heightArray = parseInt(widthHeight[1]);
					if(parseInt(x) < parseInt(widthArray + 120) && parseInt(x) > parseInt(widthArray - 120)) {
						if(parseInt(y) < parseInt(heightArray + 120) && parseInt(y) > parseInt(heightArray - 120)) {
							eintragen = false;
							break;
						} 
					} 
				}
				
				if(count > maxCount) {
					eintragen = true;
				}
				count++;
				
				if(eintragen) {
					document.getElementById(dieID).style.position = anzeige;
					positionen.push(x + "|" + y);
					setRandomWidth(x, dieID);
					setRandomHeight(y, dieID);
					nochmal = false;
				}
			} 
		}
	}
}

function getRandomWidth(minimum) {
	var x = parseInt(minimum + parseInt(Math.random() * (userWidth - minimum+1)) -300);
	if(x < 0) {
		x = x * -1;
	}
	return x;
}

function getRandomHeight(minimum) {
	var x = parseInt(minimum + parseInt(Math.random() * (userHeight - minimum+1)) -300);
	if(x < 0) {
		x = x * -1;
	}
	if(x < 100) {
		x = x + 100;
	}
	return x;
}

function setRandomWidth(x, dieID) {
	document.getElementById(dieID).style.left = x+"px";
}

function setRandomHeight(y, dieID) {
	document.getElementById(dieID).style.top = y+"px";
}
