function PreloadImages() {
  var d=document; 
  
  if(d.images){ 
    if(!d.MM_p) 
	  d.MM_p=new Array();
    
	var i,j=d.MM_p.length,a=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 IsImageHighlighted(imageId) {
	var a = document.highlightedImages;
	
	if ( a == null )
		a = new Array("", "");
	
	for (i=0; i < a.length; i++) {
		if ( a[i] == imageId ) {
			return i;
		}
	}
	return -1;
}

function ClickChangeImage(imageId, imagePath) {
	var x,y,j,i,m;
	
	if ( document.lastUpdatedHighlightImage == null )
		document.lastUpdatedHighlightImage = 0;

	if ( document.highlightedImages == null )
		document.highlightedImages = new Array("", "");
	
	if ( (j = IsImageHighlighted(imageId)) == -1 ) {
		if ((x=FindObj(imageId))!=null){
			if ( document.highlightedImages[0] == "" ) {
				SwapImage(imageId, imagePath+imageId+"_1.gif");
				document.highlightedImages[0] = imageId;
				SwapImage("right_bottom", imagePath+imageId+"_right_bottom.jpg");							
				document.lastUpdatedHighlightImage = 0;
				if ((y=FindObj(imageId+"_link"))!=null) {
					y.removeAttribute("href");
				}
			} else if ( document.highlightedImages[1] == "" ) {
				SwapImage(imageId, imagePath+imageId+"_2.gif");
				document.highlightedImages[1] = imageId;
				document.lastUpdatedHighlightImage = 1;
				SwapImage("right_top", imagePath+imageId+"_right_top.jpg");
				RemoveLink(imageId+"_link");				
			} else {				
			    document.lastUpdatedHighlightImage = document.lastUpdatedHighlightImage == 0 ? 1 : 0;
				m=document.lastUpdatedHighlightImage == 0 ? "right_bottom" : "right_top";
				// Restore the last highlighted image to its original image src
				ResetImage(document.highlightedImages[document.lastUpdatedHighlightImage], imagePath+document.highlightedImages[document.lastUpdatedHighlightImage]+"_0.gif");
				// Change the thumbnail clicked to the appropriate highlighted color
				SwapImage(imageId, imagePath+imageId+"_" + (document.lastUpdatedHighlightImage + 1) + ".gif");
				// Swap the right column image
				SwapImage(m, imagePath+imageId+"_"+m+".jpg");
				AddLink(document.highlightedImages[document.lastUpdatedHighlightImage]+"_link", "javascript:ClickChangeImage('" + document.highlightedImages[document.lastUpdatedHighlightImage] + "', '" + imagePath + "');");
				document.highlightedImages[document.lastUpdatedHighlightImage] = imageId;
				RemoveLink(imageId+"_link");
			}			
		}
	}
}

function ResetImage(imageId, defaultImageName) {
  var x
  
  if ((x=FindObj(imageId))!=null){
	  x.oSrc=defaultImageName; 
	  x.src=defaultImageName;
  }
}

function SwapImage(imageId, imageFileName) {
  var x
  
  if ((x=FindObj(imageId))!=null){
	  x.oSrc=x.src; 
	  x.src=imageFileName;
  }
}

function TriSwapImage(imageId, imageFileName) {
  if ( IsImageHighlighted(imageId) == -1 ) {
  	SwapImage(imageId, imageFileName);
  }
}

function SwapImageRestore(imageId) {
  var x;
   
  if ((x=FindObj(imageId))!=null){
   x.src=x.oSrc;
  }
}

function TriSwapImageRestore(imageId, forceSwap) {
	var x;

    if ( IsImageHighlighted(imageId) == -1 || forceSwap ) {
		SwapImageRestore(imageId);
	}
}
