var slides_count = 0;
var slide_current;
var slide_auto=false;
var slide_auto_time = 8000;
function build_slide_show() {
	while (document.getElementById('slide_'+slides_count)) {
		slides_count++;
	}
	
	if (slides_count > 0) {
		$("#slide_0").show();
		slide_current=0;
		build_slide_show_menu();
		if (slide_auto) {
			setTimeout("slide_auto_change();",slide_auto_time);
		}
	}
}

function build_slide_show_menu() {
	var nav_html = '<table align="right" border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse"><tr>';
	for (i=0;i<slides_count;i++) {
		if (i == slide_current) {
			nav_html += '<td style="border:1px #000 solid; background-color:#000;" width="8px" height="8px"></td><td width="3px" height="8px"></td>';
		} else {
			nav_html += '<td style="border:1px #000 solid; cursor:pointer;" width="8px" height="8px" onclick="slide_select('+i+');"></td><td width="3px" height="8px"></td>';
		}
	}
	nav_html += '</tr></table>';
	
	$("#slide_nav").html(nav_html);
}

function slide_next() {
	slide_select(slide_current + 1);
}

function slide_previous() {
	slide_select(slide_current + 1);
}

function slide_select(slide_num) {
	if (slide_num + 1 <= slides_count) {
		$("#slide_"+slide_current).fadeOut(400, function() {
			slide_current = slide_num;
			$("#slide_"+slide_current).fadeIn();
			build_slide_show_menu();
		});
	} else {
		slide_num = 0;
		$("#slide_"+slide_current).fadeOut(400, function() {
			slide_current = slide_num;
			$("#slide_"+slide_current).fadeIn();
			build_slide_show_menu();
		});
	}
}

function slide_auto_change() {
	slide_next();
	setTimeout("slide_auto_change();",slide_auto_time);
}
