
<!--


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_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_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; 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];}
}

function showImg(direction){
	
	var form = document.imgs;
	var actionForm = document.pageaction;
	
	if(form == null) return false;
	var currentimg = actionForm.currentimg.value;
	var newimgid = parseInt(currentimg) + parseInt(direction);
	var imgid = document.getElementById("id"+newimgid);
	if(imgid == null) return;
	actionForm.imgid.value = imgid.value;
	actionForm.currentimg.value = newimgid;
	actionForm.actiontype.value = "read";
	actionForm.submit();

	
	
}

function showGalleryImage(direction){

	var form = document.imgs;
	var actionForm = document.pageaction;
	
	if(form == null) return false;
	//var img = document.getElementById('img');
	//if(img == null) return false;
	
	//var imgTitle = document.getElementById('imgTitle');
	
	var currentimg = form.currentimg.value;

	var newimgid = parseInt(currentimg) + parseInt(direction);

	//var newimgmeta = document.getElementById("img"+newimgid);

	var imgid = document.getElementById("id"+newimgid);

	if(imgid == null){return}
	
	actionForm.imgid.value = imgid.value;
	form.currentimg.value = newimgid;
	actionForm.submit();
	
	/*
	
	if(newimgmeta != null){
	
		var newimgtitle = document.getElementById("title"+newimgid);
		
		newimgdata = new Image();
		newimgdata.onload = function() {loadImg(newimgdata)};
		newimgdata.onabort = function() {loadImgAbort(newimgdata)};
		newimgdata.onerror = function() {loadImgError(newimgdata)};
		newimgdata.src = "bin/gallery/" + newimgmeta.value;
		
		if(newimgdata !=null){
			imgTitle.innerHTML = newimgtitle.value;
			//img.src = "bin/gallery/" + newimg.value;
			form.currentimg.value = newimgid;
		}
	}
	*/
}

function switchGallery(){

	var fGallery = document.gallery;
	var sGallery = fGallery.selectgallery;
	var id = sGallery.options[sGallery.selectedIndex].value;
	if(id == ""){return false;}
	var form = document.pageaction;
	form.id.value = id;
	form.actiontype.value = "read";
	form.submit();
	
}

function reSize(oImg,iMaxHeight, iMaxWidth){
//Resize image with aspect ratio
	
	var iHeight;
	var iWidth;
	iHeight = oImg.height;
	iWidth = oImg.width;	

	
	if(iWidth > iMaxWidth){
		percentage = (iMaxWidth / iWidth);
		iWidth = Math.round(iWidth * percentage);
		iHeight = Math.round(iHeight * percentage);
		
	}
	
	if(iHeight > iMaxHeight){
		percentage = (iMaxHeight / iHeight);
		//Always make landscape pictures at defined width,
		//regardless of aspect ratio. Pictures might be skewed,
		//but a defined width is important for consistency of the layout.
		//Adjust portait widths after aspect ratio.
		if(iWidth < iHeight){
			iWidth = Math.round(iWidth * percentage);
		}
		iHeight = Math.round(iHeight * percentage);	

	}


oImg.width = iWidth;
oImg.height = iHeight;
return nImg;

}

function adjustRatio(iVal1, iVal2, iMax){
//"Formula" for calculating aspect
	iBoundary = iVal2/iMax;
	iNewVal = Math.round(iVal1/iBoundary);
	
	return iNewVal;
}
	
function loadImg(oImg){
//Resize preloaded images and replace current images

	//imgArrayLoaded[i] = "loading";
	var img = document.getElementById("img");
	oImg = reSize(oImg, 260,370);
	img.height = oImg.height;
	img.width = oImg.width;
	img.src = oImg.src;
	img.style.display = "";

}

function loadImgAbort(i){
	loadImgError(i);
}

function loadImgError(i){

	var img = document.getElementById("img"+i);
	if(img != null){
		img.src = errorSrc;
		img.name = "NoImageAvailable";
	}
}

//-->
