var showbackground;

function isMouseLeaveOrEnter(e, handler)
{		
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function transparant(obj, opac) {
	transparant.prototype.transIn = transIn;
	transparant.prototype.transOut = transOut;
	transparant.prototype.trans = trans;
	
	var construct = eval(this);
	this.obj = obj;
	this.background = document.getElementById("background" + obj.id);
	this.fps = 25;
	this.minTrans = 50;
	this.maxTrans = 90;
	this.lengthAnimation = 500;
	this.stepWidth = (this.maxTrans - this.minTrans) / (this.fps / 1000 * this.lengthAnimation);
	this.timerIn = 0;
	this.timerOut = 0;
	this.opacity = opac;
	
	construct.background.style.opacity = construct.opacity / 100;
	construct.background.style.filter = "alpha(opacity=" + construct.opacity + ")"
	
	if (construct.obj.addEventListener) {
		construct.obj.addEventListener("mouseover", function(event) {
		transIn(event);
		}, false);
		construct.obj.addEventListener("mouseout", function(event) {
		transOut(event);
		}, false);
	} else {
		construct.obj.attachEvent("onmouseover", function() {
		transIn(event);
		});
		construct.obj.attachEvent("onmouseout", function() {
		transOut(event);
		});
		construct.background.attachEvent("onmouseover", function() {
		transIn(event);
		});
		construct.background.attachEvent("onmouseout", function() {
		transOut(event);
		});
	}
	

	function transIn(evenement) {
		if (isMouseLeaveOrEnter(evenement, construct.obj)) {
			if (!showbackground) {
				clearInterval(construct.timerOut);
				clearInterval(construct.timerIn);
				construct.timerIn = setInterval(function() {
					trans("in");
				}, 1000 / construct.fps);
			}
		}
	}
	
	function transOut(evenement) {
		if (isMouseLeaveOrEnter(evenement, construct.obj)) {
			if (!showbackground) {
				clearInterval(construct.timerIn);
				clearInterval(construct.timerOut);
				construct.timerOut = setInterval(function() {
					trans("out");
				}, 1000 / construct.fps);
			}
		}
	}
	
	function trans(richting) {
	if (!showbackground) {
		if (richting == "in") {
			construct.opacity += construct.stepWidth;
			construct.background.style.opacity = (construct.opacity / 100);
			construct.background.style.filter = "alpha(opacity=" + construct.opacity + ")";
			
			if (construct.opacity >= construct.maxTrans) {
				construct.background.style.opacity = (construct.maxTrans / 100);
				construct.opacity = construct.maxTrans;
				clearInterval(construct.timerIn);
			}
			
		} else {
			construct.opacity -= construct.stepWidth;
			construct.background.style.opacity = (construct.opacity / 100);	
			construct.background.style.filter = "alpha(opacity=" + construct.opacity + ")";
			
			if (construct.opacity <= construct.minTrans) {
				construct.background.style.opacity = (construct.minTrans / 100);
				construct.opacity = construct.minTrans;
				clearInterval(construct.timerOut);
			}
		}
	} else {
		clearInterval(construct.timerIn)
		clearInterval(construct.timerOut)
	}
	
	}

}

