
var debug = 0;

function debug_print() {
	
	document.getElementById("debug_0").innerHTML = menu[0];
	document.getElementById("debug_1").innerHTML = menu[1];
	document.getElementById("debug_2").innerHTML = menu[2];
	document.getElementById("debug_3").innerHTML = menu[3];
	document.getElementById("debug_4").innerHTML = menu[4];

	document.getElementById("debug_5").innerHTML = hide_menu_ar[0];
	document.getElementById("debug_6").innerHTML = hide_menu_ar[1];
	document.getElementById("debug_7").innerHTML = hide_menu_ar[2];
	document.getElementById("debug_8").innerHTML = hide_menu_ar[3];
	document.getElementById("debug_9").innerHTML = hide_menu_ar[4];

	document.getElementById("debug_10").innerHTML = hide_menu_timeout[0];
	document.getElementById("debug_11").innerHTML = hide_menu_timeout[1];
	document.getElementById("debug_12").innerHTML = hide_menu_timeout[2];
	document.getElementById("debug_13").innerHTML = hide_menu_timeout[3];
	document.getElementById("debug_14").innerHTML = hide_menu_timeout[4];
	
	document.getElementById("debug_15").innerHTML = cur_menu_id;
	document.getElementById("debug_16").innerHTML = future_menu_id;
	document.getElementById("debug_17").innerHTML = menu_left_achieved;
	document.getElementById("debug_18").innerHTML = menu_width_achieved;
	document.getElementById("debug_19").innerHTML = sub_menu_move_left_achieved;
	document.getElementById("debug_20").innerHTML = sub_menu_expand_width_achieved;
	document.getElementById("debug_21").innerHTML = sub_menu_center_left_achieved;
	document.getElementById("debug_22").innerHTML = sub_menu_shrink_width_achieved;
	document.getElementById("debug_23").innerHTML = cur_main_pic_src;
	document.getElementById("debug_24").innerHTML = new_position;
	document.getElementById("debug_25").innerHTML = new_gallery_left;

	window.setTimeout("debug_print()", 10);
}

function pre_load_images() {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "pre_load_images<br/>";
	}
	if (document.images) {
		var preload_ber = new Image(16,15);
		preload_ber.src="images/menu/ber.gif";
		var preload_bel = new Image(16,15);
		preload_bel.src="images/menu/bel.gif";

		var preload_pic = new Array(totalPhotos);
		for (i=0; i<totalPhotos; i++) {
			preload_pic[i]= new Image(big_pic_width,big_pic_height);
			preload_pic[i].src="images/gallery/"+photo_src[i]+".gif";
		}
	}
}

// This will handle resizing of the browser and adjust everything accordingly
// #####################################################################
function re_size_me() {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "re_size_me<br/>";
	}
	var re_size_shift_amount = parseInt((parseInt(document.body.clientWidth/2) - parseInt(gallery_width/2)) - main_left);
	main_left = parseInt(document.body.clientWidth/2) - parseInt(gallery_width/2);
	thumbnail_left = main_left + big_pic_width + thumbnail_border_offset;

	// Setup the main logo and gallery backdrop
	// #####################################################################
	document.getElementById("logo_div").style.left = thumbnail_left;
	var logoLeft = main_left + gallery_width - gallery_border_offset + 5;
	document.getElementById("logo1").style.left = logoLeft + "px";
	document.getElementById("logo2").style.left = logoLeft + "px";

	document.getElementById("arrow_left").style.left  = (thumbnail_left - (thumbnail_border_offset/2) - 6) + "px";
	document.getElementById("arrow_right").style.left = (thumbnail_left + (cols_to_show * pic_width) + ((cols_to_show - 1) * pic_padding_horizontal) + (thumbnail_border_offset/2) - 12) + "px";
	document.getElementById("arrow_left_box").style.left  = (thumbnail_left - (thumbnail_border_offset/2) - 6) + "px";
	document.getElementById("arrow_right_box").style.left = (thumbnail_left + (cols_to_show * pic_width) + ((cols_to_show - 1) * pic_padding_horizontal) + (thumbnail_border_offset/2) - 12) + "px";

	// Setup the contact box
	// #####################################################################
	document.getElementById('contact_box').style.left = ((thumbnail_left + (pic_width + pic_padding_horizontal)*cols_to_show) - pic_padding_horizontal + gallery_border_offset - 289) + "px";
	document.getElementById('contact_box_text').style.left = parseInt(contact_box.style.left) + "px";
	document.getElementById("content").style.left = parseInt(main_left - gallery_border_offset) + "px";
	//document.getElementById("content").style.width = gallery_width + "px";
	document.getElementById("content").style.width = (gallery_width - (289 + gallery_border_offset + pic_padding_horizontal + pic_padding_horizontal)) + "px";
	document.getElementById('starburst').style.left = (parseInt(document.getElementById('contact_box').style.left) + parseInt(document.getElementById('contact_box').style.width) - 30) + "px";

	// Menu variables
	// #####################################################################
	menu_left_ar = new Array(main_left, main_left + 85 , main_left + 240, main_left + 445, main_left + 580);
	sub_menu_left_ar = new Array(0, main_left + 85, 0, main_left + 445, main_left + 215);

	// Setup the menu
	// #####################################################################
	var menu_index = 0;
	for (menu_index = 0; menu_index < num_menu; menu_index++) {
		document.getElementById('menu_' + menu_index).style.left = (menu_left_ar[menu_index] + 4) + "px";

		// Setup the sub-menu
		// #####################################################################
		if (document.getElementById('sub_menu_' + menu_index)) {
			document.getElementById('sub_menu_' + menu_index).style.left = parseInt(document.getElementById('sub_menu_' + menu_index).style.left) + re_size_shift_amount + "px";
			document.getElementById("sub_menu_" + menu_index).style.display = "none";
		}
	}

	// Setup the picture gallery
	// #####################################################################
	document.getElementById('pic_gallery_tl').style.left = (parseInt(document.getElementById('pic_gallery_tl').style.left) + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_t').style.left  = (parseInt(document.getElementById('pic_gallery_t').style.left)  + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_tr').style.left = (parseInt(document.getElementById('pic_gallery_tr').style.left) + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_l').style.left  = (parseInt(document.getElementById('pic_gallery_l').style.left)  + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_m').style.left  = (parseInt(document.getElementById('pic_gallery_m').style.left)  + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_r').style.left  = (parseInt(document.getElementById('pic_gallery_r').style.left)  + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_bl').style.left = (parseInt(document.getElementById('pic_gallery_bl').style.left) + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_b').style.left  = (parseInt(document.getElementById('pic_gallery_b').style.left)  + re_size_shift_amount) + "px";
	document.getElementById('pic_gallery_br').style.left = (parseInt(document.getElementById('pic_gallery_br').style.left) + re_size_shift_amount) + "px";

	// Setup big picture in the picture gallery
	// #####################################################################
	document.getElementById("pic_main").style.left = main_left + "px";

	// Setup small pictures in the picture gallery
	// #####################################################################
	var cur_left = thumbnail_left - (cur_gallery_col * (pic_width + pic_padding_horizontal));
	var num_pics_in_cur_col = 0;
	var num_pics_in_cur_row = 0;
	var displayType = "block";

	show_arrows();

	for (i=0; i<totalPhotos; i++) {
		var myPic      = document.getElementById(i);
		if (num_pics_in_cur_row >= cur_gallery_col && num_pics_in_cur_row < (cur_gallery_col + cols_to_show)) {
			displayType = "block";
		} else {
			displayType = "none";
		}
		myPic.style.left = cur_left;
		myPic.style.diplay = displayType;
		num_pics_in_cur_col++;
		if (num_pics_in_cur_col >= total_rows) {
			cur_left += pic_width + pic_padding_horizontal;
			num_pics_in_cur_col = 0;
			num_pics_in_cur_row++;
		}
	}

	// Send the menu back to the default
	future_menu_id == -1;
	deactivate_sub_menu(cur_menu_id);
	
	reposition_slideshow();
}

