// Thumbnail image hover functions
var W3CDOM = (document.createElement && document.getElementsByTagName);
var gLargeImageID = '', gLargeImageSrc = '', gLargeImageOrient = '';
var imageThumbs = new Array();
//var mouseOuts = new Array();

var maxLargeImageWidth = "400";
var maxLargeImageHeight = "300";
var ThumbImageWidth = "98";
var ThumbImageHeight = "74";

window.onload = preloadThumbs;

function preloadThumbs()
{
	if (!W3CDOM) return;
	var nav = document.getElementById('imagesThumbs');
	if(nav) {
		var imgs = nav.getElementsByTagName('img');
		for (var i=0;i<imgs.length;i++)
		{
			//imgs[i].onmouseover = swapImage('image_large');
			//imgs[i].onmouseout = mouseGoesOut;
			//var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
			imageThumbs[i] = new Image();
			imageThumbs[i].src = imgs[i].src;
			//imageThumbs[i] = new Image();
			//imageThumbs[i].src = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_omo" + suffix;
			imgs[i].number = i;
			
			// Set size of thumbnails
			////imgs[i].width = ThumbImageWidth;
			////imgs[i].height = ThumbImageHeight;
			
			// Set up width and height for large image display
			if( imgs[i].width > imgs[i].height) {	// Landscape
				imageThumbs[i].setWidth = maxLargeImageWidth;
				imageThumbs[i].setHeight = imgs[i].height * maxLargeImageWidth / imgs[i].width;
			} else {	// Portrait
				imageThumbs[i].setHeight = maxLargeImageHeight;
				imageThumbs[i].setWidth = imgs[i].width * maxLargeImageHeight / imgs[i].height;
			}
			////imageThumbs[i].width = ThumbImageWidth;
			////imageThumbs[i].height = ThumbImageHeight;
		}
	}
}
function swapImage() { //v3.0
	var i,j=0,x,a=swapLargeImage.arguments; // NSR: ImageName, index
	var index = 0;
	i=0; index=this.number;
	if ( a != null && (x=MM_findObj(a[i]))!=null){
	   x.src=imageThumbs[index].src;
	   
	   // Set the width or height depending on the orientation
	   ////x.height = imageThumbs[index].setHeight;
	   ////x.width = imageThumbs[index].setWeight;
	}
}
function swapLargeImage() { //v3.0
  var i,j=0,x,a=swapLargeImage.arguments; // NSR: Image name, {Image usemap}, image src, orientation{portrait|landscape}, label
  var size;
  document.MM_sr=new Array; 
  //for(i=0;i<(a.length-2);i+=3) {	// Assume one set of arguments
	i=0;
   	if ((x=MM_findObj(a[i]))!=null){
	   document.MM_sr[j++]=x; 
	   if(!x.oSrc) {
		   x.oSrc=x.src;
	   }
	   x.src=a[i+2];
	   
		// Ignoring map setting here - seems to tur the image into an anchor link in firefox
		
	   // Set the width or height depending on the orientation
	   if( a[i+3] == "portrait") {
		   x.height = "300";
		   x.width = "225";
	   } else {
		   x.height = "300";
		   x.width = "400";
	   }
	   
	   // Update the label
	   labelID = a[i]+"_label";
	   label = a[i+4];
	   //alert('labelID='+labelID+'label='+label);
   	   if((l=MM_findObj(labelID))!=null){
		l.innerHTML = label;
	   }
	   
	}
  //}
}


function MM_preloadImages() { //v3.0
  var d=document; 
  if(d.images){ 
  	if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {
	  x.src=x.oSrc;
  }
}

function MM_findObj(n, d) { //v4.01
  	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 && d.getElementById) x=d.getElementById(n); 
	return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; // NSR: Image name, Image usemap, image src
  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;
	   }
	   if( a[i+1].length > 0) {
	   	x.useMap=a[i+1];
	   } else {
	   	x.useMap='';
	   }
	   x.src=a[i+2];
	}
  }
}
var all_Images = new Array();
function all_swapImage(thumbNumber, width, height) { 
	var i,j=0,x;
	var size;
	  
	if(typeof(width)==='undefined') width = 400;
	if(typeof(height)==='undefined') height = 300;
	  
	var elImage = document.getElementById("image");
	var elImageLabel = document.getElementById("image"+"_label");
	  
	if(typeof(all_Images[thumbNumber])=='undefined') return; // Not rendered yet
	  
	var thumbId = "thumb"+thumbNumber;
	var elThumb = document.getElementById(thumbId);
	var label = all_Images[thumbNumber].label;
	if(typeof(label)=='undefined') label = '';
  
	elImage.src = all_Images[thumbNumber].src;
	elImageLabel.innerHTML = label;
	
	if(elThumb && elThumb.naturalHeight>elThumb.naturalWidth) { // Portrait
		elImage.height = height;
	   	elImage.width = parseInt(height * height / width);
	} else {
	   	elImage.height = height;
	   	elImage.width = width;
	}

}



