var Ontbossing = {
	kosmik: {src: '/swf/website/kosmik.swf'},
	flashMenu: {},
	privacyEffect: {},
	privacyHeight: 0,

	/*
	 * Prepare
	 */
	init: function () {
		this.prepareSifr();

		var that = this;
		window.addEvent('domready', function () {
			that.preparePrivacy();
			that.doSifr();
			that.placeMenu();
		});

		$$('head')[0].adopt(
			new Element('link', {rel: 'stylesheet', media: 'screen, projection', href: '/css/js.css', type: 'text/css'})
		);
	},

	/*
	 * Stop sIFR from auto-starting
	 */
	prepareSifr: function () {
		sIFR.registerEvents = false;
	},

	/*
	 * Transform the <h2> with sIFR
	 */
	doSifr: function () {
		sIFR.initialize();
		sIFR.activate();

		sIFR.replace(this.kosmik, {
			selector: 'h2',
			wmode: 'transparent',
			css: {
				'.sIFR-root': {
					'color': '#B54E02'
				}
			}
		});
	},

	/*
	 * Replace the HTML imagemap with a Flash menu
	 */
	placeMenu: function () {
		var urls = {
			startPaginaURL: $$('#nav-startpagina a')[0].get('href'),
			zuidAmerikaURL: $$('#nav-paviljoen-zuid-amerika a')[0].get('href'),
			afrikaURL: $$('#nav-paviljoen-afrika a')[0].get('href'),
			azieURL: $$('#nav-paviljoen-azie a')[0].get('href'),
			watURL: $$('#nav-wat-kun-jij-doen a')[0].get('href'),
			blijfURL: $$('#nav-blijf-op-de-hoogte a')[0].get('href'),
			partnersURL: $$('#nav-partners a')[0].get('href')
		}

		var menuOptions = {
			id: 'flashmenu',
			width: 270,
			height: 500,
			vars: urls,
			container: $('menu')
		}

		this.flashMenu = new Swiff('/swf/website/menu.swf', menuOptions);
	},

	/*
	 * Set the cool privacy statement effect
	 */
	preparePrivacy: function () {
		if ($('privacy-statement')) {
			//$('privacy-statement').setStyle('height', 0);

			var that = this;

			var form = $('privacy-statement').getParent();
			form.grab(
				new Element('p', {id: 'privacy-link'}).grab(
					new Element('a', {href: '#', text: 'Privacy bepaling'}).addEvent('click', function () {
						that.showHidePrivacy.apply(that);
						return false;
					})
				)
			)

			this.privacyEffect = new Fx.Tween($('privacy-statement'), {property: 'height'});
		}
	},
	
	/*
	 * Show or hide the privacy text
	 */
	showHidePrivacy: function () {
		var currentHeight = $('privacy-statement').getSize().y;

		//show the privacy text
		if (currentHeight == 0) {

			//briefly show the element to measure it
			$('privacy-statement').setStyle('height', 'auto');
			var newHeight = $('privacy-statement').getSize().y;
			$('privacy-statement').setStyle('height', 0);

			this.privacyEffect.start(0, newHeight);

		//hide the privacy text
		} else {
			this.privacyEffect.start(0);
		}
	}
}

Ontbossing.init();