// This will just force the given menu item to start displaying
// #####################################################################
function activate_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "activate_menu<br/>";
	}
	if (menu_id != -1) {
		future_menu_id = -1;
		cur_menu_id = menu_id;
		menu_left_achieved = 0;
		menu_width_achieved = 0;
		menu[cur_menu_id] = 1;
		move_menu(cur_menu_id);
		expand_menu(cur_menu_id);
	}
}

// This will queue up a given menu item to start displaying, if
// there is nothing it has to wait for, it will call the function to
// activate the new menu item.
// #####################################################################
function move_to_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "move_to_menu<br/>";
	}
	hide_menu_ar[menu_id] = 0;
	hide_menu_timeout[menu_id] = null;
	clearTimeout(hide_menu_timeout[menu_id]);

	if (cur_menu_id != menu_id) {
		if (cur_menu_id != -1) {
			switch (menu[cur_menu_id]) {
				case 4:
				case 3:
				case 2:
					future_menu_id = menu_id;
					hide_menu_ar[cur_menu_id] = 1;
					hide_sub_menu(cur_menu_id);
					break;
				case 1:
					menu[cur_menu_id] = 0;
					activate_menu(menu_id);
					break;
				case 0:
					activate_menu(menu_id);
					break;
				case -2:
					future_menu_id = menu_id;
					break;
			}
		} else {
			activate_menu(menu_id);
		}
	} else {
		switch(menu[menu_id]) {
			case 0:
				activate_menu(menu_id);
				break;
			//case -1:
			//	menu[menu_id] = 2;
			//	break;
			case -2:
				menu[menu_id] = 2;
				
				var sub_menu = document.getElementById("sub_menu_" + menu_id);
				if (sub_menu) {
					if (sub_menu.style.display == "none") {
						activate_sub_menu(menu_id);
					} else {
						expand_sub_menu(menu_id);
					}
				} else {
					activate_sub_menu(menu_id);
				}
				break;
		}
	}
}

// Start sliding left
// #####################################################################
function slide_gallery_left() {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "slide_gallery_left<br/>";
	}
	if (cur_gallery_col > 0 && new_position > 0) {
		new_position = parseInt(new_position) - 1;
		new_gallery_left = thumbnail_left - (new_position * (pic_width + pic_padding_horizontal));
		slide_gallery();
	}
}

// Start sliding right
// #####################################################################
function slide_gallery_right() {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "slide_gallery_right<br/>";
	}
	if (cur_gallery_col < (total_cols - cols_to_show) && new_position < (total_cols - cols_to_show)) {
		new_position = parseInt(new_position) + 1;
		new_gallery_left = thumbnail_left - (new_position * (pic_width + pic_padding_horizontal));
		slide_gallery();
	}
}

// Should we show the gallery slide arrows?
// #####################################################################
function show_arrows() {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "show_arrows<br/>";
	}
	if (cur_gallery_col == 0) {
		document.getElementById("arrow_left").style.display = "none";
		document.getElementById("arrow_left_box").style.display = "none";
	} else {
		document.getElementById("arrow_left").style.display = "block";
		document.getElementById("arrow_left_box").style.display = "block";
	}
	if (cur_gallery_col >= (total_cols - cols_to_show)) {
		document.getElementById("arrow_right").style.display = "none";
		document.getElementById("arrow_right_box").style.display = "none";
	} else {
		document.getElementById("arrow_right").style.display = "block";
		document.getElementById("arrow_right_box").style.display = "block";
	}
}

function show_arrow(id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "show_arrow<br/>";
	}
	arrows_ar[id] = 1;
	var arrow_id = "arrow_right";
	if (id == 0) {
		arrow_id = "arrow_left";
	}
	document.getElementById(arrow_id).style.cursor = 'hand';
	fade_in_arrow(id);
}

function hide_arrow(id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "hide_arrow<br/>";
	}
	arrows_ar[id] = 0;
	var arrow_id = "arrow_right";
	if (id == 0) {
		arrow_id = "arrow_left";
	}
	document.getElementById(arrow_id).style.cursor = 'pointer';
	fade_out_arrow(id);
}

function fade_in_arrow(id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "fade_in_arrow<br/>";
	}
	if (arrows_ar[id] == 1) {
		var arrow_id = "arrow_right_box";
		if (id == 0) {
			arrow_id = "arrow_left_box";
		}
		if (navigator.product == 'Gecko') {
			if (document.getElementById(arrow_id).style.opacity < .75) {
				document.getElementById(arrow_id).style.opacity = parseFloat(document.getElementById(arrow_id).style.opacity) + .05;
				setTimeout("fade_in_arrow('" + id + "')", 20);
			}
		} else {
			if (document.getElementById(arrow_id).filters.alpha.opacity < 75) {
				document.getElementById(arrow_id).filters.alpha.opacity = parseFloat(document.getElementById(arrow_id).filters.alpha.opacity) + 5;
				setTimeout("fade_in_arrow('" + id + "')", 20);
			}
		}
	}
}

function fade_out_arrow(id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "fade_out_arrow<br/>";
	}
	if (arrows_ar[id] == 0) {
		var arrow_id = "arrow_right_box";
		if (id == 0) {
			arrow_id = "arrow_left_box";
		}
		if (navigator.product == 'Gecko') {
			if (document.getElementById(arrow_id).style.opacity > 0) {
				document.getElementById(arrow_id).style.opacity = parseFloat(document.getElementById(arrow_id).style.opacity) - .05;
				setTimeout("fade_out_arrow('" + id + "')", 20);
			}
		} else {
			if (document.getElementById(arrow_id).filters.alpha.opacity > 0) {
				document.getElementById(arrow_id).filters.alpha.opacity = parseFloat(document.getElementById(arrow_id).filters.alpha.opacity) - 5;
				setTimeout("fade_out_arrow('" + id + "')", 20);
			}
		}
	}
}

