	// book 1 = 27 pics
	// book 2 = 37 pics
	// book 3 = 0 pics
	var header_x = -100;
	var thumbsTop = 6;

	var busCount = 4;
	var picsPerBus = 11;
	var currentBus = 1;
	var busSpeed = 5000;
	var busDriving = false;
	var parkingLotRelativeDistance = 1.5;
	var thumbsLeft = 100;
	var thumbStep = 63;
	var currentPhoto = 1;

	var busPartsReady = 0;
	var busReady = false;

function busLoaded(){
	busReady = true;
	driveBus();
}

function stopBus() {
	busDriving = false;
	clickThumb(1);
}

function driveTo(y,x) {
	busDriving = true;
	dojo.lfx.html.slideTo(document.getElementById('header'), [y,x], busSpeed).play();
}

function driveBus() {
	if (busPartsReady == picsPerBus && busReady){
		driveTo(atoi(getStyle(document.getElementById('header'), 'top')), header_x);
		busPartsReady = 0;
		setTimeout("stopBus()", busSpeed - 500);
	}
}

function imgLoaded(){
	busPartsReady++;
	driveBus();
}

function getStyle(element,styleProperty) {
	var value;
	if (element.currentStyle) {
		value = element.currentStyle[styleProperty];
	} else if (window.getComputedStyle) {
		value = document.defaultView.getComputedStyle(element, null).getPropertyValue(styleProperty);
	} else {
		alert('fuck! drecksbrowser elendiger!: ' + element.tagName);
	}
	return value;
}
function atoi(str) {
	var i = parseInt(str);
	if ( isNaN(i)  ) {
		return 0;
	} else {
		return i;
	}
}

function loadBus() {   //signals driveBus via onload of thumbnail images
		var busName = new String(currentBus);
		busName = busName.length == 1 ? "0" + busName : busName; 

		document.getElementById('header').style.left = String(Math.ceil(parkingLotRelativeDistance * atoi(getStyle(document.getElementById('header'),'width')))) + "px";;

		while (document.getElementById('bus').childNodes.length) {
			document.getElementById('bus').removeChild(document.getElementById('bus').childNodes[0]);
		}
		for(var i = 1; i <= picsPerBus;i++) {
			var thumbName = new String(i);
			thumbName = thumbName.length == 1 ? "0" + thumbName  : thumbName; 
			var link = document.createElement("a"); 
			link.href = "";
			link.onclick = new Function("clickThumb(" + i + "); return false;");
			var pic = document.createElement("img");
			pic.id = "thumb" + thumbName;
			pic.onload = new Function("imgLoaded();");
			pic.src = "pics/ford72/gallery/" + busName + "/small/" + thumbName + ".gif";
			pic.className = "thumb";
			link.appendChild(pic);
			link.style.position = "absolute";
			link.style.left = atoi(atoi(thumbsLeft) + ( i - 1 ) * thumbStep) + "px";
			link.style.top = thumbsTop + "px";
			document.getElementById('bus').appendChild(link);
		}
}

function bus(i) {
	currentBus = i;
	driveTo(atoi(getStyle(document.getElementById('header'), 'top')), Math.ceil(0 - parkingLotRelativeDistance * atoi(getStyle(document.getElementById('header'),'width'))));
	setTimeout("loadBus()",busSpeed + 300);
}

function changePhoto() {
	clickThumb(currentPhoto);
}


function nextPhoto() {
 if (currentPhoto == picsPerBus) {
	currentPhoto = 1;
 } else {
	 currentPhoto++;
 }
	changePhoto();
}

function prevPhoto() {
	if  (currentPhoto == 1) {
		currentPhoto = picsPerBus;
	} else {
		currentPhoto--;
	}
	changePhoto();
 }


function nextBus() {
	if (busDriving){
		return;
	}
	if (currentBus == busCount) {
		currentBus = 1;
	} else {
		currentBus++;
	}
	driveTo(atoi(getStyle(document.getElementById('header'), 'top')), Math.ceil(parkingLotRelativeDistance * atoi(getStyle(document.getElementById('header'),'width'))));
	setTimeout("loadBus()",busSpeed);
}

function prevBus() {
	if (busDriving){
		return;
	}
	if  (currentBus == 1) {
		currentBus = busCount;
	} else {
		currentBus--;
	}
	driveTo(atoi(getStyle(document.getElementById('header'), 'top')), Math.ceil(0 - parkingLotRelativeDistance * atoi(getStyle(document.getElementById('header'),'width'))));
	setTimeout("loadBus()",busSpeed);
 }

	function clickThumb(photoId){
		currentPhoto = photoId;
		var busName = new String(currentBus);
		busName = busName.length == 1 ? "0" + busName : busName; 
		var photoName = new String(photoId);
		photoName = photoName.length == 1 ? "0" + photoName  : photoName; 
		document.getElementById("currentPic").src = "pics/ford72/gallery/" + busName + "/big/" + photoName + ".jpg";
	}
