var ButtonFunctions = {
	print_buttons : [],
	printActions : function(e) {
		Core.preventDefault(e);
		Core.stopPropagation(e);
		window.print();
	},
	init : function() {
		var print_button = document.getElementById('print-button');
		if(print_button)
		{
			Core.removeClass(print_button,'no-script');/* added to remove the display hidden from the print buttons */
			Core.addEventListener(print_button, 'click', ButtonFunctions.printActions);
			ButtonFunctions.print_buttons.push(print_button);
		}
	}
};
var SettingsLightbox = {
	init : function() {
		var settings_link = document.getElementById('instellingen');
		if (settings_link
				&& settings_link.href.indexOf('toon_popup_settings') < 0) {
			settings_link.href = settings_link.href + '/toon_popup_settings';
		};
	}
};

var showEurLex = {
	saveCookie : function(e) {
		var today = new Date();
		today.setTime(today.getTime());
		var expires = 30 * 1000 * 60 * 60 * 24;
		var expires_date = new Date(today.getTime() + (expires));
		document.cookie = 'eurlex' + "=" + this.checked
				+ ((expires) ? ";expires=" + expires_date.toGMTString() : "")
				+ ";path=/";
	},
	init : function() {
		var showEurLex_checkbox= document.getElementById('showEurLex');
		if (showEurLex_checkbox)
		{
			Core.addEventListener(showEurLex_checkbox, 'click', showEurLex.saveCookie);
		}
			
	}
};


var BreadCrumPage = {
	cookiesetter : function() {
		var today = new Date();
		today.setTime(today.getTime());
		var expires = 30 * 1000 * 60 * 60 * 24;
		var expires_date = new Date(today.getTime() + (expires));
		document.cookie = 'last_page' + "=" + ";path=/"
				+ ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		document.cookie = 'bc_click' + "="
				+ ((expires) ? ";expires=" + expires_date.toGMTString() : "")
				+ ";path=/";
		document.cookie = 'last_page' + "=" + escape(document.location)
				+ ((expires) ? ";expires=" + expires_date.toGMTString() : "")
				+ ";path=/";
	},
	setBreadCrumbClickCookie : function(crumb_location) {
		var today = new Date();
		today.setTime(today.getTime());
		var expires = 30 * 1000 * 60 * 60 * 24;
		var expires_date = new Date(today.getTime() + (expires));
		document.cookie = 'bc_click' + "=" + ";path=/"
				+ ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		document.cookie = 'bc_click' + "=" + escape(crumb_location)
				+ ((expires) ? ";expires=" + expires_date.toGMTString() : "")
				+ ";path=/";
	},
	breadCrumbLink : function(e) {
		BreadCrumPage.setBreadCrumbClickCookie(this.href);
	},
	selectBreadCrumOption : function(e) {
		var breadcrumb_select = document.getElementById('broodkruimel_select');
		if (breadcrumb_select.selectedIndex != 0) {
			tmp_location = breadcrumb_select.options[breadcrumb_select.selectedIndex].value
					+ '';
			BreadCrumPage.setBreadCrumbClickCookie(tmp_location);
			if (tmp_location.indexOf('#') > 0) {
				bread_location = tmp_location.substring(0, tmp_location
								.indexOf('#'));
				if (document.location + ''.substring(0, bread_location.length) == bread_location) {
					var total_options = breadcrumb_select.options;
					var selected_index = breadcrumb_select.selectedIndex;
					for (i = total_options.length - 1; i >= selected_index; i--) {
						breadcrumb_select.removeChild(total_options[i]);
					}
				};
			};
			document.location = tmp_location;
		};
	},
	init : function() {
		if (document.getElementById('broodkruimels')) {
			document.getElementById('broodkruimels').style.visibility = 'visible';
			BreadCrumPage.cookiesetter();
			if (document.getElementById('broodkruimel_select')) {
				Core.addEventListener(document
								.getElementById('broodkruimel_select'),
						'change', BreadCrumPage.selectBreadCrumOption);
			};
			var breadcrumAnchors = document.getElementById('broodkruimels')
					.getElementsByTagName('a');
			for (i = 0; i < breadcrumAnchors.length; i++) {
				Core.addEventListener(breadcrumAnchors[i], 'click',
						BreadCrumPage.breadCrumbLink);
			};
		};
		if (document.getElementById('terug_regeling')) {
			Core.addEventListener(document.getElementById('terug_regeling'),
					'click', BreadCrumPage.breadCrumbLink);
		};
	}
};
var PreviousNext = {
	setLinks : function() {
		var previous = previous_link;
		var next = next_link;
		for (x in total_links) {
			if (current_el_id == false || total_links[x] == current_el_id) {
				var last_index = Number(x) - 1;
				var next_index = Number(x) + 1;
				var current_url = tmp_location.substring(0, tmp_location
								.indexOf('#'));
				if (total_links[last_index]) {
					last_anchor = document.getElementById('TOC_anchor_'
							+ total_links[last_index]).name;
					previous = current_url + '#' + last_anchor;
				};
				if (total_links[next_index]) {
					next_anchor = document.getElementById('TOC_anchor_'
							+ total_links[next_index]).name;
					next = current_url + '#' + next_anchor;
				};
				break;
			};
		};
		if (next != false) {
			document.getElementById('volgende').href = next;
		};
		if (previous != false) {
			document.getElementById('vorige').href = previous;
		};
	},
	clickedLink : function() {
		tmp_location = document.location.toString();
		if (tmp_location.indexOf('#') > -1) {
			var anchor = tmp_location
					.substring((tmp_location.indexOf('#') + 1));
			var current_el = document.getElementsByName(anchor).item(0);
			if (current_el) {
				current_el_id = current_el.id.substring(11);
			};
		};
		PreviousNext.setLinks();
	},
	init : function() {
		previous_link = false;
		next_link = false;
		total_links = new Array();
		if (document.getElementById('huidige_regelings_zoekresultaten')) {
			total_links = document
					.getElementById('huidige_regelings_zoekresultaten').value
					.split('-');
			var itemsAnchors = document.getElementById('resultaat-navigatie')
					.getElementsByTagName('a');
			for (i = 0; i < itemsAnchors.length; i++) {
				if (Core.hasClass(itemsAnchors[i], 'vorige')) {
					previous_link = itemsAnchors[i].href;
				} else if (Core.hasClass(itemsAnchors[i], 'volgende')) {
					next_link = itemsAnchors[i].href;
				};
			};
		};
		tmp_location = document.location.toString();
		current_el_id = false;
		if (tmp_location.indexOf('#') > -1) {
			var anchor = tmp_location
					.substring((tmp_location.indexOf('#') + 1));
			var current_el = document.getElementsByName(anchor).item(0);
			if (current_el) {
				current_el_id = current_el.id.substring(11);
			};
		};
		PreviousNext.setLinks();
		if (document.getElementById('vorige')) {
			Core.addEventListener(document.getElementById('vorige'), 'click',
					PreviousNext.clickedLink);
		};
		if (document.getElementById('volgende')) {
			Core.addEventListener(document.getElementById('volgende'), 'click',
					PreviousNext.clickedLink);
		};
	}
};
var Buttons = {
	init : function() {
		ButtonFunctions.init();
		SettingsLightbox.init();
		BreadCrumPage.init();
		PreviousNext.init();
		showEurLex.init();
	}
};
Core.start(Buttons);