// Slide the gallery accordingly
// #####################################################################
function slide_gallery() {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "slide_gallery<br/>";
	}
	var cur_left = parseInt(document.getElementById("0").style.left);
	var num_pics_in_cur_col = 0;
	var num_pics_in_cur_row = 0;
	var displayType = "block";
	var show_left  = thumbnail_left - (pic_width + pic_padding_horizontal);
	var show_right = thumbnail_left + (cols_to_show * (pic_width + pic_padding_horizontal)) - pic_padding_horizontal;
	var clip_left = thumbnail_left;
	var clip_right = show_right - (pic_width + pic_padding_horizontal);
	var move_amount = parseInt((new_gallery_left - cur_left)/4);

	if (move_amount == 0 && cur_left != new_gallery_left) {
		move_amount = (new_gallery_left < cur_left) ? -1 : 1;
	}

	for (i=0; i<totalPhotos; i++) {
		var my_new_left = parseInt(document.getElementById(i).style.left) + move_amount;

		// Do we show it?
		if (my_new_left > show_left && my_new_left < show_right) {
			document.getElementById(i).style.display = "block";

			// Do we clip it?
			var need_clipping = false;
			if (my_new_left < clip_left) {
				document.getElementById(i).style.clip="rect(0px," + pic_width + "px," + pic_height + "px," + (clip_left - my_new_left) + "px)";
				need_clipping = true;
			}
			if (my_new_left > clip_right) {
				document.getElementById(i).style.clip="rect(0px," + (show_right - my_new_left) + "px," + pic_height + "px,0px)";
				need_clipping = true;
			}
			if (!need_clipping) {
				document.getElementById(i).style.clip="rect(0px," + pic_width + "px," + pic_height + "px,0px)";
			}
		} else {
			document.getElementById(i).style.display = "none";
		}
		document.getElementById(i).style.left = my_new_left + "px";
	}

	if (Math.abs(move_amount) > 0) {
		setTimeout("slide_gallery('" + new_position + "', '" + new_gallery_left + "')", 20);
	} else {
		cur_gallery_col = new_position;
		show_arrows();
	}
}

// Sets up a picture with given variables.
// #####################################################################
function setBorder(myBorder, img_id, src, img_top, img_left, img_height, img_width, z, display) {
	myBorder.setAttribute('id',img_id);
	myBorder.setAttribute('src',src);
	myBorder.setAttribute('style','border:0px;  opacity:1; filter: alpha(opacity=50);');
	myBorder.setAttribute('width',img_width);
	myBorder.setAttribute('height',img_height);
	myBorder.style.zIndex = z;
	myBorder.style.position = "absolute";
	myBorder.style.display = display;
	myBorder.style.padding = "0";
	myBorder.style.margin = "0";
	myBorder.style.top = img_top + "px";
	myBorder.style.left = img_left + "px";
	document.body.appendChild(myBorder);
}

// Sets the main picture in the gallery when a thumbnails gets hovered over.
// #####################################################################
function set_main(main_index) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "set_main<br/>";
	}

	var main_source = "images/gallery/" + photo_src[main_index] + ".gif";
	if (cur_main_pic_src != main_index) {
		var myPic_new = document.getElementById("pic_main");
		myPic_new.src = main_source;
		cur_main_pic_src = main_index;
	}
}

// Sets a timer to hide a menu
// #####################################################################
function hide_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "hide_menu<br/>";
	}
	hide_menu_ar[menu_id] = 1;
	hide_menu_timeout[menu_id] = window.setTimeout("hide_sub_menu('" + menu_id + "')", menu_close_delay);
}

// Start showing a sub-menu item
// #####################################################################
function show_sub_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "show_sub_menu<br/>";
	}
	hide_menu_timeout[menu_id] = null;
	menu[menu_id] = 3;
	fadeIn(menu_id);
	var sub_menu = document.getElementById("sub_menu_" + menu_id);
	if (sub_menu) {
		sub_menu.style.display = "block";
	}
}

// Start hiding a sub-menu item
// #####################################################################
function hide_sub_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "hide_sub_menu<br/>";
	}
	hide_menu_timeout[menu_id] = null;
	if (hide_menu_ar[menu_id] == 1) {
		hide_menu_ar[menu_id] = 0;

		if (menu_id == cur_menu_id && menu[menu_id] != -2) {
			switch(menu[menu_id]) {
				case 4:
				case 3:
				case 2:
					menu[menu_id] = -2;
					fadeOut(menu_id);
			}
		}
	}
}

// Fades in a sub-menu
// This is the last step in turning on a menu item.
// This keeps fading it in while the menu id = 1 and while it isnt fully
// shown yet.  Once it is fully shown, it changes the menu id to 2, which
// means the menu is fully activated.
// #####################################################################
function fadeIn(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "fadeIn<br/>";
	}
	if (cur_menu_id == menu_id && menu[menu_id] == 3) {
		var done_fade = 0;
		var sub_menu = document.getElementById("sub_menu_" + menu_id);
		if (sub_menu) {
			if (navigator.product == 'Gecko') {
				sub_menu.style.opacity = parseFloat(sub_menu.style.opacity) + .1;
				if (parseFloat(sub_menu.style.opacity) >= 1) {
					done_fade = 1;
				}
			}
			else {
				sub_menu.filters.alpha.opacity = sub_menu.filters.alpha.opacity + 10;
				if (sub_menu.filters.alpha.opacity >=100) {
					done_fade = 1;
				}
			}
			if (done_fade) {
				menu[menu_id] = 4;
				if (future_menu_id == -2) {
					future_menu_id = -1;
					hide_menu_ar[menu_id] = 1;
					window.setTimeout("hide_sub_menu('" + menu_id + "')", menu_close_delay);
				}
			} else {
				window.setTimeout("fadeIn('" + menu_id + "')", fadeSpeed);
			}
		}
	}
}

