/*	l a r g e i m g s . j s
	author: Andrew Purdam webmaster @ hallvet . com . au
	Creation date: 7/12/05
	
	Implementation of download of large imgs to replace other imgs 
	when a window is deemed large enough
	
	Requires:
	Definition of global variable "browser" to be 
	"Safari", "OmniWeb", "Opera", "WebTV", "iCab", "Internet Explorer", "FireFox", "Netscape Navigator", or "An Unknown Browser"
	(actually, just need to know if it is Internet Explorer)

	Two entry points are needed per document:
	In header
	<script language="javascript" src="largeimgs.js"></script>
	<script language="javascript">
	<!--
	largeimgs['img-id-name'] = new altimg('src-uri', width, height) ;
	needed for each large img in the document
	 :
	// -->
	</script>

	<body onload="resizeimgs(minwidth, minheight)">

*/
var largeimgs = new Array() ;	// imgs to use when over the window size threshhold
var smallimgs = new Array() ;	// imgs to use then under. These get filled in on first call to resizeimgs

function altimg(srcuri, w, h)	// constructor for alternative img object
{
	this.srcuri = srcuri ;
	this.width = w ;
	this.height = h ;
}

var firsttime = true ;

function resizeimgs(mw, mh)	//	called with minimum width and height to trigger use of larger images
{

	if (firsttime)
	{
		firsttime = false ;
		
		// set the small (original) images, and if IE, doctor the large img names
		for (var imgname in largeimgs) 
		{	
  			var imgobj = document.images[imgname] ;
			if (imgobj)
				smallimgs[imgname] = new altimg(imgobj.src, imgobj.width, imgobj.height) ;

		// if internetexplorer, need to reparse the largeimgs relative to the document root
		
			if (browser == "Internet Explorer")
			{	// IE doesn't interpret relative uris, so I need to parse the srcuri 
				// into the src root
				var url = new String(document.URL) ;	// got the URL, now get the root
				root1 = url.lastIndexOf("/") ;	// either in Unix or
				root2 = url.lastIndexOf("\\") ;	// Windows notation
				if (root1 > root2) root = url.substring(0,root1+1) ;	// include the slash
				else if (root2 > root1) root = url.substring(0,root2+1) ;
				else root = url + "/" ;	// couldn't find any slashes, so append one
				largeimgs[imgname].srcuri = root + largeimgs[imgname].srcuri ;
			}
		}
	}	

	width = window.innerWidth ? window.innerWidth : document.body.offsetWidth ;
	height = window.innerHeight ? window.innerHeight : document.body.offsetHeight ;

	if (width < mw || height < mh) for (var imgname in largeimgs)
	{
		var imgobj = document.images[imgname] ;
		if (imgobj)
		{
			imgobj.src = smallimgs[imgname].srcuri ;
			imgobj.width = smallimgs[imgname].width ;
			imgobj.height = smallimgs[imgname].height ;
		}
	}
	else for (var imgname in largeimgs)
	{
  		var imgobj = document.images[imgname] ;
		if (imgobj)
		{
			imgobj.src = largeimgs[imgname].srcuri ;
			imgobj.width = largeimgs[imgname].width ;
			imgobj.height = largeimgs[imgname].height ;
		}
	}
}
