window.onload = init;

var popupFeatures = 'location=0,status=0,menubar=0,toolbar=0,directories=0,scrollbars=1,width=450,height=400'; // The specifications for the default popup page
PreloaderImage = new Image(); // An image object to hold the preloaded mouseover images


function init() {
	if (!document.getElementsByTagName)
		return;
	InitMenuDropdownActions();
	InitImageRollovers();
}

function InitImageRollovers() {
	var all_A = document.getElementsByTagName("a");
	for (var i = 0;i < all_A.length; i++) {
		var thisA = all_A[i];
		if (thisA.className && thisA.className == 'imgrollover') {
			if (thisA.childNodes && thisA.childNodes.length == 1 && thisA.childNodes[0].nodeName.toLowerCase() == 'img') {
				thisA.onmouseover = ImageRollover;
				thisA.onmouseout = ImageRollout;
				PreloadImage(thisA);
			}
		}
		if (thisA.className && (thisA.className == 'popup'))
			thisA.onclick = event_popup;
	}
	var all_img = document.getElementsByTagName("img");
	for (var i = 0;i < all_img.length; i++) {
		var thisimg = all_img[i];
		if (thisimg.className && thisimg.className == 'imgrollover') {
			thisimg.onmouseover = ImageRollover;
			thisimg.onmouseout = ImageRollout;
			PreloadImage(thisimg);
		}
	}
}

function ImageRollover(e) {
	var target = find_target(e);
	if (!target) return;
	if (target.nodeName.toLowerCase() == 'a')
		var img_tag = target.childNodes[0];
	else
		var img_tag = target;
	if (target.parentNode.parentNode.className != 'highlight' && target.parentNode.parentNode.className != 'current')
		img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, '_on$1');
}

function ImageRollout(e) {
	var target = find_target(e);
	if (!target) return;
	if (target.nodeName.toLowerCase() == 'a')
		var img_tag = target.childNodes[0];
	else
		var img_tag = target;
	if (target.parentNode.parentNode.className != 'highlight' && target.parentNode.parentNode.className != 'current')
		img_tag.src = img_tag.src.replace(/_on(\.[^.]+)$/, '$1');
}

// menu dropdowns for IE
function InitMenuDropdownActions() {
	if (document.getElementById("menubar")) {
		var menuLIs = document.getElementById("menubar").getElementsByTagName("LI");
		for (var i = 0;i < menuLIs.length; i++) {
			menuLIs[i].onmouseover=function() {
				if (document.all) this.className+=" sfhover";
			}
			menuLIs[i].onmouseout=function() {
				if (document.all) this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}


function PreloadImage(target) {
	if (target.nodeName.toLowerCase() == 'a')
		var img_tag = target.childNodes[0];
	else
		var img_tag = target;
	// Preload mouseovers
	if (img_tag.parentNode.parentNode.className != 'highlight' && img_tag.parentNode.parentNode.className != 'current') {
		var ImgToLoad = img_tag.src.replace(/(\.[^.]+)$/, '_on$1');
		PreloaderImage.src = ImgToLoad;
	}
}

function event_popup(e) {
	var eventTarget = find_target(e);
	if (!eventTarget) return;
	var features = popupFeatures;
    if (eventTarget.getAttribute('popup'))
		var features = eventTarget.getAttribute('popup');
	var thisTarget = '_blank';
    if (eventTarget.getAttribute('target'))
		var thisTarget = eventTarget.getAttribute('target');
    var theWindow = window.open(eventTarget.getAttribute('href'), thisTarget, features);
    theWindow.focus();
    return false;
}

function find_target(e) {
	var target; 
	if (window.event && window.event.srcElement) 
		target = window.event.srcElement;
	else if (e && e.target)
		target = e.target;
	if (!target)
		return null;
	return target;
}