// Fades out a sub-menu.
// This is the first step in turning off a menu item.
// This keeps fading it out while the menu id = -2 and while it isnt fully
// invisible yet.  Once it is fully invisible, it calls the function to
// shrink and center the sub-menu.  If there is no sub-menu for this menu
// item, we simply de-activate the menu item.
// #####################################################################
function fadeOut(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "fadeOut<br/>";
	}
	if (cur_menu_id == menu_id && menu[menu_id] == -2) {
		if (future_menu_id != -1 || cur_menu_id != default_menu_id) {
			var sub_menu = document.getElementById("sub_menu_" + menu_id);
			if (sub_menu) {
				if (navigator.product == 'Gecko') {
					sub_menu.style.opacity = parseFloat(sub_menu.style.opacity) - .10;
					if (parseFloat(sub_menu.style.opacity) > 0) {
						window.setTimeout("fadeOut('" + menu_id + "')", fadeSpeed);
					} else {
						sub_menu.style.display = "none";
						shrink_sub_menu(menu_id);
					}
				}
				else {
					sub_menu.filters.alpha.opacity = sub_menu.filters.alpha.opacity - 10;
					if (sub_menu.filters.alpha.opacity > 0) {
						window.setTimeout("fadeOut('" + menu_id + "')", fadeSpeed);
					} else {
						sub_menu.style.display = "none";
						shrink_sub_menu(menu_id);
					}
				}
			} else {
				deactivate_sub_menu(menu_id);
			}
		} else {
			// We have moved off to nothing and we are the default, so we need to re-set the menu values.
			menu[menu_id] = 4;
		}
	}
}

// This function is called when we are ready to start showing a sub-menu.
// Before this is called we need to have the main menu animation completed.
// This will initialize the submenu in a centered position and start the
// sub-menu annimation to adjust the size of the sub-menu and adjust the
// position.  If there is no sub-menu, we fully hide it.
// #####################################################################
function activate_sub_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "activate_sub_menu<br/>";
	}
	if (cur_menu_id == menu_id) {
		menu[menu_id] = 2;
		// Initialize submenu position
		if (document.getElementById("sub_menu_" + menu_id)) {
			var leftpoint = menu_left_ar[menu_id];
			if (sub_menu_pos_ar[menu_id] == 2) {
				leftpoint = parseInt(document.getElementById("menu_tr").style.left) - menu_border_corner_width - 1;
			}
			document.getElementById("sub_menu_tl").style.left = leftpoint;
			document.getElementById("sub_menu_t").style.left  = leftpoint + menu_border_corner_width;
			document.getElementById("sub_menu_tr").style.left = leftpoint + menu_border_corner_width + 1;
			document.getElementById("sub_menu_l").style.left  = leftpoint;
			document.getElementById("sub_menu_m").style.left  = leftpoint + menu_border_corner_width;
			document.getElementById("sub_menu_r").style.left  = leftpoint + menu_border_corner_width + 1;
			document.getElementById("sub_menu_bl").style.left = leftpoint;
			document.getElementById("sub_menu_b").style.left  = leftpoint + menu_border_corner_width;
			document.getElementById("sub_menu_br").style.left = leftpoint + menu_border_corner_width + 1;
			sub_menu_move_left_achieved = 0;
			sub_menu_expand_width_achieved = 0;
			document.getElementById("sub_menu_t").width  = 1;
			document.getElementById("sub_menu_m").width  = 1;
			document.getElementById("sub_menu_b").width  = 1;
			document.getElementById("sub_menu_tl").style.display = "block";
			document.getElementById("sub_menu_t").style.display  = "block";
			document.getElementById("sub_menu_tr").style.display = "block";
			document.getElementById("sub_menu_l").style.display  = "block";
			document.getElementById("sub_menu_m").style.display  = "block";
			document.getElementById("sub_menu_r").style.display  = "block";
			document.getElementById("sub_menu_bl").style.display = "block";
			document.getElementById("sub_menu_b").style.display  = "block";
			document.getElementById("sub_menu_br").style.display = "block";
			document.getElementById("sub_menu_tl").style.zIndex = 3;
			document.getElementById("sub_menu_t").setAttribute('src',"images/menu/m.gif");
			document.getElementById("sub_menu_t").style.zIndex  = 3;
			document.getElementById("sub_menu_tr").style.zIndex = 3;
			if (sub_menu_pos_ar[menu_id] == 1) {
				document.getElementById("menu_bl").setAttribute('src',"images/menu/l.gif");
				document.getElementById("sub_menu_tl").setAttribute('src',"images/menu/l.gif");
			}
			if (sub_menu_pos_ar[menu_id] == 2) {
				document.getElementById("menu_br").setAttribute('src',"images/menu/r.gif");
				document.getElementById("sub_menu_tr").setAttribute('src',"images/menu/r.gif");
			}
			expand_sub_menu(menu_id);
		} else {
			document.getElementById("sub_menu_tl").style.display = "none";
			document.getElementById("sub_menu_t").style.display  = "none";
			document.getElementById("sub_menu_tr").style.display = "none";
			document.getElementById("sub_menu_l").style.display  = "none";
			document.getElementById("sub_menu_m").style.display  = "none";
			document.getElementById("sub_menu_r").style.display  = "none";
			document.getElementById("sub_menu_bl").style.display = "none";
			document.getElementById("sub_menu_b").style.display  = "none";
			document.getElementById("sub_menu_br").style.display = "none";
			menu[menu_id] = 4;
			if (future_menu_id == -2) {
				future_menu_id = -1;
				hide_menu_ar[menu_id] = 1;
				window.setTimeout("hide_sub_menu('" + menu_id + "')", menu_close_delay);
			}
			clearTimeout(hide_menu_timeout[menu_id]);
		}
	}
}

// Turn off a sub-menu
// We status that the menu is fully off.
// We fully hide the sub-menu.
// This will be called when we are done centering and shrinking the sub-menu.
// Once this is done, we have effectively turned off a menu item, although
// it is still selected by the box in the main menu.
// Now that we are fully done, lets see if another menu item was waiting
// in the queue.  If there was one, lets activate that menu item.
// #####################################################################
function deactivate_sub_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "deactivate_sub_menu<br/>";
	}
	document.getElementById("sub_menu_tl").style.display = "none";
	document.getElementById("sub_menu_t").style.display  = "none";
	document.getElementById("sub_menu_tr").style.display = "none";
	document.getElementById("sub_menu_l").style.display  = "none";
	document.getElementById("sub_menu_m").style.display  = "none";
	document.getElementById("sub_menu_r").style.display  = "none";
	document.getElementById("sub_menu_bl").style.display = "none";
	document.getElementById("sub_menu_b").style.display  = "none";
	document.getElementById("sub_menu_br").style.display = "none";

	document.getElementById("menu_bl").setAttribute('src',"images/menu/bl.gif");
	document.getElementById("menu_b").setAttribute('src',"images/menu/b.gif");
	document.getElementById("menu_br").setAttribute('src',"images/menu/br.gif");
	document.getElementById("menu_b").width  = parseInt(document.getElementById("menu_t").width);
	document.getElementById("menu_bl").style.left = parseInt(document.getElementById("menu_tl").style.left) + "px";
	document.getElementById("menu_b").style.left  = parseInt(document.getElementById("menu_t").style.left) + "px";
	document.getElementById("menu_br").style.left = parseInt(document.getElementById("menu_tr").style.left) + "px";

	menu[menu_id] = 0;

	// If nothing else, just go back to home
	if (future_menu_id == -1) {
		future_menu_id = default_menu_id;
	}
	activate_menu(future_menu_id);
}

