//***************************
//******  slideshow functions
//***************************
// 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?

function slideshow(){
//instantiate new slideshow object
//call like: var theshow = new slideshow('div_id',1);
//where 'div_id' is the name of the prefix given to the divs that this slide show controls
//and 1 is the number of elements that need to be shown/hidden each time the slides advance
//can also call like: var theshow = new slideshow('div_id',1,'id5','id6','id7');
//where the last three elements are the div id's to be shown/hidden
	this.tid;
	this.position = 0;
	var items = slideshow.arguments.length;
	if(items < 2) return;
	this.div_id = slideshow.arguments[0];
	this.sub_elements = slideshow.arguments[1];
	this.media = new Array();
	for(var i=2; i<items; i++){
		this.media.push(slideshow.arguments[i]);
	}
	this.set_marker = set_marker;
	this.show_hide = show_hide;
	this.start_slide_show = start_slide_show;
	this.stop_slide_show = stop_slide_show;
	this.switch_media = switch_media;
	this.switcher = switcher;
}
function show_hide(showindex, hideindex){
//show/hide div elements
	this.position = showindex;
	var show = this.div_id+'.'+this.media[showindex];
	var hide = this.div_id+'.'+this.media[hideindex];
	//show or hide each sub-element of this div
	for(var i=1; i<=this.sub_elements; i++){
		var sub = (i == 1) ? '' : ('.sub'+i);
		if(ie4){
			document.all[show+sub].style.display='block';
			document.all[hide+sub].style.display='none';
			//document.all['currentpage'].innerHTML = this.position + 1;
		}
		else if(nn4){
			document[show+sub].document[show+sub].style.display='block';
			document[hide+sub].document[hide+sub].style.display='none';
			//document['currentpage'].document['currentpage'].innerHTML = this.position + 1;
		}
		else if(dom){
			document.getElementById(show+sub).style.display='block';
			document.getElementById(hide+sub).style.display='none';
			//document.getElementById('currentpage').innerHTML = this.position + 1;
		}
	}
}
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 start_slide_show(){
//start automatic slide switching
	this.stop_slide_show();
	var myself = this;
	function callMethod() {
		myself.switcher();
	}
	this.tid = setInterval(callMethod, 5000);
	this.set_marker('playing slideshow...');
}
function stop_slide_show(){
//stop automatic slide switching
	clearInterval(this.tid);
	this.set_marker('');
}
function switcher(){
//called by start_slide_show during automatic slide switching
	var next_pos = this.position + 1;
	if(this.position >= this.media.length - 1){
		next_pos = 0;
	}
	this.show_hide(next_pos, this.position);
}
function switch_media(direction){
//called when we click prev/next links
	this.stop_slide_show();
	if(direction == 'prev'){
		if(this.position > 0) {
			this.show_hide(this.position-1, this.position);
		} else {
			this.show_hide(this.media.length-1, 0);
		}
	}
	else{
		if (this.position < this.media.length - 1) {
			this.show_hide(this.position+1, this.position);
		} else {
			this.show_hide(0, this.position);
		}
	}
}

