/*****************************************************************************

	SLIDESHOW.JS
	Code to manage addtional interaction on the slideshow pages. 
	06/08 - Timothy Krukowski for Primum Marketing Communications & gMed. Inc.

 *****************************************************************************/ 

//Slideshow info
var gGastroSlideshow = [];
gGastroSlideshow[0] = 'First Visit';
gGastroSlideshow[1] = 'My Activities';
gGastroSlideshow[2] = 'Lab Report';
gGastroSlideshow[3] = 'Colonoscopy';
gGastroSlideshow[4] = 'Video';
gGastroSlideshow[5] = 'Patient Portal';

var gCardioSlideshow = [];
gCardioSlideshow[0] = 'First Visit';
gCardioSlideshow[1] = 'My Activities';
gCardioSlideshow[2] = 'Echocardiography Report';
gCardioSlideshow[3] = 'Myocardial Perfusion Report';
gCardioSlideshow[4] = 'Stress Test';
gCardioSlideshow[5] = 'Refill Request';
gCardioSlideshow[6] = 'Patient Portal';

var gUroSlideshow = [];
gUroSlideshow[0] = 'First Visit';
gUroSlideshow[1] = 'My Activities';
gUroSlideshow[2] = 'Cystoscopy Report';
gUroSlideshow[3] = 'Urodynamics Report';
gUroSlideshow[4] = 'My Medications';

var practice = [];
practice[0] = 'Homepage';
practice[1] = 'Schedule';
practice[2] = 'Automated Charge Posting from EMR';

var step = 0;


/*
 *	page_init_slideshow
 *
 *		Extra on-load stuff just for the slideshow
 */
function page_init_slideshow(showType)
{
	//assign actions to Next and Previous buttons
	var prev = document.getElementById("Prev");
	var next = document.getElementById("Next");
	var slide = document.getElementById("Slide");

	//get "on" images
	(new Image()).src = prev.src.replace("_off", "_on");
	(new Image()).src = next.src.replace("_off", "_on");
	
	//assign rollovers
	prev.onmouseover = function(){this.src = this.src.replace("_off", "_on");};
	prev.onmouseout = function(){this.src = this.src.replace("_on", "_off");};
	next.onmouseover = function(){this.src = this.src.replace("_off", "_on");};
	next.onmouseout = function(){this.src = this.src.replace("_on", "_off");};
	
	//set array to use
	var slideSet;
	var buttonPosition;
	switch( showType ) {
		case "gGastro":
			slideSet = gGastroSlideshow;
			path = "../Images/slides/gGastro/gastro_slides_";
			buttonPosition = 198;
			break;
		
		case "gCardio":
			slideSet = gCardioSlideshow;
			path = "../Images/slides/gCardio/cardio_slides_";
			buttonPosition = 198;			
			break;
			
		case "gUro":
			slideSet = gUroSlideshow;
			path = "../Images/slides/gUro/guro_slides_";
			buttonPosition = 198;
			break;
			
		case "practice":
			slideSet = practice;
			path = "../Images/slides/practice/practice_slides_";
			buttonPosition = 152;			
			break;			
		
		default:
			break;
	}
	
	//preload slides
	preload_slides(slideSet, path);
	
	//assign onclick
	prev.onclick = function(){revert_slide(slideSet, path);};
	next.onclick = function(){advance_slide(slideSet, path);};
	
	//show content
	var content = document.getElementById("Content");
	if ( content.className == "hide" ) {
		content.className = "show";
	}
	
	//show buttons
	show_hide_buttons(slideSet);
	
	//place buttons
	//position = Math.round( (slide.height / 2) + slide.offsetTop - 10 );
	position = slide.offsetTop + buttonPosition;
	prev.style.top =  position + "px";
	next.style.top = position + "px";
	
}


/*
 *	show_hide_buttons
 *
 *		Decide which nav buttons to show
 */
function show_hide_buttons(showType)
{
	var prev = document.getElementById("Prev");
	var next = document.getElementById("Next");
	
	if( step == showType.length - 1 ) {
		next.style.display = "none";
	}
	else {
		next.style.display = "block";	
	}
	
	if( step == 0 ) {
		prev.style.display = "none";
	}
	else {
		prev.style.display = "block";	
	}	
	
}


/*
 *	advance_slide
 *
 *		Will go to the next slide
 */
function advance_slide(showType, path)
{
	step++;
	if( step > showType.length - 1 ) {
		step = showType.length - 1;
	}
	
	document.getElementById("Caption").innerHTML = showType[step];
	document.getElementById("Slide").src = path + (step + 1) + ".jpg";
	
	show_hide_buttons(showType);
	set_bottom();
}



/*
 *	revert_slide
 *
 *		Will go to the previous slide
 */
function revert_slide(showType, path)
{
	step--;
	if( step < 0 ) {
		step = 0;
	}
	
	document.getElementById("Caption").innerHTML = showType[step];
	document.getElementById("Slide").src = path + (step + 1) + ".jpg";
	
	show_hide_buttons(showType);
	set_bottom();
}


/*
 *	preload_slides
 *
 *		Will load the appropriate slide set ahead of time
 */
function preload_slides(showType, path)
{
	for( i=0; i < showType.length; i++ ) {
		(new Image()).src = path + (i + 1) + ".jpg";
	}
}