// This will move the horizontal position of a menu to the desired location.
// #####################################################################
function move_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "move_menu<br/>";
	}
	if (cur_menu_id == menu_id && menu[menu_id] == 1) {
		var target_left = menu_left_ar[menu_id];

		var move_amount = ((target_left) - parseInt(document.getElementById("menu_tl").style.left))/move_speed;
		if (parseInt(move_amount) == 0) {
			move_amount = ((target_left) - parseInt(document.getElementById("menu_tl").style.left));
		}

		document.getElementById("menu_tl").style.left = (parseInt(document.getElementById("menu_tl").style.left) + parseInt(move_amount)) + "px";
		document.getElementById("menu_t").style.left  = (parseInt(document.getElementById("menu_t").style.left)  + parseInt(move_amount)) + "px";
		document.getElementById("menu_tr").style.left = (parseInt(document.getElementById("menu_tr").style.left) + parseInt(move_amount)) + "px";
		document.getElementById("menu_l").style.left  = (parseInt(document.getElementById("menu_l").style.left)  + parseInt(move_amount)) + "px";
		document.getElementById("menu_m").style.left  = (parseInt(document.getElementById("menu_m").style.left)  + parseInt(move_amount)) + "px";
		document.getElementById("menu_r").style.left  = (parseInt(document.getElementById("menu_r").style.left)  + parseInt(move_amount)) + "px";
		document.getElementById("menu_bl").style.left = (parseInt(document.getElementById("menu_bl").style.left) + parseInt(move_amount)) + "px";
		document.getElementById("menu_b").style.left  = (parseInt(document.getElementById("menu_b").style.left)  + parseInt(move_amount)) + "px";
		document.getElementById("menu_br").style.left = (parseInt(document.getElementById("menu_br").style.left) + parseInt(move_amount)) + "px";

		if (parseInt(document.getElementById("menu_tl").style.left) != target_left) {
			setTimeout("move_menu('" + menu_id + "')", 20);
		} else {
			menu_left_achieved = 1;
			if (menu_width_achieved == 1) {
				activate_sub_menu(menu_id);
			}
		}
	}
}

// This will expand or contract the horizontal size of a menu to the desired width.
// #####################################################################
function expand_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "expand_menu<br/>";
	}
	if (cur_menu_id == menu_id && menu[menu_id] == 1) {
		var target_width = menu_width_ar[menu_id] + (2*menu_border_offset_width) - (2*menu_border_corner_width);

		var grow_amount = ((target_width) - parseInt(document.getElementById("menu_t").width))/grow_speed;
		if (parseInt(grow_amount) == 0) {
			grow_amount = ((target_width) - parseInt(document.getElementById("menu_t").width));
		}

		document.getElementById("menu_t").width  = (parseInt(document.getElementById("menu_t").width)  + grow_amount);
		document.getElementById("menu_m").width  = (parseInt(document.getElementById("menu_m").width)  + grow_amount);
		document.getElementById("menu_b").width  = (parseInt(document.getElementById("menu_b").width)  + grow_amount);

		document.getElementById("menu_tr").style.left = (parseInt(document.getElementById("menu_tr").style.left) + grow_amount) + "px";
		document.getElementById("menu_r").style.left  = (parseInt(document.getElementById("menu_r").style.left)  + grow_amount) + "px";
		document.getElementById("menu_br").style.left = (parseInt(document.getElementById("menu_br").style.left) + grow_amount) + "px";

		if (parseInt(document.getElementById("menu_t").width) != target_width) {
			setTimeout("expand_menu('" + menu_id + "')", 20);
		} else {
			menu_width_achieved = 1;
			if (menu_left_achieved == 1) {
				activate_sub_menu(menu_id);
			}
		}
	}
}


