// ======================================================================================================
// Set the following variables...
// ======================================================================================================

var imgLocation="images/fade/commercial/"; //location of all of the images *make sure to include the forward slash after dir name
var thumbLocation="thumb/" //set for location of thumbnails
var picOrder="abc"; //set to 'ramdom' otherwise will show in ABC order
var showCaptions=""; //set to 'true' for captions othwise they won't show
var showImgNumber="" //set to show image display number
var thumbs="true"; // set to 'true' for thumbnail imgs
var autoChange="true";  //set to 'true' for automatic change otherwise manual change
var rotationSpeed=4500; // if autoChange is set to 'true' this is the speed the pics will change at in milliseconds
var showButtons="true";  //set to 'true' if want prev and next buttons 
var showScrollBar="" //set to 'false' to not have thumbnail scrollbar

// ======================================================================================================
// End of editable section     						DO NOT EDIT BELOW THIS LINE
// ======================================================================================================


var intval=""

function randOrd(){ // function for random imgs
return (Math.round(Math.random()*galleryarray.length)); } 

function checkVars(){
loadFirstImg();
showBrowseImages();

if (picOrder === "ramdom"){ // set for ramdom order
galleryarray.sort( randOrd );}

if (showCaptions === "true"){ // set for captions
createCap();}

if (showButtons === "true"){ // set for captions
buttons();}

if (showScrollBar === "false"){ // set for thubnail scrollbar
scrollBar();}

if (showImgNumber === "true"){ // set for captions
showImgNumberFun();}

if(thumbs==="true"){  // runs manual slideshow
create_thumbs();}

if (autoChange==="true") { // checks for autoChage var
startRotate();
}}


function startRotate(){
browseImagesHide();
buttons();
rotateimages();
intval=window.setInterval("rotateimages()", rotationSpeed);	
}

function stopSlideShow(){
window.clearInterval(intval);
}

function loadFirstImg(){
document.getElementById("slideshow").setAttribute("src", imgLocation+galleryarray[curimg])  //load first img src
createCap();
showImgNumberFun();
}

function createCap(){
if (showCaptions === "true"){ // set for captions
captionsSet();
document.getElementById("CaptionBox").innerHTML= caption[curimg]}} // changes the captions for auto fade


function showImgNumberFun(){
if (showImgNumber === "true"){ // set for captions
keeptrack();}}

function scrollBar(){
document.getElementById("navigation").style.overflow="hidden";}

function buttons(){
info='<a href="javascript:;" onclick="backward();return false">Previous Slide<\/a> | <a href="javascript:;" onclick="forward();return false">Next Slide<\/a> ';
document.getElementById("buttons").innerHTML=info;
document.getElementById("buttons").style.display='inline';}

function hideButtons(){
document.getElementById("buttons").style.display='none';}

function rotateimages(){
change_index(+1);}


function captionsSet(){
for(i=0; i<galleryarray.length; i++) { 
	var picArrayNumber=galleryarray[curimg];
    var captionPosition = picArrayNumber.indexOf("$")
  	 if (captionPosition===-1){
   	 caption[curimg]="No Caption Inserted";}
   else{
   	var captionName=picArrayNumber.substr(captionPosition+1,picArrayNumber.length); //gets the caption out of the filename
   	var locateExt = captionName.lastIndexOf(".") // set to remove ext on filename
   	var finalCaptionName=captionName.substr(0,locateExt); // actuall caption stored in finalCaptionName
   	caption[curimg]=finalCaptionName;}}}
	
function keeptrack(){
document.getElementById("picNumber").innerHTML="Image "+(curimg+1)+" of "+galleryarray.length;
}

function backward(){
if (curimg>0){
change_index(-1)
}
stopSlideShow();
browseImagesHide();
showStartRoto();
}


function forward(){
if (curimg<galleryarray.length-1){
change_index(+1);
stopSlideShow();
browseImagesHide();
showStartRoto();
}}

function create_thumbs(){
	var html = "<table border=\"0\" cellpadding=\"2\" cellspacing=\"5\"><tr>";
	for(var curimg=0;curimg<galleryarray.length;curimg++){
	html += "<td class=\"inactive\" id=\"thumb"+curimg+"\" width=\"100\"><a href=\"javascript:;\" id=\""+curimg+"\" name=\""+curimg+"\" onClick=\"change_index('',this.id); createCap();\"><img src=\""+imgLocation+""+thumbLocation+""+galleryarray[curimg]+"\" width=\"100\" height=\"75\" border=\"0\" alt=\""+curimg+"\" onclick=\"stopSlideShow();\" /></td>";
	}
	html += "</tr></table>";
	document.getElementById('navigation').innerHTML = html;}

function change_index(amount,position){
	var current_index = curimg;
	var new_index = new Number(0);
	if((amount != 1 && amount != -1) && position){
		new_index = parseInt(position);
	}
	else if(amount == 1 || amount == -1){
		new_index = current_index + parseInt(amount);
		if(new_index == galleryarray.length){
			new_index = 0;
		}
		if(new_index == -1){
			new_index = galleryarray.length-1;
		}
	}

	
	document.getElementById('thumb'+new_index).className = 'active';
	document.getElementById('thumb'+current_index).className = 'inactive';
	
	
	document.images.slideshow.src=imgLocation+"/"+galleryarray[new_index];
	curimg = new_index;
	//document.getElementById(curimg).focus();
	createCap();
	showImgNumberFun();
}

function browseImages(){
	stopSlideShow();
	hideButtons();
	browseImagesLinkHide();
	document.getElementById('navigation').style.display = 'block';
	showStartRoto();
}

function browseImagesHide(){
	document.getElementById('navigation').style.display = 'none';
}

function browseImagesLinkHide(){
	document.getElementById('browseSlideshow').style.display = 'none';
}

function showBrowseImages(){
	document.getElementById('browseSlideshow').innerHTML = "<a href=\"javascript:;\" onclick=\"browseImages();\">Browse Images</a>";
	document.getElementById('browseSlideshow').style.display = 'block';
}

function showStartRoto(){
	document.getElementById('rotoButtons').innerHTML = "<a href=\"javascript:;\" onClick=\"startRotate();hideStartRoto();showBrowseImages();\">Resume Slideshow</a>";
	document.getElementById('rotoButtons').style.display = 'block';
}
     
function hideStartRoto(){
	document.getElementById('rotoButtons').style.display = 'none';
}
