self.name = "main"; 


current = 0; // Sets the current picture being shown to the first one.
currentArray = 0; // Tells me which array is being moved.

var current = new Array() 
current[0] = 0;

var ActiveVar = new Array() // Sets up the active array count.
ActiveVar[0] = 0; // Sets up the variable that counts the pictures.
ActiveVar[1] = 0; // Sets up the variable that counts the pictures.
ActiveVar[2] = 0; // Sets up the variable that counts the pictures.
ActiveVar[3] = 0; // Sets up the variable that counts the pictures.
ActiveVar[4] = 0; // Sets up the variable that counts the pictures.
ActiveVar[5] = 0; // Sets up the variable that counts the pictures.

ActiveVar[0] =MainVar[0];
ActiveVar[1] =MainVar[1];
ActiveVar[2] =MainVar[2];
ActiveVar[3] =MainVar[3];
ActiveVar[4] =MainVar[4];
ActiveVar[5] =MainVar[5];

var ActiveArray = new Array() // Sets up the active array.

for (loop2=0; loop2 < ArrayCount+1; loop2++) {
	ActiveArray[loop2] = new Array();
	for (loop=0; loop < MainVar[loop2]; loop++) {
	  ActiveArray[loop2][loop] = new Fix(MainArray[loop2][loop].DatVal, MainArray[loop2][loop].PicVal, MainArray[loop2][loop].TitVal);

	}
	
}

function LoadNextPic()  { // Loads next picture for faster operation.
	NextImage = new Image();
	NextPic = current[currentArray] + 1;
    if (NextPic>=ActiveVar[currentArray]) NextPic = 0;
    NextImage.src = ActiveArray[currentArray][NextPic].PicVal;
}

LoadThis = 0;
function PreLoader() { // If checked, preloads all images into cache.  Five second interval between pics.
  if (Form.PreloadPics.checked && ++LoadThis < MainVar) {
    ShowingImage = new Image();
    ShowingImage.src = MainArray[LoadThis].PicVal;
	window.status="Pre-Loading image... '" + MainArray[LoadThis].PicVal + "'";
    RunLoader();
  } else {
	window.status=" ";
  }
}

function PreviousPic(direction,CurrArr) { // Flips to the previous photo.
  currentArray=CurrArr
  if (currentArray > 0) {
  	if (current[currentArray] == undefined){
  		current[currentArray] = 0;
  	}
  }

  if (direction==0){
	current[currentArray]--;
	if(current[currentArray]<0) current[currentArray] = ActiveVar[currentArray] - 1}
  else{
	current[currentArray]++;
	if(current[currentArray]  >=  ActiveVar[currentArray]) current[currentArray] = 0}
  ;
  ShowPic(current[currentArray],currentArray);
}

function ReplaceChars(entry) { // Replaces the _'s in cat names to make it pretty.
  out = "_"; // replace this
  add = " "; // with this
  temp = "" + entry; // temporary holder
  while (temp.indexOf(out)>-1) {
    pos= temp.indexOf(out);
    temp = "" + (temp.substring(0, pos) + add + 
    temp.substring((pos + out.length), temp.length));
  }
return temp;
}

function RunLoader() { // Pre-loads all images every 5 seconds, if checkbox is selected.
  timerLoad = setTimeout("PreLoader()",5000)
}

function ShowPic(newpic,currentArray) { // Shows the photo and text on the page.
  current[currentArray] = newpic;
  
  //newpic=int(newpic)
  document.getElementById("Spot"+currentArray).innerHTML = '<a href=javascript:PicRemote("' + ActiveArray[currentArray][newpic].PicVal + '");><img name="PicShowing" src=' + ActiveArray[currentArray][newpic].PicVal + ' height=200 border=0></a>';
  document.getElementById("Desc"+currentArray).innerHTML = ActiveArray[currentArray][newpic].TitVal ;
  document.getElementById("Count"+currentArray).innerHTML = (newpic+1) + ' of ' + ActiveVar[currentArray];
  LoadNextPic();

}
function PicRemote(picName) { // Pops up the photo in a remote window.
    ShowingImage = new Image();
    ShowingImage.src = picName;
    wid = ShowingImage.width + 50;
    hei = ShowingImage.height + 100;
  //if (wid < 30 || hei < 30) {
    //wid=650;
    //hei=550;
  //}
  //if (screen.width < wid || screen.height < hei) {
  //  wid = screen.width - 50;
  //  hei = screen.height - 50;
  //}
  OpenWindow = window.open("", "remoteWin", "resizable=1, scrollbars=1, toolbar=0, left=15, top=10, width=" + wid + ", height=" + hei);
  OpenWindow.document.open();
  if(picName=="/images/Upload/dtDWS_MajorityLeader.jpg"){
  OpenWindow.document.write('<html><head><title></title></head>'
    + '<body font:8pt verdana; margin:2px"><center><br>'
    + '<img src=' + picName + '><br>'
	+ '<br><a href="javascript:window.close();">close window</a></center></body></html>');
  }else{
  OpenWindow.document.write('<html><head><title>' + ActiveArray[currentArray][current[currentArray]].TitVal + '</title></head>'
    + '<body font:8pt verdana; margin:2px"><center><br>'
    + '<img src=' + picName + '><br>' + ActiveArray[currentArray][current[currentArray]].TitVal
	+ '<br><a href="javascript:window.close();">close window</a></center></body></html>');
	}
  OpenWindow.document.close();
}
