//declare array to hold the images of the top navigation 
var theImages = new Array();

//declare variable for holding the block
var block;

//declare variable browserOk and intialize to false
var browserOk = false;
//if the browser is capable of handling document.images, it is a good browser, set browserOk to true
if ( (parseInt(navigator.appVersion)>=4 ) || ( navigator.appName == "Netscape"  ) ) browserOk = true;

//declare variable and set to false that will let us know if a layer is currently opened
var overDiv = false;

//declare variable to determine which browser the user has for event handling
var bV  = parseInt(navigator.appVersion);
var bNS = navigator.appName=="Netscape";

//declare the event handling for this page.  if a user clicks the mouse the function aClick() will handle the event
//the two if statments after this are for the various browser types
document.onmousedown = aClick;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (bNS && bV<5) window.onmousedown = aClick;

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    function to preload the images on the page
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function preloadImages() {
  var d=document; 
   if(d.images){ 
      if(!d.p) 
	     d.p=new Array();
	 var j = theImages.length;
	 for(i=0; i<theImages.length; i++){
         if (theImages[i].indexOf("#")!=0){ 
		     d.p[j]=new Image; 
			 d.p[j++].src=theImages[i];
	      }
	  }
	}
if(document.getElementById('mainPic')){
    document.getElementById('mainPic').style.height=theHeight;
	writePhotoNumber(1);
}

}
/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    Macromedia image restore function
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
     x.src=x.oSrc;
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    Macromedia find object function
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    Macromedia swap Image function
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function MM_swapImage() {
  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];
		}
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    builds the array
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function buildArray(lgt) {// opret et array med lgt elementer
   for (var i=1; i<=lgt; i++) this[i]=0;
   this.length = lgt;
   return this;
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    function to build the image objects each object has a tn, pic and length value
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function buildTnPic(thumbNail,fullPic,altText) { // build objekt
   this.tn=thumbNail;
   this.pic=fullPic;
   this.alt=altText;
   this.length=2;
   return this;
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    changes the main image on the page to the next image in the list
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function nextpic(){
//get value of the current image's source
  var currentImage = document.images.mainImg.src;
    //loop through every image in the gallery
  for(i=1;i<img.length;i++){
    //if the source of the current image is equal to this image
	//we know where where we are in the list and we should move on to the next
      if(currentImage.indexOf(img[i].pic) != - 1){
  	    //if the current image is the last in the list, img.length-1, then we need to go to the first image in the list
		//we call setpic(), otherwise we just go to the next picture with i+1
	    if(i == img.length-1)
	      setpic(1);
		else
		  setpic(i+1);
		 break;
	   }
  }
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    changes the main image on the page to the previous image in the list
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function priorpic(){
//get value of the current image's source
  var currentImage = document.images.mainImg.src;
  //loop through every image in the gallery
  for(i=1;i<img.length;i++){
    //if the source of the current image is equal to this image
	//we know where where we are in the list and we should move on to the previous
      if(currentImage.indexOf(img[i].pic) != - 1){
	    //if the current image is the first in the list then we need to go to the last image in the list
		//we do this using img.length-1 and call setpic() otherwise we just go to the previous picture with i-1
	    if(i == 1)
	      setpic(img.length-1);
		else
		  setpic(i-1);
		 break;
	   }
  }
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    changes the main image on the page
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */

function setpic(n) { 
//if the layer is initilized, close it
if(block)closeIt();
//reset the value of overDiv to false
overDiv = false;
    if ( browserOk ){
	   document.images.mainImg.src= img[n].pic;
  	   document.images.mainImg.alt= img[n].alt;   
	   writePhotoNumber(n);
	}
   else
       alert ("Sorry IE3 cannot show pictures here")
}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||
    handels each time the user clicks the mouse on the page
   |||||||||||||||||||||||||||||||||||||||||||||||||||||  */
function aClick(){
//check to see if the mouse is not currently over one of the layers and that the layer has been initialized
  if(!overDiv && block){
  //make sure that the layer is not in the middle of scrolling when the user clicks
    if(clipValues(block,'b')>=botVal)
	//close the currently opened layer
	  closeIt();
   }
}

function writePhotoNumber(theNumber){
    document.getElementById('countCell').innerHTML = 'Photo ' + theNumber + ' of ' + (img.length-1);
}