// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var tid; //timer for automatic timed slide switching
var position = 0; //what slide position are we on?
var media = new Array(); //hold all available slides as div id's

function change_page(showindex){
//change our page number
	position = showindex;
	document.cookie = 'slideShowPosition='+position+';path=/';
	window.location.reload();
}
function set_marker(marker){
//show or hide the indicator for whether or not we are automatically switching slides
/*
	if(ie4){
		document.all['slideindicator'].innerHTML = marker;
	}
	else if(nn4){
		document['slideindicator'].document['slideindicator'].innerHTML = marker;
	}
	else if(dom){
		document.getElementById('slideindicator').innerHTML = marker;
	}
*/
}
function resume_slide_show(){
	start_slide_show();
	switch_media('next', 1);
}
function start_slide_show(){
//start automatic slide switching
	stop_slide_show();
	tid = setInterval('switcher()', 16000);
	document.cookie = 'slideShowPlay=True;path=/';
	set_marker('playing slideshow...&nbsp;&nbsp;&nbsp;');
}
function stop_slide_show(){
//stop automatic slide switching
	clearInterval(tid);
	document.cookie = 'slideShowPlay=;path=/';
	set_marker('');
}
function switcher(){
//called by start_slide_show during automatic slide switching
	var next_pos = position + 1;
	if(position >= media.length - 1){
		next_pos = 0;
	}
	change_page(next_pos);
}
function switch_media(direction, continue_playing){
//called when we click prev/next links
	if(!continue_playing){
		stop_slide_show();
	}
	var next_pos;
	if(direction == 'prev'){
		next_pos = position - 1;
		if(position <= 0){
			next_pos = media.length - 1;
		}
	}
	else{
		next_pos = position + 1;
		if(position >= media.length - 1){
			next_pos = 0;
		}
	}
	change_page(next_pos);
}
function am_playing(){
//if cookie says we are playing slide show, "start" it again
//this needs to be called after onLoad has loaded the page so we can reference the div element 
//that displays whether we are auto-playing
	if(document.cookie.match(/slideShowPlay/)){
		if(document.cookie.match(/slideShowPlay=True/) != null) start_slide_show();
	}
	else{
		start_slide_show();
	}
}
