//<script>
// Image Effect Engine
//
// Miller Hare image effect library v1.0
// 04/04/2006 Miller Hare Limited
			
// Fade effect inspired by http://www.clagnut.com/sandbox/imagefades/
			
var MHL_imageEffectEngine = new ImageEffectEngine();
						
			
function ImageEffectEngine() {
	this.imgs = [];
				
	this.register = function(imageID, initiallyVisible) {
		var op = (initiallyVisible)?1:0;
		this.imgs.push({
					id: imageID,
					startVisible: initiallyVisible,
					opacity: op,
					imgObj: null,
					xfadeObj: null
				});
	};
				
	this.writeCSS = function() {
		document.write("<style type='text/css'>");
					
		for (var i=0; i<this.imgs.length; i++) {
			if (!this.imgs[i].startVisible) {
				document.write("#" + this.imgs[i].id + " {visibility:hidden;}");
			}
		}
					
		document.write("<" + "/style>");
				
	};
				
	this.getImageIndex = function(imageID) {
		for (var i=0; i<this.imgs.length; i++) {
			if (this.imgs[i].id == imageID) {
				return i;
			}
		}
		return -1;
	};
				
	this.fade = function(imageElement, opStepAmount) {
		var imageIndex = this.getImageIndex(imageElement.id);
					
		if (imageIndex>=0) {
			imageElement.style.visibility = 'visible';
			this.imgs[imageIndex].imgObj = imageElement;
			this.fadeAgain(imageIndex, opStepAmount);
		}
	};
	
	this.xfade = function(imageElement, xfadeElement, opStepAmount) {
		var imageIndex = this.getImageIndex(imageElement.id);
					
		if (imageIndex>=0) {
			if (xfadeElement) {
				this.setOpacity(xfadeElement, 1);
				this.setOpacity(imageElement, 0);
				xfadeElement.style.visibility = 'visible';
				this.imgs[imageIndex].xfadeObj = xfadeElement;
				this.imgs[imageIndex].opacity = 0;
			} else {
				this.imgs[imageIndex].xfadeObj = null;
			}
			imageElement.style.visibility = 'visible';
			
			this.imgs[imageIndex].imgObj = imageElement;
			this.fadeAgain(imageIndex, opStepAmount);
		}
	};
				
	this.fadeAgain = function(imageIndex, opStepAmount) {
		var img = this.imgs[imageIndex];
		var lastIteration = false;
		var iee = this;
					
		img.opacity += opStepAmount;
		if (img.opacity <= 0) {
			img.opacity = 0;
			lastIteration = true;
		}
		if (img.opacity >= 1) {
			img.opacity = 1;
			lastIteration = true;
		}
					
		this.setOpacity(img.imgObj, img.opacity);
		if (img.xfadeObj) {
			this.setOpacity(img.xfadeObj, 1-img.opacity);
		}
					
		if(!lastIteration) {
			window.setTimeout(function() {
					iee.fadeAgain(imageIndex, opStepAmount);
				}, 50);
		} else {
			if (img.xfadeObj) {
				img.xfadeObj.style.visibility = 'hidden';
				img.xfadeObj.style.display = 'none';
				img.xfadeObj.src = img.imgObj.src;
				img.xfadeObj.style.width = img.imgObj.style.width;
				img.xfadeObj.style.height = img.imgObj.style.height;
				img.xfadeObj = null;
			}
		}
	};
				
	this.setOpacity = function(el, op) {
				
		op = (op == 1)?0.9999:op;
					
		el.style.filter = "alpha(opacity:"+op*100+")";
		el.style.MozOpacity = op;
		el.style.KHTMLOpacity = op;
		el.style.opacity = op;
	};
	
	this.prepareForXFade = function(el, xfadeel, opStepAmount) {
	
		//xfadeel.src = el.src;
		if (xfadeel.style.visibility != 'visible') {
			xfadeel.style.visibility = 'visible';
			xfadeel.style.display = 'block';
			this.setOpacity(xfadeel, 1);
		
			xfadeel.style.top = el.style.top;
			xfadeel.style.left = el.style.left;
		}
		el.style.visibility = 'hidden';
		el.style.display = 'block';
		this.setOpacity(el, 0);
		
		if (!el.onload) {
			var iee = this;
			el.onload = function() {
				iee.xfade(el, xfadeel, opStepAmount);
			};
		}
	};
	
	this.centreInParent = function(el, elWidth, elHeight, topPad, leftPad, topOffset, leftOffset) {
		var w, h;
		var pw, ph;
		var tp, lp;
		
		if (el.parentNode) {
			
			
			w = (elWidth != undefined)?elWidth:el.width;
			h = (elHeight != undefined)?elHeight:el.height;
			tp = (topPad != undefined)?topPad:0;
			lp = (leftPad != undefined)?leftPad:0;
			
			
			el.style.position = 'absolute';
			el.style.width = w + 'px';
			el.style.height = h + 'px';
			
			
			el.style.top = '0px';
			el.style.left = '0px';
			
			pw = el.parentNode.offsetWidth;
			ph = el.parentNode.offsetHeight;
			//ph = pw; //treat as a square box;
			
			el.style.top = (ph-h)/2 + tp - topOffset + 'px';
			el.style.left = (pw-w)/2 + lp - leftOffset - leftOffset + 'px';
		}
	};
	
	this.overbutton = function(el, entering) {
		if (el) {
			if (entering) {
				el.oldsrc = el.src;
				el.src = el.src.replace(/(\.\w+)$/, '_over$1');
			} else {
				el.src = el.oldsrc;
			}
		}
	}
}