
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Opensupport2(newin) {
Support2=window.open(newin,"Support2","resizeable=yes,scrollbars=yes,width=875,height=650 top=20,left=20");
window.Support2.focus();
}

function Opensupport4(newin) {
Support4=window.open(newin,"Support4","resizeable=yes,scrollbars=yes,width=875,height=400 top=20,left=20");
window.Support4.focus();
}

function Opensupport5(newin) {
Support5=window.open(newin,"Support4","resizeable=yes,scrollbars=yes,width=680,height=540 top=20,left=20");
window.Support5.focus();
}



//--------------------------------------------------
//--------------Slideshow Code----------------------
//--------------------------------------------------



// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 4500;
// Duration of crossfade (seconds)
var crossFadeDuration = 4;



// Specify the image files in pics.js <!--- W-R-O-N-G!!!! SEE CORRECT WAY BELOW...

//*********************************************************************************************************************
// USE CODE BELOW IN THE CALLING PROGRAM....
// We want to make the pictures dynamically load an array in the calling program (from the rows in a DB table).
//
// DB TABLE:
// 				reggallery can be copied from Seaside Landing website.
// NOTE: 
// 				The <script> tag for this .js file is BELOW the dynamic allocation of the array Pic! 
// 				Otherwise Pic array would be UNDEFINED...see below...
// CF CODE:
//				Insert code below into calling program...
/*

<cfquery name="getgall" datasource="#dsn#" dbtype="ODBC">
		Select * 
		from reggallery
		order by displayorder
		</cfquery>

<!--- OLD CODE: <script language="JavaScript" type="text/JavaScript" src="pics-gallery.js"></SCRIPT>--->

<script language="JavaScript" type="text/JavaScript">
var Pic = new Array();
var Cap = new Array();
var dex = 0;
<cfoutput query="getgall">
Pic[dex] =  'images/index.html#image#';
Cap[dex++] =  '#thetext#';
</cfoutput>
</script>
<script language="JavaScript" type="text/JavaScript" src="scripts-gallery.js"></SCRIPT>

*/         
//*********************************************************************************************************************

var timeout;
var pos = 0;
var p = Pic.length;
var preLoad = new Array();
var pausestate = false;
var reverse = false;
var start = true;

// Preload All Slideshow Images
for (i = 0; i < p; i++) {
	preLoad[i] = new Image();
	preLoad[i].src = Pic[i];
}


function runSlideShow() {
/*	if(!pausestate){ */

// always display what is set up.........
	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[pos].src;
	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}
	document.getElementById("daCaption").innerHTML = "<span>" + Cap[pos]; + "</span>";

		
	if(!pausestate){ //if you are not paused ....
		pos = pos + 1; // bump up the index
		if (pos > (p - 1)) pos = 0; // when you reach the end ... point to the beginning of the array
		timeout = setTimeout('runSlideShow()', slideShowSpeed); // kick it off again to keep looping
	}
		/* CRAP: 
			if (reverse) {
			pos = pos + 1;
			reverse=false;
		}*/

	/*  GOD ONLY KNOWS...}
	else {
	if (reverse && pos > 1) pos = pos -1;
	timeout = setTimeout('runSlideShow()', 10000);
	}  */
	
	
} // end of function

function initial() {
		pauseico = document.getElementById('pause');
		runSlideShow();
}

function changeTo(image) {
	var thumbsource = image.src;
	fullsource = thumbsource.replace('thumbsizeimages','fullsizeimages');
	document.images.SlideShow.src = fullsource;
	pause('on');
}

function restartshow () {
	
	if(pausestate){ //if you are paused ....
		pause('off'); // tell slideshow to continue looping after it gets started...
		pos = pos + 1; // point dex to next pic
		if (pos > preLoad.length - 1) { // see if index is greater than last element of array
			//alert("resetting pos to 0...");
			pos = 0 // if past last element - point to first element
		} 	
		runSlideShow(); // display what you've set up...
	}
	// NOTE: if you ain't paused, you don't need to restart (Right Tater???)	

} // end function
	
function ssnext() {
	clearTimeout(timeout); // stop the looping ... we're going to control display manually
	
		
	if(!pausestate){ //if you are not paused ....
		pause('on');  // set pause 'on' to prevent runSlideShow from taking off again
		pos = pos - 1; // since you weren't paused, index was pointing to next picture - point back to 
						// ... the one that is currently seen by the user
	}

	pos = pos + 1; // point dex to next pic
	if (pos > preLoad.length - 1) { // see if index is greater than last element of array
		//alert("resetting pos to 0...");
		pos = 0 // if past last element - point to first element
	} //cl new code

	runSlideShow(); // display what you've set up...	

} // end function

/* CRAP: if (reverse) {pos = pos + 1; reverse = false;} */
// crap:	pause('off');

function ssprev() {
	clearTimeout(timeout);  // stop the looping ... we're going to control display manually
	
	if(!pausestate){ //if you are not paused ....
		pause('on');  // set pause 'on' to prevent runSlideShow from taking off again
		pos = pos - 1; // since you weren't paused, index was pointing to next picture - point back to 
						// ... the one that is currently seen by the user
	}

	pos = pos - 1; // point dex to prev pic
	if (pos < 0){  // see if index is less than 0
		//alert("pos is: " + pos);
		pos = preLoad.length - 1; // if index is less than 0 - point to last element
		//alert("pos set to: " + pos);
	}
	
	runSlideShow(); // display what you've set up...
	
} // end function	

// crap: 	pause('off');

		
	/*	crap...
	document.images.SlideShow.src = preLoad[pos].src;
	document.getElementById("daCaption").innerHTML = Cap[pos];
	runSlideShow(); // display what you've set up...
	pause('on');  // set pause back on since you're using the prev button to navigate
	*/
		
	/*	if (!reverse) {
			alert("if - pos is: " + pos);
			pos = pos - 1;
			//temppos = pos - 1; <--- idiotic!
			temppos = pos;
			alert("if - temppos is: " + temppos);
			document.images.SlideShow.src = preLoad[temppos].src;
			document.getElementById("daCaption").innerHTML = Cap[temppos];
			reverse=true;
		}
		else {
			pos = pos - 1; // cl added this line
			alert("else - pos is: " + pos);
			document.images.SlideShow.src = preLoad[pos].src;
			document.getElementById("daCaption").innerHTML = Cap[pos];
		}
		pause('on');
		runSlideShow();  */
 	//}
	/*  YE OLDE CRAP CODE....
		if (pos == 1 || pos == 0){
		document.images.SlideShow.src = preLoad[pos].src;
		document.getElementById("daCaption").innerHTML = Cap[pos];
		pos = 0;
		
} // end function		
	}*/ 


function pause(state) {
	if(state == 'on') {
		pauseico.style.display = '';
		pausestate = true;
	}
	if(state == 'off') {
		pauseico.style.display = 'none';
		pausestate = false;
	}
	if(!state){
		if(!pausestate){
			pauseico.style.display = '';
			pausestate = true;
			clearTimeout(timeout);  // stop the looping ... we're going to control display manually
		}
		else {
			pauseico.style.display = 'none';
			pausestate = false;
			runSlideShow();
		}
	}
}


