// /* © 2007 by Jelte Zeilstra */

function albumPrev( button ) {
	f = button.form;
	c = albumGetCurrent( f );
	
	if( c <= 1 ) {
		albumShowPhoto( f, albumGetLast( f ) );
	} else {
		albumShowPhoto( f, c - 1 );
	}
	
	return false;
}

function albumNext( button ) {
	f = button.form;
	c = albumGetCurrent( f );
	
	if( c >= albumGetLast( f ) ) {
		albumShowPhoto( f, 1 );
	} else {
		albumShowPhoto( f, c + 1 );
	}
	
	return false;
}

function albumGo( button, number ) {
	f = button.parentNode.parentNode.parentNode.parentNode.parentNode;
	
	albumShowPhoto( f, number );
	
	return false;
}

function albumGetCurrent( albumform ) {
	spans = albumform.getElementsByTagName( 'span' );
	return parseInt( spans[0].innerHTML );
}
function albumGetLast( albumform ) {
	divs = albumform.childNodes[4].getElementsByTagName( 'div' );
	return divs.length;
}


function albumShowPhoto( albumform, number ) {
	//alert( 'Show ' + number );
	divs = albumform.childNodes[4].getElementsByTagName( 'div' );
	divid = number - 1;
	
	for( i=0; i<divs.length; i++ ) {
		if( i == divid ) {
			divs[i].style.display = 'block';
		} else {
			divs[i].style.display = 'none';
		}
	}
	
	spans = albumform.getElementsByTagName( 'span' );
	spans[0].innerHTML = number;
}


/*** SCROLL ***/
var scroll_loop = false;

function albumScrollLeft() {
	scroll_loop = true;
	albumScrollMove( 2 ) /* Box gaat 1 px naar rechts */;
}
function albumScrollRight() {
	scroll_loop = true;
	albumScrollMove( -2 ) /* Box gaat 1 px links */;
}
function albumScrollStop() {
	scroll_loop = false;
}

function albumScrollMove( pixels ) {
	scrollcontent = document.getElementById( 'albumbar-scroll-content' );
	if( !scrollcontent ) {
		// Nothing to scroll
		alert( 'nothing to scroll' ); //debug
		return;
	}
	if( scrollcontent.style.left ) {
		oudleft = parseInt( scrollcontent.style.left );
	} else {
		oudleft = 0;
	}
	newleft = oudleft + pixels;
	scrollablewidth = -1 * ( scrollcontent.clientWidth - scrollcontent.parentNode.clientWidth );
	
	if( scrollablewidth > 0 ) {
		scrollablewidth = 0;
	}
	
	if( newleft >= 0 ) {
		scrollcontent.style.left = 0;
	} else if( newleft <= scrollablewidth ) {
		scrollcontent.style.left = scrollablewidth + 'px';
	} else {
		scrollcontent.style.left = newleft + 'px';
	}
	
	if( scroll_loop ) {
		setTimeout( "albumScrollMove( " + pixels + " )", 20 );
	}
}