// This will expand or contract the horizontal size of a sub-menu to the desired width.
// #####################################################################
function expand_sub_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "expand_sub_menu<br/>";
	}
	if (cur_menu_id == menu_id && menu[menu_id] == 2) {
		var target_width = sub_menu_width_ar[menu_id] + (2*menu_border_offset_width) - (2*menu_border_corner_width);
		var orig_grow_amount = parseInt(((target_width) - parseInt(document.getElementById("sub_menu_t").width))/grow_speed);
		var grow_amount = orig_grow_amount;
		if (parseInt(grow_amount) == 0) {
			grow_amount = 1;
		}

		document.getElementById("sub_menu_t").width = parseInt(parseInt(document.getElementById("sub_menu_t").width) + grow_amount);
		document.getElementById("sub_menu_m").width = parseInt(parseInt(document.getElementById("sub_menu_m").width) + grow_amount);
		document.getElementById("sub_menu_b").width = parseInt(parseInt(document.getElementById("sub_menu_b").width) + grow_amount);

		if (sub_menu_pos_ar[menu_id] == 1) {
			document.getElementById("sub_menu_tr").style.left = parseInt(parseInt(document.getElementById("sub_menu_tr").style.left) + grow_amount) + "px";
			document.getElementById("sub_menu_r").style.left  = parseInt(parseInt(document.getElementById("sub_menu_r").style.left)  + grow_amount) + "px";
			document.getElementById("sub_menu_br").style.left = parseInt(parseInt(document.getElementById("sub_menu_br").style.left) + grow_amount) + "px";
		}
		if (sub_menu_pos_ar[menu_id] == 2) {
			document.getElementById("sub_menu_tl").style.left = parseInt(parseInt(document.getElementById("sub_menu_tl").style.left) - grow_amount) + "px";
			document.getElementById("sub_menu_l").style.left  = parseInt(parseInt(document.getElementById("sub_menu_l").style.left)  - grow_amount) + "px";
			document.getElementById("sub_menu_bl").style.left = parseInt(parseInt(document.getElementById("sub_menu_bl").style.left) - grow_amount) + "px";
			document.getElementById("sub_menu_t").style.left  = parseInt(parseInt(document.getElementById("sub_menu_t").style.left)  - grow_amount) + "px";
			document.getElementById("sub_menu_m").style.left  = parseInt(parseInt(document.getElementById("sub_menu_m").style.left)  - grow_amount) + "px";
			document.getElementById("sub_menu_b").style.left  = parseInt(parseInt(document.getElementById("sub_menu_b").style.left)  - grow_amount) + "px";
		}

		if (sub_menu_pos_ar[menu_id] == 1) {
			if (parseInt(document.getElementById("sub_menu_tr").style.left) >= (parseInt(document.getElementById("menu_tr").style.left) - menu_border_corner_width) &&
				parseInt(document.getElementById("sub_menu_tr").style.left) < (parseInt(document.getElementById("menu_tr").style.left) + menu_border_corner_width)) {
				document.getElementById("sub_menu_tr").setAttribute('src',"images/menu/r.gif");
				document.getElementById("menu_br").setAttribute('src',"images/menu/r.gif");
			} else {
				if (parseInt(document.getElementById("sub_menu_tr").style.left) > (parseInt(document.getElementById("menu_tr").style.left) + menu_border_corner_width)) {
					if (document.getElementById("menu_br").getAttribute('src').match("images/menu/ber.gif") == null) {
						document.getElementById("menu_br").style.left = parseInt(document.getElementById("menu_tr").style.left) + menu_border_corner_width;
						document.getElementById("menu_b").width = (parseInt(document.getElementById("menu_t").width) + parseInt(menu_border_corner_width));
						document.getElementById("sub_menu_tr").setAttribute('src',"images/menu/tr.gif");
						document.getElementById("menu_b").setAttribute('src',"images/menu/m.gif");
						document.getElementById("menu_br").setAttribute('src',"images/menu/ber.gif");
						document.getElementById("menu_b").style.zIndex = 3;
						document.getElementById("sub_menu_t").style.zIndex = 2;
						document.getElementById("sub_menu_t").setAttribute('src',"images/menu/t.gif");
					}
				}
			}
		}
		if (sub_menu_pos_ar[menu_id] == 2) {
			if (parseInt(document.getElementById("sub_menu_tl").style.left) <= (parseInt(document.getElementById("menu_tl").style.left) + menu_border_corner_width) &&
				parseInt(document.getElementById("sub_menu_tl").style.left) > (parseInt(document.getElementById("menu_tl").style.left) - menu_border_corner_width)) {
				document.getElementById("sub_menu_tl").setAttribute('src',"images/menu/l.gif");
				document.getElementById("menu_bl").setAttribute('src',"images/menu/l.gif");
			} else {
				if (parseInt(document.getElementById("sub_menu_tl").style.left) < (parseInt(document.getElementById("menu_tl").style.left) - menu_border_corner_width)) {
					if (document.getElementById("menu_bl").getAttribute('src').match("images/menu/bel.gif") == null) {
						document.getElementById("menu_bl").style.left = parseInt(document.getElementById("menu_bl").style.left) - menu_border_corner_width;
						document.getElementById("menu_b").style.left = parseInt(document.getElementById("menu_b").style.left) - menu_border_corner_width;
						document.getElementById("menu_b").width = (parseInt(document.getElementById("menu_t").width) + parseInt(menu_border_corner_width));
						document.getElementById("sub_menu_tl").setAttribute('src',"images/menu/tl.gif");
						document.getElementById("menu_bl").setAttribute('src',"images/menu/bel.gif");
						document.getElementById("menu_b").setAttribute('src',"images/menu/m.gif");
						document.getElementById("menu_b").style.zIndex = 3;
						document.getElementById("sub_menu_t").style.zIndex = 2;
						document.getElementById("sub_menu_t").setAttribute('src',"images/menu/t.gif");
					}
				}
			}
		}

		if (parseInt(document.getElementById("sub_menu_t").width) != target_width) {
			setTimeout("expand_sub_menu('" + menu_id + "')", 20);
		} else {
			show_sub_menu(menu_id);
		}
	}
}




