
var autoscroll_interval = 5;

var fotoAlbum = new Object();

function init_fotoAlbum() {
	fotoAlbum.init = true;
	fotoAlbum.currentAlbum = -1;
	fotoAlbum.currentFoto = 0;
	fotoAlbum.maxThumbWidth = 68;
	fotoAlbum.locked = true;
	fotoAlbum.auto = false;
	fotoAlbum.auto_overimg = new Image();
	fotoAlbum.auto_overimg.src = "./images/fotoslider/autoslide_on.png";
	fotoAlbum.display = new Object();
	fotoAlbum.display.counter = 0; // dots while loading
	fotoAlbum.display.dots = ".";
	fotoAlbum.display.album = new Array();
	for(i=0; i<albumList.album.length; i++){ fotoAlbum.display.album[i] = new Array(); }

	init_list();
	document.getElementById("album_displaywrap").style.top = 12 - fotoAlbum.list.listHeight;
	setOpacity(document.getElementById("fotodisplay"), 0)	
	album_list_show();
}


/*** thumbdisplay ***/

function initScrollLayer() {
	var wndo = new dw_scrollObj('album_thumbs', 'album_thumbwrap', 'album_thumbdisplay');
	dw_scrollObj.GeckoTableBugFix('album_thumbs');

	setOpacity(document.getElementById("album_thumbwrap"), 0);
	fadeIn("album_thumbwrap",0);
	fotoAlbum.locked = false;

	
}

function scrollBy(value, clicked) {
	if(!fotoAlbum.locked) {
		if(clicked){ stop_autoslide(); }
		album_list_hide();
		var scroll = 0;
		switch(value) {
			case "start": scroll = (albumList.album[fotoAlbum.currentAlbum].foto.length+4)*fotoAlbum.maxThumbWidth; break;
			case "prev5": scroll = 5 * fotoAlbum.maxThumbWidth; break;
			case "prev2": scroll = 2 * fotoAlbum.maxThumbWidth; break;
			case "prev": scroll = fotoAlbum.maxThumbWidth; break;
			case "next": scroll = -fotoAlbum.maxThumbWidth; break;
			case "next2": scroll = -2 * fotoAlbum.maxThumbWidth; break;
			case "next5": scroll = -5 * fotoAlbum.maxThumbWidth; break;
			case "end": scroll = -(albumList.album[fotoAlbum.currentAlbum].foto.length+4)*fotoAlbum.maxThumbWidth; break;
			default: break;
		}
		dw_scrollObj.scrollBy("album_thumbs", scroll, 0);
		return false;
	}
}

function buildAlbum(index) {
	document.getElementById("album_displaywrap").style.visibility="visible";
	album_switchImg();
	fotoAlbum.init = false;

	var numberOfFotos = albumList.album[index].foto.length;
	var contents =  "<table id='album_thumbdisplay' width="+((numberOfFotos+4)*fotoAlbum.maxThumbWidth)+" cellspacing='0' cellpadding='0' border='0'><tbody>";
	var row1 = "<tr><td><img src='./images/fotoslider/start.png'></td>";
	var row2 = "<tr><td class='spacer'></td>";

	for(i=0; i<numberOfFotos; i++) {
		var split_url = albumList.album[index].foto[i].split("/");
		split_url[split_url.length-2] += "/thumbs";
		var split_img = split_url[split_url.length-1].split(".");
		split_url[split_url.length-1] = split_img.join("_th.");
		var url = split_url.join("/");
		row1 += "<td><a href='javascript:;' onclick='showfoto(\""+i+"\")'><img src="+url+" class='thumbdisplay' id='thumb"+i+"' border='0'></a></td>";
		row2 += "<td class='spacer'><img src='images/empty.gif' width='"+fotoAlbum.maxThumbWidth+"' height='1' border='0'></td>";
	}
	row1 += "<td><img src='./images/fotoslider/eind.png'></td></tr>";
	row2 += "<td class='spacer'></td></tr>";

	contents +=  row1;
	contents +=  row2;
	contents +=  "</tbody></table>";

	document.getElementById("album_thumbwrap").innerHTML = contents;
	initScrollLayer();
}

function showfoto(index) {
	switch(fotoAlbum.currentFoto-index) {
		case -2: scrollBy("next2"); break;
		case -1: scrollBy("next"); break;
		case 1: scrollBy("prev"); break;
		case 2: scrollBy("prev2"); break;
		default: break;
	}
}

function startScroll(endpos) {
	fotoAlbum.currentFoto = endpos / -fotoAlbum.maxThumbWidth;
	album_switchImg();
}

function endScroll() {
}


/*** control ***/

function changeAlbum(index) {
	fotoAlbum.locked = true;
	if(fotoAlbum.currentAlbum != -1) { document.getElementById("album_item"+fotoAlbum.currentAlbum).style.background = "#EEEEEE"; }
	fotoAlbum.currentAlbum = index;
	document.getElementById("album_item"+fotoAlbum.currentAlbum).style.background = "#CCCCCC";
	fotoAlbum.currentFoto = 0;
	fotoAlbum.currentshow = -1;

	album_list_hide();
	fadeOut("album_thumbwrap", 100);
	fotoAlbum.changealbum_timer = setInterval("changealbum_timer("+index+")", 100);
}

function changealbum_timer(index) {
	if(!fadeout_array["album_thumbwrapbusy"]) {
		clearInterval(fotoAlbum.changealbum_timer);
		buildAlbum(index);
	}
}


