function init() {
	// initialize Eventhandlers for MouseOver, MouseOut-Events
	setupEventHandler();
}

function setupEventHandler() {

	if (ie || opera) {
		// register Mouse-Handler in IE
		document.onmouseover = HandleMouseover;
		document.onmouseout  = HandleMouseout;
	} else if (ns || safari || firefox || mozilla) {
		// Event-Capturing in NS
		window.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		window.onmouseover = HandleMouseover;
		window.onmouseout  = HandleMouseout;
	}
}

function HandleMouseover(event) {
	var eSrc = null;

	if (ie || opera) {
		eSrc = window.event.srcElement;
	}
	else if(ns || safari || firefox || mozilla) {
		eSrc = event.target;
	}

	if (null == eSrc || null == eSrc.tagName ) {
		return;
	}

	var tagName = eSrc.tagName.toUpperCase();

	// Hover for image buttons
	if (("IMG" == tagName || "INPUT" == tagName) && eSrc.id.indexOf('btn') != -1) {
		doSwapButtonImgMouseOver(eSrc);
	}

	// Hover vor text buttons (check for IMG, TD, SPAN)
	// At the moment only for IE
	if (ie) {
		if ("IMG" == tagName || "TD" == tagName || "SPAN" == tagName) {
			if (null ==  eSrc.id || eSrc.id.indexOf('btn') == -1) {
				return;
			}
			
			var node = getEnclosingDiv(eSrc);
	
			if (null != node && null != node.id && "DIV" == node.tagName.toUpperCase() && node.id.indexOf('btn') != -1) {
				var td = node.getElementsByTagName('TD');
				
				// left image
				doSwapButtonImgMouseOver(td[0].firstChild);
	
				// middle image
				doSwapButtonImgMouseOver(td[1], 'background');
	
				// right image
				doSwapButtonImgMouseOver(td[2].firstChild);
			}
		}
	}
}

function getEnclosingDiv(node) {
	// search the div wich embbeds this node
	var parent = node.parentNode;
	
	if (null == parent) return null;
	
	if (parent.nodeName == 'DIV' ) {
		return parent;
	} else {
		return arguments.callee(parent);
	}
}

function doSwapButtonImgMouseOver(node, attribute) {
	var att = '';

	if (arguments.length == 1) {
		att = 'src';
	} else {
		att = attribute;
	}

	var tokens = node.getAttribute(att).split('.');		// example btnLogin.gif or http://www.domain.com/.../btnLogin.gif
	var imgtype = tokens[tokens.length - 1];			// should return: gif, jpg, etc...

	if (null != imgtype) {
		if (node.getAttribute(att).lastIndexOf('1.' + imgtype) != -1) {
			node.setAttribute(att, node.getAttribute(att).substr(0, node.getAttribute(att).indexOf('.' + imgtype)-1) + '3.' + imgtype);
		}
		if (node.getAttribute(att).lastIndexOf('5.' + imgtype) != -1) {
			node.setAttribute(att, node.getAttribute(att).substr(0, node.getAttribute(att).indexOf('.' + imgtype)-1) + '6.' + imgtype);
		}
	}
}

function doSwapButtonImgMouseOut(node, attribute) {
	var att = '';

	if (arguments.length == 1) {
		att = 'src';
	} else {
		att = attribute;
	}

	var tokens = node.getAttribute(att).split('.');		// example btnLogin.gif or http://www.domain.com/.../btnLogin.gif
	var imgtype = tokens[tokens.length - 1];			// should return: gif, jpg, etc...

	if (null != imgtype) {
		if (node.getAttribute(att).lastIndexOf('3.' + imgtype) != -1) {
			node.setAttribute(att, node.getAttribute(att).substr(0, node.getAttribute(att).indexOf('.' + imgtype)-1) + '1.' + imgtype);
		}
		if (node.getAttribute(att).lastIndexOf('6.' + imgtype) != -1) {
			node.setAttribute(att, node.getAttribute(att).substr(0, node.getAttribute(att).indexOf('.' + imgtype)-1) + '5.' + imgtype);
		}
	}
}


function HandleMouseout(event) {
	var eSrc = null;

	if (ie || opera) {
		eSrc = window.event.srcElement;
	}
	else if(ns || safari || firefox || mozilla) {
		eSrc = event.target;
	}

	if (null == eSrc || null == eSrc.tagName ) {
		return;
	}
	
	var tagName = eSrc.tagName.toUpperCase();
	
	// Hover vor image buttons
	if (("IMG" == tagName || "INPUT" == tagName) && eSrc.id.indexOf('btn') != -1) {
		doSwapButtonImgMouseOut(eSrc);
	}
	
	// Hover vor text buttons
	// At the moment only for IE
	if (ie) {
		if ("IMG" == tagName || "TD" == tagName || "SPAN" == tagName) {
			if (null ==  eSrc.id || eSrc.id.indexOf('btn') == -1) {
				return;
			}

			var node = getEnclosingDiv(eSrc);
	
			if (null != node && null != node.id && "DIV" == node.tagName.toUpperCase() && node.id.indexOf('btn') != -1) {
				var td = node.getElementsByTagName('TD');
				
				// left image
				doSwapButtonImgMouseOut(td[0].firstChild);
	
				// middle image
				doSwapButtonImgMouseOut(td[1], 'background');
				
				// right image
				doSwapButtonImgMouseOut(td[2].firstChild);
			}
		}
	}
}