// This will contract the horizontal size of a sub-menu down to 1.
// #####################################################################
function shrink_sub_menu(menu_id) {
	if (debug == 1) {
		document.getElementById("call_trace").innerHTML += "shrink_sub_menu<br/>";
	}
	if (cur_menu_id == menu_id && menu[menu_id] == -2) {
		var target_width = 1;
		var grow_amount = parseInt(((target_width) - parseInt(document.getElementById("sub_menu_t").width))/shrink_speed);
		if (grow_amount == 0) {
			grow_amount = -1;
		}

		document.getElementById("sub_menu_t").width = (parseInt(document.getElementById("sub_menu_t").width)  + grow_amount);
		document.getElementById("sub_menu_m").width = (parseInt(document.getElementById("sub_menu_m").width)  + grow_amount);
		document.getElementById("sub_menu_b").width = (parseInt(document.getElementById("sub_menu_b").width)  + grow_amount);

		if (sub_menu_pos_ar[menu_id] == 1) {
			document.getElementById("sub_menu_tr").style.left = (parseInt(document.getElementById("sub_menu_tr").style.left) + grow_amount) + "px";
			document.getElementById("sub_menu_r").style.left  = (parseInt(document.getElementById("sub_menu_r").style.left)  + grow_amount) + "px";
			document.getElementById("sub_menu_br").style.left = (parseInt(document.getElementById("sub_menu_br").style.left) + grow_amount) + "px";
		}
		if (sub_menu_pos_ar[menu_id] == 2) {
			document.getElementById("sub_menu_tl").style.left = (parseInt(document.getElementById("sub_menu_tl").style.left) - grow_amount) + "px";
			document.getElementById("sub_menu_l").style.left  = (parseInt(document.getElementById("sub_menu_l").style.left)  - grow_amount) + "px";
			document.getElementById("sub_menu_bl").style.left = (parseInt(document.getElementById("sub_menu_bl").style.left) - grow_amount) + "px";
			document.getElementById("sub_menu_t").style.left  = (parseInt(document.getElementById("sub_menu_t").style.left)  - grow_amount) + "px";
			document.getElementById("sub_menu_m").style.left  = (parseInt(document.getElementById("sub_menu_m").style.left)  - grow_amount) + "px";
			document.getElementById("sub_menu_b").style.left  = (parseInt(document.getElementById("sub_menu_b").style.left)  - grow_amount) + "px";
		}

		if (sub_menu_pos_ar[menu_id] == 1) {
			if (parseInt(document.getElementById("sub_menu_tr").style.left) >= (parseInt(document.getElementById("menu_tr").style.left) - menu_border_corner_width) &&
				parseInt(document.getElementById("sub_menu_tr").style.left) < (parseInt(document.getElementById("menu_tr").style.left) + menu_border_corner_width)) {
				if (document.getElementById("menu_br").getAttribute('src').match("images/menu/r.gif") == null) {
					document.getElementById("sub_menu_tr").setAttribute('src',"images/menu/r.gif");
					document.getElementById("menu_br").setAttribute('src',"images/menu/r.gif");
					document.getElementById("menu_br").style.left = parseInt(document.getElementById("menu_tr").style.left);
					document.getElementById("menu_b").width = parseInt(document.getElementById("menu_t").width);
				}
			} else {
				if (parseInt(document.getElementById("sub_menu_tr").style.left) < parseInt(document.getElementById("menu_tr").style.left)) {
					if (document.getElementById("menu_br").getAttribute('src').match("images/menu/br.gif") == null) {
						if (document.getElementById("menu_br").getAttribute('src').match("images/menu/r.gif") == null) {
							document.getElementById("menu_br").style.left = parseInt(document.getElementById("menu_tr").style.left);
							document.getElementById("menu_b").width = parseInt(document.getElementById("menu_t").width);
						}
						document.getElementById("menu_b").setAttribute('src',"images/menu/b.gif");
						document.getElementById("menu_br").setAttribute('src',"images/menu/br.gif");
						document.getElementById("sub_menu_tr").setAttribute('src',"images/menu/r.gif");
						document.getElementById("sub_menu_t").setAttribute('src',"images/menu/m.gif");
						document.getElementById("menu_b").style.zIndex = 2;
						document.getElementById("sub_menu_t").style.zIndex = 3;
					}
				}
			}
		}

		if (sub_menu_pos_ar[menu_id] == 2) {
			if (parseInt(document.getElementById("sub_menu_tl").style.left) <= (parseInt(document.getElementById("menu_tl").style.left) + menu_border_corner_width) &&
				parseInt(document.getElementById("sub_menu_tl").style.left) > (parseInt(document.getElementById("menu_tl").style.left) - menu_border_corner_width)) {
				if (document.getElementById("menu_bl").getAttribute('src').match("images/menu/l.gif") == null) {
					document.getElementById("sub_menu_tl").setAttribute('src',"images/menu/l.gif");
					document.getElementById("menu_bl").setAttribute('src',"images/menu/l.gif");
					document.getElementById("menu_bl").style.left = parseInt(document.getElementById("menu_bl").style.left) + menu_border_corner_width;
					document.getElementById("menu_b").style.left = parseInt(document.getElementById("menu_b").style.left) + menu_border_corner_width;
					document.getElementById("menu_b").width = parseInt(document.getElementById("menu_t").width);
				}
			} else {
				if (parseInt(document.getElementById("sub_menu_tl").style.left) > parseInt(document.getElementById("menu_tl").style.left)) {
					if (document.getElementById("menu_bl").getAttribute('src').match("images/menu/bl.gif") == null) {
						if (document.getElementById("menu_bl").getAttribute('src').match("images/menu/l.gif") == null) {
							document.getElementById("menu_bl").style.left = parseInt(document.getElementById("menu_bl").style.left) + menu_border_corner_width;
							document.getElementById("menu_b").style.left = parseInt(document.getElementById("menu_t").style.left);
							document.getElementById("menu_b").width = parseInt(document.getElementById("menu_t").width);
						}
						document.getElementById("menu_b").setAttribute('src',"images/menu/b.gif");
						document.getElementById("menu_bl").setAttribute('src',"images/menu/bl.gif");
						document.getElementById("sub_menu_tl").setAttribute('src',"images/menu/l.gif");
						document.getElementById("sub_menu_t").setAttribute('src',"images/menu/m.gif");
						document.getElementById("menu_b").style.zIndex = 2;
						document.getElementById("sub_menu_t").style.zIndex = 3;
					}
				}
			}
		}

		if (parseInt(document.getElementById("sub_menu_t").width) != target_width) {
			setTimeout("shrink_sub_menu('" + menu_id + "')", 20);
		} else {
			deactivate_sub_menu(menu_id);
		}
	}
}


// Slideshow functions
// ################################################
function calculatePositions_slideshow() {
	leftPixel = 0;
	topPixel = 0;

	document.getElementById("slideshow_container").style.left = parseInt(document.getElementById('contact_box').style.left) + (parseInt(document.getElementById('contact_box').style.width) - imageWidth)/2 + "px";
	document.getElementById("slideshow_container").style.top = parseInt(document.getElementById('contact_box').style.top) + parseInt(document.getElementById('contact_box').style.height) +  padding_above_slideshow + "px";
	
	document.getElementById("slideshow_image_0").style.left = leftPixel + "px";
	document.getElementById("slideshow_image_1").style.left = leftPixel + "px";
	document.getElementById("slideshow_text").style.left = leftPixel + "px";

	document.getElementById("slideshow_image_0").style.top = topPixel + "px";
	document.getElementById("slideshow_image_1").style.top = topPixel + "px";
	document.getElementById("slideshow_text").style.top = ((parseInt(topPixel)+parseInt(imageHeight)) + 3) + "px";
	
	document.getElementById("slideshow_image_0").style.width = imageWidth + "px";
	document.getElementById("slideshow_image_1").style.width = imageWidth + "px";
	document.getElementById("slideshow_text").style.width = (imageWidth - 4) + "px";
	
	document.getElementById("slideshow_image_0").style.height = imageHeight + "px";
	document.getElementById("slideshow_image_1").style.height = imageHeight + "px";
	document.getElementById("slideshow_text").style.height = CaptionHeight + "px";
	
	// Create the slideshow markers
	var marker_left = (imageWidth - (totalPhotos_slideshow * 6) - ((totalPhotos_slideshow - 1)*2))/2;
	for (var i=0; i < totalPhotos_slideshow; i++) {
		var slideshow_marker = document.createElement('img');
		slideshow_marker.setAttribute('id','slideshow_marker_' + i);
		slideshow_marker.setAttribute('src','images/slideshow/marker.jpg');
		slideshow_marker.style.zIndex = 1;
		slideshow_marker.style.position = "absolute";
		slideshow_marker.style.display = "block";
		slideshow_marker.style.padding = "0";
		slideshow_marker.style.margin = "0";
		slideshow_marker.style.border = "solid 1px black";
		slideshow_marker.style.width = "4";
		slideshow_marker.style.height = "5";
		slideshow_marker.style.top = (imageHeight + CaptionHeight + 10) + "px";
		slideshow_marker.style.left = marker_left + (i * 8) + " px";
		
		slideshow_marker.onmouseover = function () {this.style.cursor="hand";};
		slideshow_marker.onclick = new Function ('move_to_slideshow(' + i + ')');
		
		document.getElementById("slideshow_container").appendChild(slideshow_marker);
	}
	
	document.getElementById("slideshow_marker_0").style.height = "11px";
	document.getElementById("slideshow_marker_0").style.top = (imageHeight + CaptionHeight + 7) + "px";
}

function reposition_slideshow() {
	document.getElementById("slideshow_container").style.left = parseInt(document.getElementById('contact_box').style.left) + (parseInt(document.getElementById('contact_box').style.width) - imageWidth)/2 + "px";
}

