self.name = "main";	// If you are using frames, change "main" to the name of the frame that the photoalbum is in.

current = 0;	// Sets the current picture being shown to the first one.

ActiveVar = 0;	// Sets up the variable that counts the pictures.

var ActiveArray = new Array()	// Sets up the active array.

for (loop=0; loop < MainVar; loop++) {
  ActiveArray[ActiveVar++] = new Fix(MainArray[loop].DatVal, MainArray[loop].PicVal, MainArray[loop].TitVal, MainArray[loop].CatVal, MainArray[loop].TxtVal)
}

function DisplayCategories() { // Lists out the categories.
  TotalCategories = Category.length;
  for (loop=0; loop < TotalCategories; loop++)  {
    document.write("<option value=" + Category[loop] + ">" + ReplaceChars(Category[loop]) + "</option>");
  }
}

function LoadPiclist() { // Loads initial list of pictures on web page.
  for (loop=0; loop < MainVar; loop++)  {
    document.write("<option value=" + ActiveArray[loop].PicVal + ">" + ActiveArray[loop].TitVal + "</option>");
  // document.write("<option value=" +  ">" + ActiveArray[loop].TitVal + "</option>");
  }
}

function LoadNextPic()  { // Loads next picture for faster operation.
	NextImage = new Image();
	NextPic = current + 1;
    if (NextPic>=ActiveVar) NextPic = 0;
    NextImage.src = ActiveArray[NextPic].PicVal;
}

function NextarbPic() { // Flips to the next photo.
  TotalImages = document.arbForm.arbDropdown.options.length;
  current++;
  if (current>=ActiveVar) current = 0;
  ShowarbPic(current);
  }

LoadThis = 0;
function PreLoader() { 
   // If checked, preloads all images into cache.  Five second interval between pics.
  if (arbForm.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 PreviousarbPic() { // Flips to the previous photo.
  current--;
  if(current<0) current = ActiveVar - 1;
  ShowarbPic(current);
}

function RandomarbPic() { // Shows a random photo.
  randompic = Math.floor(Math.random()*ActiveVar);
  ShowarbPic(randompic);
}

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;
// document.subform.text.value = temp;
}


/* ******** main function to show the pics ****/
function ShowarbPic(newpic){ // Shows the photo and text on the page.
  current = newpic;
  var newImg = new Image();
  newImg.src = ActiveArray[current].PicVal;//imgSrc;
  var height = newImg.height;
  var width = newImg.width;
  var ratio = height/width;
  SelectionBox = document.arbForm.arbDropdown;
  SelectionBox.options[current].selected = true;	
    //alert ('The image size is '+width+'*'+height + ' **ratio ' + ratio);
  if ( height<=width)
  {
	   document.getElementById("arbSpot").innerHTML = '<a href=javascript:arbPicRemote("' + ActiveArray[current].PicVal + '");><img name="PicShowing" src=' + ActiveArray[current].PicVal + ' width=300 ></a>';
	   //alert( ' i m in "if" ');
  } else  {
	   document.getElementById("arbSpot").innerHTML = '<a href=javascript:arbPicRemote("' + ActiveArray[current].PicVal + '");><img name="PicShowing" src=' + ActiveArray[current].PicVal + ' height=300></a>';
	   //alert( ' i m in "else" ');
  }
  
  document.getElementById("Journal").innerHTML = '<div class="aura_imagery"><p><font color="#67584"> TITLE: </font>' + ActiveArray[current].TitVal + '</p><p><font color="#67584"> Created on: </font>' + ActiveArray[current].DatVal + '</p><p><font color="#67584">Catagory : </font>' + ActiveArray[current].CatVal  + '</p><p><font color="#67584">About Image :</font> <br>' + ActiveArray[current].TxtVal + '</p></div>';
  
  if (document.arbForm.SelectedMode[1].checked) { 
    timerSlideShow = setTimeout("NextarbPic();", document.arbForm.Timer.value*1000)
	LoadNextPic();
  } else {	 
    LoadNextPic();
  }
  if (document.arbForm.WhereView[1].checked) {  
	timerID = setTimeout("arbPicRemote(ActiveArray[current].PicVal)",1000)
  }	

}


function ShowarbCategory(picked) { // Shows the pictures in that category.
  ActiveArray.length = 0;
  PicList = "<SELECT size=1 style='width:200px; font:8pt ' name='arbDropdown' onChange='ShowarbPic(this.options.selectedIndex);'>";
  ActiveVar = 0;
  current = 0;
  for (loop=0; loop < MainVar; loop++) {
	if (MainArray[loop].CatVal.toLowerCase() == picked.toLowerCase() || picked == "all") {
	  ActiveArray[ActiveVar++] = new Fix(MainArray[loop].DatVal, MainArray[loop].PicVal, MainArray[loop].TitVal, MainArray[loop].CatVal, MainArray[loop].TxtVal)
	 PicList = PicList + "<option value=" + MainArray[loop].PicVal + ">" + MainArray[loop].TitVal + "</option>"; 
	} 
  }
  PicList = PicList + "</select>";
  document.getElementById("PicSpot").innerHTML = PicList;
}




function ShowarbCategory34(picked) { // Shows the pictures in that category.
  ActiveArray.length = 0;																				     
  PicList = "<SELECT size=10 style='width:200px; font:8pt ' name='arbDropdown' onChange='ShowarbPic(arbForm.arbDropdown.options.selectedIndex);'>";
  ActiveVar = 0;
  current = 0;
  for (loop=0; loop < MainVar; loop++) {
	if (MainArray[loop].CatVal.toLowerCase() == picked.toLowerCase() || picked == "all") {
	  ActiveArray[ActiveVar++] = new Fix(MainArray[loop].DatVal, MainArray[loop].PicVal, MainArray[loop].TitVal, MainArray[loop].CatVal, MainArray[loop].TxtVal);
	 PicList = PicList + "<option value=" + MainArray[loop].PicVal + ">" + MainArray[loop].TitVal + "</option>"; 
	} 
  }
  PicList = PicList + "</select>";
  document.getElementById("PicSpot").innerHTML = PicList;
  LoadPiclist();
}
