﻿
// Custom object to keep the global namespace clean.
var Mofo02 = function() {
	return {
		// Add a link tag to the <head> section that loads the js-style.css stylesheet.
		addStylesheet: function() {
			var stylesheet = document.createElement('link');
			stylesheet.setAttribute('rel', 'stylesheet');
			stylesheet.setAttribute('type', 'text/css');
			stylesheet.setAttribute('href', '/WiseAddonsbyJJ/js-style02.css');
			document.getElementsByTagName('head')[0].appendChild(stylesheet);
		},
		// Toggle the trigger's anchor text and the corresponding content's visibility.
		toggleContent: function(a) {
			if (a.parentNode.className == 'article02' || a.parentNode.className == 'article02 hidden') {
				a.parentNode.className = 'article02 visible';
				a.className = 'trigger off';
				a.innerHTML = '<h2>Övriga bolag i koncernen</h2>';
			}
			else {
				a.parentNode.className = 'article02 hidden';
				a.className = 'trigger on';
				a.innerHTML = '<h2>Övriga bolag i koncernen</h2>';
			}
		},
		// Create a trigger link element and insert it above the given contentElement.
		addTrigger: function(contentElement) {
			var trigger = document.createElement('a');
			trigger.className = 'trigger off';
			trigger.innerHTML = '<h2>Övriga bolag i koncernen</h2>';
			trigger.setAttribute('onclick', 'Mofo02.toggleContent(this);');
			trigger.setAttribute('style', 'text-decoration:none;color:black');
			contentElement.parentNode.insertBefore(trigger, contentElement);
		},
		// Find all <div> elements with the 'content' class and add a trigger link.
		makeTriggers: function() {
			var divs = document.getElementsByTagName('div');
			for (var i = 0; i < divs.length; i++) {
				if (divs[i].className == 'content02') {
				    Mofo02.addTrigger(divs[i]);
				}
			}
		},
		// Make sure the page content is loaded before trying to insert triggers.
		addLoadEvent: function() {
			var onLoad = window.onload;
			if (typeof window.onload != 'function') {
			    window.onload = Mofo02.makeTriggers;
			}
			else {
				window.onload = function() {
				    Mofo02.makeTriggers();
					if (onLoad) {
						onLoad();
					}
				}
			}
		}
	};
}();

Mofo02.addStylesheet();
Mofo02.addLoadEvent();

