var intervall_GT = 20;
var position = new Array(84, 229);
var offset = new Array(2, 1);
var offset_climax = new Array(4, 0);
var steps_climax = 15;

var timer, counter, climax_counter;
function initNissanGT(){
	document.getElementById("nissan_gt").style.top = position[0] + "px"
	document.getElementById("nissan_gt").style.left = position[1] + "px";
	document.getElementById("nissan_gt").style.background = "url(media/karosserie.gif) top left no-repeat";
	
	counter = 0; steps = 500; climax = false, climax_counter = 0;
	timer = window.setInterval("bewegeNissanGT()", intervall_GT);
}

function stoppeNissanGT(){
	window.clearInterval(timer);
}

function bewegeNissanGT(){
	var neue_position = new Array(-1, -1);

	if (! climax){
		counter++;
		if (counter <= steps){
			for (var i = 0; i < 2; i++){
				neue_position[i] = position[i] + Math.round((zufall(offset[i] * 2) - (offset[i] / 2)) * (counter/steps));
			}
		} else {
			steps = steps_climax;
			counter = 0; climax = true;
		}
	} else {
		counter++;
		if (counter <= steps){
			for (var i = 0; i < 2; i++){
				neue_position[i] = Math.round(position[i] - (Math.sin(Math.PI * counter/steps) * offset_climax[i])/(climax_counter + 1));
				if (climax_counter == 0){
					neue_position[i] += Math.round((zufall(offset[i] * 2) - (offset[i] / 2)) * (1 - counter/steps));
				}
			}
		} else {
			climax_counter++;
			if (climax_counter < 2){
				steps = steps_climax;
				counter = 0; climax = true;
			} else {
				steps = 10 * intervall_GT + zufall(8 * intervall_GT);
				counter = 0; climax_counter = 0; climax = false;
			}
		}
	}
	
	if (neue_position[0] != -1){ document.getElementById("nissan_gt").style.top = neue_position[0] + "px"; }
	if (neue_position[1] != -1){ document.getElementById("nissan_gt").style.left = neue_position[1] + "px"; }
}

function zufall(n) {
	var zahl = Math.random() * n;
	if ( zahl == n ){ zahl = 0 }
	return Math.floor(zahl);
	
}