function move_to_slideshow(pic) {
	document.getElementById("play_slideshow").style.display = "none";
	if (slideshow_fading == 1) {
		force_move_slideshow = pic;
		slideshow_fadeSpeed_bak = slideshow_fadeSpeed;
		slideshow_fadeAmount_bak = slideshow_fadeAmount;
		slideshow_fadeSpeed = 10;
		slideshow_fadeAmount = 10;
	} else {
		clearTimeout(slideshow_timer);
		clearTimeout(slideshow_timer_marker);
		currentPhoto = pic;
		document.getElementById("slideshow_image_"+current_slide_position).src = photo[currentPhoto];
		force_move_slideshow = -1;
		advance_slideshow();
	}
}

function prepare_slideshow() {
	document.getElementById("slideshow_image_"+current_slide_position).src = photo[currentPhoto];
	document.getElementById("slideshow_text").innerHTML = photoCaption[currentPhoto];
	calculatePositions_slideshow();
	getNextPicture();
	
	var play_button = document.createElement('img');
	play_button.setAttribute('id','play_slideshow');
	play_button.setAttribute('src','images/SlideShow/play.gif');
	play_button.style.zIndex = 1;
	play_button.style.position = "absolute";
	play_button.style.display = "block";
	play_button.style.padding = "0";
	play_button.style.margin = "0";
	play_button.style.top = "0px";
	play_button.style.left = "0px";
	play_button.onmouseover = function () {this.style.cursor="hand";};
	play_button.onclick = function () {start_slideshow();};
	document.getElementById("slideshow_container").appendChild(play_button);
}

function start_slideshow() {
	document.getElementById("play_slideshow").style.display = "none";
	slideshow_timer = window.setTimeout("advance_slideshow()", initialWait);
}

function advance_slideshow() {
	fade_marker();
	fade_slideshow();
}

function fade_marker() {
	var keep_adjusting_marker = 0;
	if (parseInt(document.getElementById("slideshow_marker_"+currentPhoto).style.height) < 11) {
		document.getElementById("slideshow_marker_"+currentPhoto).style.height = parseFloat(document.getElementById("slideshow_marker_"+currentPhoto).style.height) + 2 + "px";
		document.getElementById("slideshow_marker_"+currentPhoto).style.top = parseFloat(document.getElementById("slideshow_marker_"+currentPhoto).style.top) - 1 + "px";
		keep_adjusting_marker = 1;
	}
	if (parseInt(document.getElementById("slideshow_marker_"+lastPhoto).style.height) > 5) {
		document.getElementById("slideshow_marker_"+lastPhoto).style.height = parseFloat(document.getElementById("slideshow_marker_"+lastPhoto).style.height) - 2 + "px";
		document.getElementById("slideshow_marker_"+lastPhoto).style.top = parseFloat(document.getElementById("slideshow_marker_"+lastPhoto).style.top) + 1 + "px";
		keep_adjusting_marker = 1;
	}
	if (keep_adjusting_marker == 1) {
		slideshow_timer_marker = window.setTimeout("fade_marker()", slideshow_fadeSpeed);
	}
}

function fade_slideshow() {
	slideshow_fading = 1;
	var picB = (current_slide_position == 0) ? 1 : 0;
	if (navigator.product == 'Gecko') { 
		document.getElementById("slideshow_image_"+current_slide_position).style.opacity = parseFloat(document.getElementById("slideshow_image_"+current_slide_position).style.opacity) + slideshow_fadeAmount / 100.0;
		document.getElementById("slideshow_image_"+picB).style.opacity = parseFloat(document.getElementById("slideshow_image_"+picB).style.opacity) - slideshow_fadeAmount / 100.0;

		if (parseFloat(document.getElementById("slideshow_image_"+picB).style.opacity) > 0) {
			window.setTimeout("fade_slideshow(" + current_slide_position + ")", slideshow_fadeSpeed);
			if (parseFloat(document.getElementById("slideshow_image_"+current_slide_position).style.opacity) >= (show_caption_at/100.0)) {
				document.getElementById("slideshow_text").innerHTML = photoCaption[currentPhoto];
			}
		}
		else {
			if (force_move_slideshow == -1) {
				getNextPicture(picB);
				slideshow_timer = window.setTimeout("advance_slideshow()", (currentPhoto == 0) ? time_at_end : timeOnPhoto);
				slideshow_fading = 0;
			} else {
				slideshow_fading = 0;
				getNextPicture(picB);
				move_to_slideshow(force_move_slideshow);
				if (slideshow_fadeSpeed != slideshow_fadeSpeed_bak) {
					slideshow_fadeSpeed = slideshow_fadeSpeed_bak;
					slideshow_fadeAmount = slideshow_fadeAmount_bak;
				}
			}
		}
	}
	else {
		document.getElementById("slideshow_image_"+current_slide_position).filters.alpha.opacity = parseInt(document.getElementById("slideshow_image_"+current_slide_position).filters.alpha.opacity) + slideshow_fadeAmount;
		document.getElementById("slideshow_image_"+picB).filters.alpha.opacity = parseInt(document.getElementById("slideshow_image_"+picB).filters.alpha.opacity) - slideshow_fadeAmount;
	
		if (parseInt(document.getElementById("slideshow_image_"+picB).filters.alpha.opacity) > 0) {
			window.setTimeout("fade_slideshow(" + current_slide_position + ")", slideshow_fadeSpeed);
			if (parseInt(document.getElementById("slideshow_image_"+current_slide_position).filters.alpha.opacity) >= show_caption_at) {
				document.getElementById("slideshow_text").innerHTML = photoCaption[currentPhoto];
			}
		}
		else {
			if (force_move_slideshow == -1) {
				getNextPicture(picB);
				slideshow_timer = window.setTimeout("advance_slideshow()", (currentPhoto == 0) ? time_at_end : timeOnPhoto);
				slideshow_fading = 0;
			} else {
				slideshow_fading = 0;
				getNextPicture(picB);
				move_to_slideshow(force_move_slideshow);
				if (slideshow_fadeSpeed != slideshow_fadeSpeed_bak) {
					slideshow_fadeSpeed = slideshow_fadeSpeed_bak;
					slideshow_fadeAmount = slideshow_fadeAmount_bak;
				}
			}
		}
	}
}

function incrPhoto() {
	lastPhoto = currentPhoto;
	currentPhoto = currentPhoto + 1;
	if (currentPhoto >= totalPhotos_slideshow) {
		currentPhoto = 0;
	}
}

function getNextPicture() {
	incrPhoto();
	current_slide_position = (current_slide_position == 0) ? 1 : 0;
	document.getElementById("slideshow_image_"+current_slide_position).src = photo[currentPhoto];
}
