// resizes main image.  Also keeps track of currently selected image using the preview image's ".sel" attribute
function resizepreview()
	{
	var preimg = document.getElementById("thumbimg");
	//var rcol = document.getElementById("rightshadowcol");
	//var vbol =document.getElementById("bottomshadowcol");
	//rcol.style.height = preimg.height - 14;
	//vbol.style.width = preimg.width - 5;
	resize();
		if(!preimg.sel){
		preimg.sel=0;
		showimg(document.getElementById("img"+preimg.sel));
		}
	}
	
	// Call resize to set thumbnail, dropshadow and preview sizes.  Also populate title and description tags.
	window.onload= function() {resizepreview();};

	
	
	// Function Shows title and description of an image.  Also set main preview image to currently selected image.
	function showimg(obj)
	{
		var preimg = document.getElementById("thumbimg");
		preimg.src = obj.src;
		var cur = obj.id.replace("img", "");
		//alert('cur='+cur);
		preimg.sel = cur;
		obj.style.border="2px solid #660000";
		resizepreview();
		var t=document.getElementById("imgtitle");
		var d=document.getElementById("imgdesc");
		var t1 = document.getElementById(obj.id+'title');
		var d1 = document.getElementById(obj.id+'desc');
		t.innerHTML=t1.innerHTML;
		d.innerHTML=d1.innerHTML;
	}
	// Loops through all thumbnails, if their height or widht is greater than 55 it resizes them accordingly
	function resize()
		{
		var imgdiv=document.getElementById("imagelist");
		var img = imgdiv.getElementsByTagName("img");
		var preimg = document.getElementById("thumbimg");		
		for (var i=0; i < img.length; i++)
			{
				if (preimg.src != img[i].src)
				{
				img[i].style.border="2px solid #FFFFFF";
				
				}
				else
				{
				img[i].style.border="2px solid #660000";
				}
		}
	}
	// resizes Preview image
function maxth()
{
	var imgt = document.getElementById("thumbimg");
	/*var maxw = 440;
	var maxh = 330;
	//alert(imgt);
	if (imgt && imgt.width > maxw)
		{imgt.width=maxw;}
	if (imgt && imgt.height > maxh)
		{imgt.height=maxh;}
	resizepreview();
	*/
}
	// used by arrows to scroll forward or backward throught the gallery
	
		function shownext(i)
		
		{
			var preimg = document.getElementById("thumbimg");
			var imgdiv=document.getElementById("imagelist");
			var img = imgdiv.getElementsByTagName("img")
			var curimg= preimg.sel;
			
			if (!curimg){curimg=1;}
			//alert('curimg'+curimg);
			var nextimg = parseInt(curimg) + parseInt(i);
			//alert('init-nextimg='+nextimg);
			if (nextimg>img.length-1){nextimg=0;}
			if (nextimg<0){nextimg=img.length-1;}
			//alert('nextimg='+nextimg);
			var obj = document.getElementById("img" + nextimg);
			if(obj){showimg(obj);}
			if(!obj){alert(obj);}
		}
			