function autoslide() {
	if(!fotoAlbum.auto) {
		fotoAlbum.auto = true;
		album_list_hide();
		document.getElementById("album_autoimg").src = fotoAlbum.auto_overimg.src;
		document.getElementById("album_autoslide").innerHTML = "autoslide";
		do_autoslide();
		fotoAlbum.autoslider = setInterval( "do_autoslide()", (autoscroll_interval*1000) );
	} else {
		stop_autoslide();
	}
}

function do_autoslide() {
	if( fotoAlbum.currentFoto < (albumList.album[fotoAlbum.currentAlbum].foto.length-1) ) {
		scrollBy("next", false);
	} else {
		scrollBy("start", false);
	}
}

function stop_autoslide() {
	if(fotoAlbum.auto) {
		fotoAlbum.auto = false;
		document.getElementById("album_autoimg").src = "./images/fotoslider/autoslide.png";
		document.getElementById("album_autoslide").innerHTML = "";
		clearInterval(fotoAlbum.autoslider);
	}
}


/*** list ***/

function init_list() {
	fotoAlbum.list = new Object();
	fotoAlbum.list.listHeight = (albumList.album.length * 15) + 11;

	var list_string = "";
	for(i=0; i<albumList.album.length; i++) {
		list_string += "<a href='javascript:;' id='album_item"+i+"' onclick='changeAlbum("+i+")' onmouseover='album_list_over(this)' onmouseout='album_list_up(this)'>&nbsp;"+albumList.album[i].naam+"</a>";
	}
	document.getElementById("album_listcontent").innerHTML = list_string;

	fotoAlbum.list.step = 0;
	fotoAlbum.list.speed = 3; // minimum pixels per 25 miliseconde
	fotoAlbum.list.dy = (fotoAlbum.list.listHeight);
	fotoAlbum.list.id = "album_list";
	fotoAlbum.list.number_of_steps = Math.round(fotoAlbum.list.dy/fotoAlbum.list.speed);
	document.getElementById(fotoAlbum.list.id).style.top = -fotoAlbum.list.dy;
}

function album_list_show() {
	stop_autoslide();
	if(fotoAlbum.list.step==fotoAlbum.list.number_of_steps) {
		fotoAlbum.list.slider = setInterval("album_list_in()",25);
	} else {
		fotoAlbum.list.slider = setInterval("album_list_out()",25);
	}
}

function album_list_hide() {
	if(fotoAlbum.list.step==fotoAlbum.list.number_of_steps) {
		fotoAlbum.list.slider = setInterval("album_list_in()",25);
	}
}

function album_list_out() {
	fotoAlbum.list.step += 1;
	pos = Math.round(-(fotoAlbum.list.dy - ((fotoAlbum.list.dy / fotoAlbum.list.number_of_steps) * fotoAlbum.list.step)));
	pos_string = pos+"px";
	document.getElementById(fotoAlbum.list.id).style.top = pos_string;
	if(fotoAlbum.list.step==fotoAlbum.list.number_of_steps) { clearInterval(fotoAlbum.list.slider); }
}

function album_list_in() {
	fotoAlbum.list.step -= 1;
	pos = Math.round(-(fotoAlbum.list.dy - ((fotoAlbum.list.dy / fotoAlbum.list.number_of_steps) * fotoAlbum.list.step)));
	pos_string = pos+"px";
	document.getElementById(fotoAlbum.list.id).style.top = pos_string;
	if(fotoAlbum.list.step==0) { clearInterval(fotoAlbum.list.slider); }
}

function album_list_up(obj) {
	if(obj.id!=("album_item"+fotoAlbum.currentAlbum)) {
			obj.style.background = "#EEEEEE";
	}
}

function album_list_over(obj) {
	obj.style.background = "#CCCCCC";
	obj.style.color = "#000000";
}

/*** fotodisplay ***/

function album_switchImg() {
	if(fotoAlbum.display.album[fotoAlbum.currentAlbum][fotoAlbum.currentFoto]==null) {
		fotoAlbum.display.album[fotoAlbum.currentAlbum][fotoAlbum.currentFoto] = new Image();
		fotoAlbum.display.album[fotoAlbum.currentAlbum][fotoAlbum.currentFoto].src = albumList.album[fotoAlbum.currentAlbum].foto[fotoAlbum.currentFoto];
	}

	if(fotoAlbum.currentshow != fotoAlbum.currentFoto) {
		fotoAlbum.display.animTimer = setInterval("album_diplayControl()",25);
		if(!fadeout_array.fotodisplaybusy && !fadein_array.fotodisplaybusy && !fotoAlbum.init) {
			fadeOut("fotodisplay",100);
		}
	}
}

function album_diplayControl() {
	if(fotoAlbum.currentshow == fotoAlbum.currentFoto) {
		clearInterval(fotoAlbum.display.animTimer);
	} else {
		if(!fadeout_array.fotodisplaybusy && !fadein_array.fotodisplaybusy && fotoAlbum.display.album[fotoAlbum.currentAlbum][fotoAlbum.currentFoto].complete) {
			document.getElementById("fotodisplay").src = fotoAlbum.display.album[fotoAlbum.currentAlbum][fotoAlbum.currentFoto].src;
			fotoAlbum.currentshow = fotoAlbum.currentFoto;
			fadeIn("fotodisplay", 0);
			clearInterval(fotoAlbum.display.animTimer);
		}
		fotoAlbum.display.counter++;
		if(fotoAlbum.display.counter==8) { 
			fotoAlbum.display.counter = 0;
			fotoAlbum.display.dots += ".";
			if(fotoAlbum.display.dots.length>6) { fotoAlbum.display.dots = "."; }
			document.getElementById("load_dots").innerHTML = fotoAlbum.display.dots;
		}
	}
}




