
	//// BEGIN HEADER ////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	////                                                                                          ////
	////    IMAGEHANDLER. V2.0                                                                    ////
	////                                                                                          ////
	////    Jose Cao-Garcia                                                                       ////
	////                                                                                          ////
	////    This software is licensed under the Creative Commons                                  ////
	////    Attribution-ShareAlike 2.5 License:                                                   ////
	////    <http://creativecommons.org/licenses/by-sa/2.5/legalcode>                             ////
	////                                                                                          ////
	////    HELP/INFO/DEVELOPER CONTACT: jose@jcao.com, http://jcao.com                           ////
	////                                                                                          ////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	////                                                                                          ////
	////    This script provides support for various image-related tasks:                         ////
	////                                                                                          ////
	////    Adds support for 2-bit .png transparency for standards-challenged browsers            ////
	////    (microsoft internet explorer 6), and allows png graphics to be swapped out            ////
	////    dynamically and resized (most msie png support scripts do not allow you to resize     ////
	////    .png graphics).                                                                       ////
	////                                                                                          ////
	////    This file works by assuming you structure your documents meticulously and use         ////
	////    strict image naming conventions. If you do, this file will save you immense amounts.  ////
	////                                                                                          ////
	////    adds support for automating imageStates and Rollovers for any image via a             ////
	////    naming-convention compliance scheme:                                                  ////
	////                                                                                          ////
	////    If an image filename ends in -ovr or -out (before the extension) it is assumed that   ////
	////    this image is an image that needs rollover behaviour. In order for this to work,      ////
	////    both states of such images need to exist in the same directory: so to make an image   ////
	////    with rollover states you need two files the out-state and the over-state, with        ////
	////    matching filename roots and extensions, and the appropriate keyword suffix.           ////
	////    For example:                                                                          ////
	////                                                                                          ////
	////        over state: filanameRoot-ovr.png                                                  ////
	////        out state:  filanameRoot-out.png                                                  ////
	////                                                                                          ////
	////    Finally, if a rollover image is contained directly within a link, and the current     ////
	////    page location is a match for the link, the image will display in the over state       ////
	////    by default.                                                                           ////
	////                                                                                          ////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	//// END HEADER //////////////////////////////////////////////////////////////////////////////////


	var imageHandler = function(scope) {
	// root and scope
		var root            = this;
		root.ie6Help        = (client.engine == 'msie' && parseInt(client.engRev) == 6);
		root.scope          = scope || document.body;
		root.images         = root.scope.getElementsByTagName('img');
	// define naming convention suffixes
		root.ovrStateSuffix = '-ovr';
		root.outStateSuffix = '-out';
	// method determines if element is within scope. Returns obj element or false.
		root.inScope = function(obj) {
			var childObj = obj;
			if (root.scope != document.body) {
			// crawl parents for scope element if scope is reduced
				while (obj != document.body) {
					if (obj == root.scope) { return childObj; }
					obj = obj.parentNode;
				}
			// finally, return false if not found.
				return false;
			} else {
			// no test if scope is entire body
				return childObj
			}
		}
	// method sets imageHandler methods for images
		root.setImgMethods   = function(childScope) {
		// do not permit handling of beyond-scope elements
			var scope  = childScope || root.scope;
			if (!root.inScope(scope)) { throw('imageHandler.setImgMethods - cannot set methods for elements beyond scope of influence for object.') }
			var images = scope.getElementsByTagName('img');
		// loop through images
			for (var i = 0; i < images.length; i++) {
			// name image
				var thisImg = images[i];
			// add methods if image has not been set to be ignored
				if(!thisImg.getAttribute('ignore')) {
					root.addImgSrcSetter(thisImg);
					root.addImgStateSetters(thisImg);
					root.setImageLinkStates(thisImg);
				// special handholding for standards-challenged browsers.
					if (typeof(root.showInIe6) != 'undefined') { root.showInIe6(thisImg); }
				}
			}
		}
	// method cuts imageHandler methods from images
		root.cutImgMethods = function(childScope) {
		// do not permit handling of beyond-scope elements
			var scope  = childScope || root.scope;
			if (!root.inScope(scope)) { throw('imageHandler.setImgMethods - cannot set methods for elements beyond scope of influence for object.') }
			var images = scope.getElementsByTagName('img');
		// loop through images
			for (var i = 0; i < images.length; i++) {
			// name image
				var thisImg = images[i];
			// remove methods/custom attributes
				thisImg.onmouseover = null;
				thisImg.onmouseout  = null;
				thisImg.onmousedown = null;
				thisImg.onmouseup   = null;
				thisImg.ovrState    = null;
				thisImg.outState    = null;
				thisImg.dwnState    = null;
			// set flag to ignore image
				thisImg.setAttribute('ignore', true);
			}
		}
	// method adds image source setting method to an image
		root.addImgSrcSetter = function(thisImg) {
			thisImg.setSrc = function(url) { this.src = url; } 
		}
	// method adds image state setting methods to an image (over, out)
		root.addImgStateSetters = function(thisImg) {
		// get some url info
			var imgSrc         = thisImg.src;                                                                //<-- raw source
			var thisPath       = imgSrc.substring(0, (imgSrc.lastIndexOf('/')+1));                           //<-- path to image
			var thisFile       = imgSrc.substring(imgSrc.lastIndexOf('/')+1).split('#')[0].split('?')[0];    //<-- complete filename
			var thisExtension  = thisFile.substring(thisFile.lastIndexOf('.'));                              //<-- filename extension
			var thisFileName   = thisFile.substring(0, thisFile.lastIndexOf('.'));                           //<-- filename, without extension
		// check for rollover/out naming convention
			var isRollover = (
				(thisFileName.lastIndexOf(root.outStateSuffix) == (thisFileName.length - root.outStateSuffix.length)) ||
				(thisFileName.lastIndexOf(root.ovrStateSuffix) == (thisFileName.length - root.ovrStateSuffix.length))
			)
		// if image naming convention indicates a rollover, append state methods
			if (isRollover) {
			// store path and state filename strings in a custom attribute.
				thisImg.setAttribute('imagpath', thisPath);
				thisImg.setAttribute('ovrimage', thisFile.split(root.outStateSuffix + thisExtension).join(root.ovrStateSuffix + thisExtension));
				thisImg.setAttribute('offimage', thisFile.split(root.ovrStateSuffix + thisExtension).join(root.outStateSuffix + thisExtension));
			// set over/out events
				thisImg.ovrState    = function() { this.setSrc(this.getAttribute('imagpath') + this.getAttribute('ovrimage'));   }
				thisImg.outState    = function() { thisImg.setSrc(this.getAttribute('imagpath') + this.getAttribute('offimage')); }
				thisImg.onmouseover = function() { this.ovrState(); }      // need to add some conditional logic here to prevent flickering in ie 6
				thisImg.onmouseout  = function() { this.outState(); }      // need to add some conditional logic here to prevent flickering in ie 6
			}
		}
	// method sets image state based based on page location, if image is a link.
		root.setImageLinkStates = function(thisImg) {
		// permits you to spoof url, to allow pages with non-matching urls to highlight links.
			var spoofLoc = document.body.getAttribute('spooflocation');
			if (spoofLoc) { window.spoofUrl = document.location.href.substring(0, document.location.href.lastIndexOf('/')) + '/' + spoofLoc; }
			window.spoofUrl = window.spoofUrl || document.location.href;
		// makes image current state
			var makeCurrent = function(thisImg) {
				if (thisImg.onmouseover) { thisImg.onmouseover(); }
				thisImg.onmouseover = null;
				thisImg.onmouseout  = null;
			}
		// if image is a link, and we are at the link destination, set over state and remove over/out events
			if (thisImg.parentNode && thisImg.parentNode.nodeName == 'A') {
				if (thisImg.parentNode.getAttribute('href') != '') {
					var linkURL = thisImg.parentNode.href;
					var linkANC = linkURL.split('#')[1] || false;
					var pageURL = spoofUrl;
					var pageANC = pageURL.split('#')[1] || false;
					if (linkANC) {
					// for anchor links, link must be an exact match
						if (linkURL == pageURL) {
							thisImg.setAttribute('isCurrent', 'true');
							makeCurrent(thisImg);
						}
					} else {
					// for page links, link match can exclude anchor
						if (pageURL.indexOf(linkURL) == 0) {
							thisImg.setAttribute('isCurrent', 'true')
							makeCurrent(thisImg);
						}
					}
				}
			}
		}
	///////////////////////////////////////////////////////////////////////////
	////    BEGIN IE 6 HANDHOLDING ...                                     ////
	///////////////////////////////////////////////////////////////////////////
		if (root.ie6Help) {
		// method adds image source setting method to an image (ie 6 handholding version)
			root.addImgSrcSetter = function(thisImg) {
				thisImg.setSrc = function(url) {
				// check to see if the file is a png graphic.
					var isPng   = (/\.png$/.test(url.split('?')[0]));
				// load image by prefferable method given mime
					if (isPng) {
					// first, look to see if the image has been cached and sized up yet.
						var cachedPngs = document.getElementById('msieSixPngLoaderDiv').getElementsByTagName('img');
						var cachedImg  = false;
						for (var i = 0; i < cachedPngs.length && !cachedImg; i++) {
							var thisPng = cachedPngs[i];
							if (thisPng.src == url) { cachedImg = thisPng; } /// make sure this string test is solid.
						}
					// if there is a cached image use the dimensions from that image for the destination,
					// if not - cache it, calling this method from the the cached image's onload event.
						if (cachedImg) {
							this.style.filter     = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + cachedImg.src + '\', sizingMethod=\'scale\')';
							this.src              = './global/img/blank.gif';
							this.style.width      = cachedImg.offsetWidth + 'px';
							this.style.height     = cachedImg.offsetHeight + 'px';
							this.style.visibility = 'visible';
						} else {
							var pngLoaderDiv = document.getElementById('msieSixPngLoaderDiv');
							var newCacheImg  = document.createElement('img');
								newCacheImg.setAttribute('iscacheimg', 'true');
								newCacheImg  = pngLoaderDiv.appendChild(newCacheImg);
								var callBack = this;                                   //<!-- we need to inject this into the onload event of the new cache image
								newCacheImg.onload = function() {
										callBack.style.width      = this.offsetWidth + 'px';
										callBack.style.height     = this.offsetHeight + 'px';
										callBack.style.filter     = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.src + '\', sizingMethod=\'scale\')';
										callBack.src              = './global/img/blank.gif';
										callBack.style.visibility = 'visible';
										if (this != cachedPngs[0]) { cachedPngs[0].onload(); } //<!-- this is a hack, that could cause problems ... must identify/implement the real solution
								}
								newCacheImg.src = url;
						}
					} else {
					// set source normally, and remove any enforced scaling so image scales naturally
						this.style.filter  = null; //<!-- remove any prior "filter" crap from image
						this.src           = url;  //<!-- set source
						this.style.width   = '';   //<!-- remove any prior scale enforcement
						this.style.height  = '';   //<!-- remove any prior scale enforcement
					}
				}
			}
		// fix a png's graphic display in IE 6 if not set by the setSrc method
			root.showInIe6 = function(thisImg) {
				if (!thisImg.getAttribute('iscacheimg')) {
					var isPng   = (/\.png$/.test(thisImg.src.split('?')[0]));
 					if (isPng && !thisImg.getAttribute('iscacheimg')) { thisImg.setSrc(thisImg.src); }
				}
			}
		// creates a hidden div for ie6 to cache png images in ... 
			root.makeIe6PngCache = function() {
			// DOM ref for pngLoader div
				window.msieSixPngLoaderDiv = document.getElementById('msieSixPngLoaderDiv');
			// create for pngLoader div if doesn't allready exist
				if (!msieSixPngLoaderDiv) {
					msieSixPngLoaderDiv           = document.createElement('div');
				// prevent preload div from affecting layout
					window.msieSixPngLoaderDiv.style.visibility = 'hidden';
					window.msieSixPngLoaderDiv.style.overflow   = 'hidden';
					window.msieSixPngLoaderDiv.style.position   = 'absolute';
					window.msieSixPngLoaderDiv.style.width      = '1px';
					window.msieSixPngLoaderDiv.style.height     = '1px';
					window.msieSixPngLoaderDiv.style.top        = '-1px';
					window.msieSixPngLoaderDiv.style.left       = '-1px';
					window.msieSixPngLoaderDiv.style.padding    = '0px';
					window.msieSixPngLoaderDiv.style.margin     = '0px';
				// insert it in the bottom of the render tree ( where it will be less likely to affect layout )
					msieSixPngLoaderDiv           = document.body.insertBefore(msieSixPngLoaderDiv, document.body.getElementsByTagName('*')[0]);
					msieSixPngLoaderDiv.id        = 'msieSixPngLoaderDiv';
					msieSixPngLoaderDiv.innerHTML = '<!-- this div permits unobtrusive preloading and measurement of .png images in IE 6, for transparency support -->';
				}
			}
		// add the IE6PngCache to the HTML document.
			root.makeIe6PngCache();
		}
	///////////////////////////////////////////////////////////////////////////
	////    END IE 6 HANDHOLDING ...                                       ////
	///////////////////////////////////////////////////////////////////////////
		root.setImgMethods();
	}



