/*******************************************************************************************
 * hoverNav
 * Written by Craig Francis
 * An ugly solution to getting the hover state with <img> tags, which show an alt tag
 * when the browser has images disabled - rather than nothing, with CSS background images.
 *******************************************************************************************/

	var hoverNav = new function() {

		//--------------------------------------------------
		// Old browsers

			if (!document.getElementById || !document.getElementsByTagName) {
				return;
			}

		//--------------------------------------------------
		// Initialisation

			this.init = function() {

				//--------------------------------------------------
				// Debug

					console.log('hoverNav.js: Initialisation');

				//--------------------------------------------------
				// Get a reference to the nav

					var pageNav = document.getElementById('pageNav');
					if (!pageNav) {
						console.log('hoverNav.js: Could not find reference to "pageNav"');
						return;
					}

				//--------------------------------------------------
				// Process the images

					var imgRegExp = new RegExp('Off\.gif');

					var imgs = pageNav.getElementsByTagName('img');
					for (var k = (imgs.length - 1); k >= 0; k--) {
						if (imgs[k].src.match(/Off\.gif$/)) {

							var parent = getParent(imgs[k], 'a');
							if (!parent) {
								parent = imgs[k];
							}

							parent.hoverNavImg = imgs[k];

							parent.onmouseover = hoverNav.linkOn;
							parent.onfocus = hoverNav.linkOn;
							parent.onmouseout = hoverNav.linkOff;
							parent.onblur = hoverNav.linkOff;

						}
					}

			}

		//--------------------------------------------------
		// Initialisation

			this.linkOn = function() {
				this.hoverNavImg.src = this.hoverNavImg.src.replace(/Off\.gif/, 'Over.gif');
			}

			this.linkOff = function() {
				this.hoverNavImg.src = this.hoverNavImg.src.replace(/Over\.gif/, 'Off.gif');
			}

		//--------------------------------------------------
		// On page load

			addLoadEvent(function() {
				hoverNav.init();
			});

	}
