﻿iv = {
	//CSS classes
	dynamicClass: 'dyn',
	currentLinkClass: 'current',
	showClass: 'show',

	//IDs
	parentID: 'listWrapper',
	tocID: 'toolinfotoc',

	//Global properties
	current: null,
	sections: [],
	sectionLinks: [],

	init: function() {
		var targetName, targetElement;
		if (!document.getElementById || !document.createTextNode) {
			return;
		}
		var parent = document.getElementById(iv.parentID);
		var toc = document.getElementById(iv.tocID);
		if (!parent || !toc) {
			return;
		}
		DOMhelp.cssjs('add', parent, iv.dynamicClass);

		var toclinks = toc.getElementsByTagName('a');
		for (var i = 0; i < toclinks.length; i++) {
			DOMhelp.addEvent(toclinks[i], 'click', iv.getSection, false);
			targetName = toclinks[i].getAttribute('href').replace(/.*#/, '');
			toclinks[i].targetName = targetName;

			if (i == 0) {
				var presetLink = targetName;
			}
			targetElement = document.getElementById(targetName);
			if (targetElement) {
				iv.sections[targetName] = targetElement.parentNode.parentNode;
				iv.sectionLinks[targetName] = toclinks[i];
			}
		}
		var loc = window.location.hash.replace('#', '');
		loc = document.getElementById(loc) ? loc : presetLink;
		iv.showSection(loc);
	},

	getSection: function(e) {
		var t = DOMhelp.getTarget(e);
		iv.showSection(t.targetName);
	},

	showSection: function(sectionName) {
		if (iv.current != null) {
			DOMhelp.cssjs('remove', iv.sections[iv.current], iv.showClass);
			DOMhelp.cssjs('remove', iv.sectionLinks[iv.current], iv.currentLinkClass);
			iv.current = sectionName;
		}
		DOMhelp.cssjs('add', iv.sections[sectionName], iv.showClass);
		DOMhelp.cssjs('add', iv.sectionLinks[sectionName], iv.currentLinkClass);
		iv.current = sectionName;
	}
}
DOMhelp.addEvent(window, 'load', iv.init, false);

var dropdown = {
    init: function() {
        //startList = function() {
        if (document.all && document.getElementById) {
            navRoot = document.getElementById("nav");
            for (i = 0; i < navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName == "LI") {
                    node.onmouseover = function() {
                        this.className += " over";
                    }
                    node.onmouseout = function() {
                        this.className = this.className.replace(" over", "");
                    }
                }
            }
        }
    }
}
DOMhelp.addEvent(window, 'load', dropdown.init, false);

//}
//window.onload = startList;

//var heading = {
//    init: function() {
//        if (!document.getElementById || !document.createTextNode) {
//            return;
//        }
//        var navRoot = document.getElementById("searchPage");
//        var headings = navRoot.getElementsByTagName("h2");
//        for (i = 0; i < heading.length; i++) {
//            headings[i].onmouseover = function() {
//                this.className += " over";
//            }
//            headings[i].onmouseout = function() {
//                this.className = this.className.replace(" over", "");
//            }
//        }
//    }
//}
//DOMhelp.addEvent(window, 'load', heading.init, false);

var tables = {
	init: function() {
		if (!document.getElementById || !document.createTextNode) {
			return;
		}
		var tabell = document.getElementsByTagName("table");
		//if (tabell.className.indexOf('sustain') !=-1) return;
		for (var j = 0; j < tabell.length; j++) {
			if (tabell[j].className.indexOf("noscript") < 0) {
				var rows = tabell[j].getElementsByTagName("tr");
				for (i = 0; i < rows.length; i++) {
					//manipulate rows
					if (i % 2 == 0) {
						rows[i].className = " even";
					} else {
						rows[i].className = " odd";
					}
				}
			}
		}
	}
}
DOMhelp.addEvent(window, 'load', tables.init, false);

$(function() {
	var head = $("#info-widget > dl.head");

	var infoBoxes = head.find("> dd");

	function findMaxHeightOfInfoBoxes() {
		var maxHeight = 0;

		infoBoxes.each(function() {
			var height = $(this).height();

			if (height > maxHeight) {
				maxHeight = height;
			}
		});

		return maxHeight;
	}

	infoBoxes.css("height", findMaxHeightOfInfoBoxes() + "px");

	var selectedInfoBox = null;

	head.find("> dt > span.title").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	}).click(function() {
		var className = $(this).parent().attr("class");

		var designatedInfoBox = head.find("> dd" + "." + className);

		var visibleSiblings = head.find("> dd:visible").not(designatedInfoBox);

		if (selectedInfoBox && selectedInfoBox[0] == designatedInfoBox[0]) {
			//$("#info-widget")[0].style.height = "0px";

			if ($.browser.msie && $.browser.version.substr(0, 1) == 7) {
				designatedInfoBox.find("div").slideUp();
			}
			designatedInfoBox.slideUp("normal", function() {
				selectedInfoBox = null;
			});
		} else {
			selectedInfoBox = designatedInfoBox;

			if (visibleSiblings.length > 0) {
				visibleSiblings.fadeOut("normal", function() {
					designatedInfoBox.find("div").fadeIn("normal");
					designatedInfoBox.fadeIn("normal");
				}).find("div").fadeOut("normal");
			} else {
				designatedInfoBox.find("div").show();
				if ($.browser.msie && $.browser.version.substr(0, 1) == 7) {
					designatedInfoBox.find("div").slideDown();
				}
				designatedInfoBox.slideDown("normal", function() {
					//$("#info-widget")[0].style.height = head.outerHeight() + "px";
				});
			}
		}
	});
});

