// functions to scale images

// 10 aug 2002, frank o'brien, dianfrank_del@attbi.com

// given file name and image tag properties for 
//  percentage of orignal width and heigth,
//  border width, and alternative text,
// writes an html line to show image scaled to percentage
//  or original

// advantage is the image width and height are not 
//  needed as parameters as they are determined by 
//  reading image file into local image object,
// disadvantage is this load must occur before html 
//  outputed and this could be slow

function ShowImageSlow (imgfname, prctg, borderw, altstr) {
	myImage=new Image()
	myImage.src=imgfname
	document.write("<img src="+imgfname+
	 " width='"+Math.floor(prctg/100*myImage.width)+
	 "' height='"+Math.floor(prctg/100*myImage.heigth)+
	 "' border='"+borderw+
	 "' alt='"+altstr+
	 "'>")
}

// given file name and image tag properties for 
//  percentage of orignal width and heigth,
//  original width, orginal heigth, 
//  border width, and alternative text,
// writes an html line to show image scaled to percentage
//  of original

// advantage is image html line writen quickly,
// disadvantage is must know width and heigth

function ShowImage (imgfname, prctg, imgw, imgh, borderw, altstr) {
	document.write("<img src="+imgfname+
	 " width='"+Math.floor(prctg/100*imgw)+
	 "' height='"+Math.floor(prctg/100*imgh)+
	 "' border='"+borderw+
	 "' alt='"+altstr+
	 "'>")
}

// will return the inner screen width in pixels if browser
//  is netscape navigator or internet explorer compatible,
//  otherwise returns null

function ScreenWidth () {
	// check if not nav compatible
	if (window.innerWidth==null) {
		// check if not ie compatible
		if (document.body.clientWidth==null) {
			// don't know width
			return null
		}
		else {
			// is ie compatible
			return document.body.clientWidth
		}
	}
	else {
		// is nav compatible
		return window.innerWidth
	}
}

// will return true if screen width is less than 780
//  which is about 800 pixels less borders
// if screen width unknown, returns true

function IsSmallScreen () {
	if (ScreenWidth()==null) {
		return true
	}
	else {
		if (ScreenWidth()<780) {
			return true
		}
		else {
			return false
		}
	}
}

// given image that fits well on large screens,
// will display the image scaled by 80% if screen is small,
//  and display original image if screen is not small

function ShowLargeImage (imgfname, imgw, imgh, borderw, altstr) {
	if (IsSmallScreen()) {
		// show image scaled 80%
		ShowImage(imgfname, 80, imgw, imgh, borderw, altstr)
	}
	else {
		// show original image
		ShowImage(imgfname, 100, imgw, imgh, borderw, altstr)
	}
}

// given name of image file that will display appropriately on 
//  a screen size of 800 pixels or wider, name of an image file
//  that will display appropriately on a screen size of less 
//  than 800, and the alternate text string,
// writes an html img tag line for displaying the high res image 
//  on display size of 800 or larger, otherwise will write img tag
//  line to display the low res image
// 780 used as test for 800 screen width to allow for scrollbar

function SelectImage (hres_imgfname, hres_imgw, hres_imgh, 
	 lres_imgfname, lres_imgw, lres_imgh, borderw, altstr) {
	if (IsSmallScreen()) {
		// show low res image
		ShowImage(lres_imgfname, 100, lres_imgw, lres_imgh, borderw, altstr)
	}
	else {
		// show high res image 
		ShowImage(hres_imgfname, 100, hres_imgw, hres_imgh, borderw, altstr)
	}
}
