var in_process = false;

function Gallery_Show(elem) {
	
	if (in_process)
		return;
	else
		in_process = true;
		
		
	var parent = $(elem).parentNode;
	var children = $('gallery_container').getElementsByClassName('gallery_image_active');
	
	for (x = 0; x < children.length; x++){		
		children[x].setAttribute('className', 'gallery_image');
		children[x].setAttribute('class', 'gallery_image');
	}		
	
	parent.setAttribute('className', 'gallery_image_active');
	parent.setAttribute('class', 'gallery_image_active');
	
	children = $('gallery_detail_container').getElementsByTagName('div');

	for (x = 0; x < children.length; x++){
		if (children[x].id.substring(0,18) == "gallery_container_") {
			$(children[x]).hide();
		}
	}
	$("gallery_container_" + parent.id).show();
	in_process = false;
}

function Gallery_Right() {
	
	if (in_process)
		return;
	else
		in_process = true;
	
	children = $('gallery_container').getElementsByTagName('div');
	start = null;
	end = null;
	// find the first visible child and hide it.
	for (x = 0; x < children.length; x++){
		if ($(children[x]).visible()) {
			start = x;
			break;
		 }
	}
	
	//find the last visible child, add 1 and show it.
	for (x = (children.length - 1); x >= 0; x--){
		if ($(children[x]).visible()) {
			if (x == children.length-1) {
				break;
			}
			else if (x < children.length-1) {
				end = x + 1;
				break;
			}
		 }
	}
	
	if (start != null & end != null) {
		Effect.Fade(children[start].id, {afterFinish: function(){
				Effect.Appear(children[end].id);
		} });
	}
	
	in_process = false;
	
}

function Gallery_Left () {
	
	if (in_process)
		return;
	else
		in_process = true;
		
	children = $('gallery_container').getElementsByTagName('div');
	start = null;
	end = null;
	
	// find the first visible child and hide it.
	for (x = 0; x < children.length; x++){
		if ($(children[x]).visible()) {
			if (x == 0) {
				break;
			}
			else if (x > 0) {
				start = x-1;
				//alert("start: " + start);
				break;
			}
		 }
	}
	
	//find the last visible child, add 1 and show it.
	for (x = (children.length - 1); x > 0; x--){
		if ($(children[x]).visible()) {
			if (x < children.length-1) {
				end = x + 1;
				// alert(x);
				break;
			}
		 }
	}
	
	if (start != null & end != null) {
		Effect.Fade(children[end].id, {afterFinish: function(){
				Effect.Appear(children[start].id);
		} });
	}
	in_process = false;
}