Event.observe(window, 'load', function()
{	
	// initialisatie van de menu items...
	
		var menu			= new Menu();
		var doneer			= new Doneer();
		var poll			= new Poll();
		var resizer 		= new Resizer();
		var slideshow		= new SlideShow();
		var selectormenus	= new SelectorMenus();
		
	// flash animatie voor de header
		
		swfobject.embedSWF("/flash/header.swf", "flash", "960", "100", "9.0.0", "/flash/expressInstall.swf", {}, {wmode:"transparent"});
		
		if ($('donation_flash'))
		{
			swfobject.embedSWF("/flash/trailer.swf", "donation_flash", "142", "142", "9.0.0", "/flash/expressInstall.swf", {}, {wmode:"transparent"});
		}
		
	// projectbar
		
		if ($('carrousel_1'))
		{
			imageScrollCollection = new ImageScrollCollection();
			imageScrollCollection.addImageScroll('carrousel_1','lr',true,true,true,true);
			
			var options	= {'MaxSize':90, 'Margin':40};
			var fisheye = new FishEyeToolBar('carrousel_1', options);
		}
		
		if ($('submit_mailafriend'))
		{
			
			Event.observe($('submit_mailafriend'), 'click', function()
			{ 
				$('form_mailafriend').submit();
			}.bind(this));
		}

		if ($('stuur_door'))
		{
			Event.observe($('stuur_door'), 'click', function()
			{ 
				if (!$('mailafriend').visible())
				{
					$('mailafriend').show();
				}
				else
				{
					$('mailafriend').hide();
				}
				
			}.bind(this));
		}
		
		if ($('results_close'))
		{
			Event.observe($('results_close'), 'click', function()
			{ 
				if (!$('results_close').visible())
				{
					$('results_close').show();
					$('results').show();
				}
				else
				{
					$('results_close').hide();
					$('results').hide();
				}
				
			}.bind(this));
		}
		
		Event.observe($('query'), 'mousedown', function()
		{
			$('results_close').show();
					$('results').show();
		}.bind(this));
		
		
		
		if ($('tab_button_1'))
		{
			Event.observe($('tab_button_1'), 'click', function()
			{ 
				if (!$('tab_1').visible())
				{
					$('tab_button_1').addClassName("active");
					$('tab_button_2').removeClassName("active");
					$('tab_button_3').removeClassName("active");
					$('tab_button_4').removeClassName("active");
					$('tab_1').show();
					$('tab_2').hide();
					$('tab_3').hide();
					$('tab_4').hide();
				}
			}.bind(this));
			
			Event.observe($('tab_button_2'), 'click', function()
			{ 
				if (!$('tab_2').visible())
				{
					$('tab_button_1').removeClassName("active");
					$('tab_button_2').addClassName("active");
					$('tab_button_3').removeClassName("active");
					$('tab_button_4').removeClassName("active");
					
					$('tab_1').hide();
					$('tab_2').show();
					$('tab_3').hide();
					$('tab_4').hide();
				}
			}.bind(this));
			
			Event.observe($('tab_button_3'), 'click', function()
			{ 
				if (!$('tab_3').visible())
				{
					$('tab_button_1').removeClassName("active");
					$('tab_button_2').removeClassName("active");
					$('tab_button_3').addClassName("active");
					$('tab_button_4').removeClassName("active");
					
					$('tab_1').hide();
					$('tab_2').hide();
					$('tab_3').show();
					$('tab_4').hide();
				}
			}.bind(this));
			
			Event.observe($('tab_button_4'), 'click', function()
			{ 
				if (!$('tab_4').visible())
				{
					$('tab_button_1').removeClassName("active");
					$('tab_button_2').removeClassName("active");
					$('tab_button_3').removeClassName("active");
					$('tab_button_4').addClassName("active");
					
					$('tab_1').hide();
					$('tab_2').hide();
					$('tab_3').hide();
					$('tab_4').show();
				}
			}.bind(this));
		}
		
});

var SelectorMenus = Class.create(
{
	initialize: function()
	{
		this.menus	= new Array();
		
		$$('.selector').each(function(selector)
		{
			this.menus[this.menus.length] = new SelectorMenu(selector);
		}.bind(this));
	}
});

var SelectorMenu = Class.create(
{
	initialize: function(item)
	{
		this.item	= item;
		
		Event.observe(this.item, 'mouseover', function(){ this.mouseOver(); }.bind(this));
		Event.observe(this.item, 'mouseout', function(){ this.mouseOut(); }.bind(this));
	},
	mouseOver: function()
	{
		this.item.down('ul').show();
	},
	mouseOut: function()
	{
		
		this.item.down('ul').hide();
	}
});

var SlideShow = Class.create(
{
	initialize: function()
	{
		this.images = new Array();
		this.text 	= new Array();
		this.index 	= 0;
		
		//hide all of the slideshow images and dump the images into an array
		$$('#traileritems .item').each(function(image) { $(image).hide(); this.images[this.images.length] = $(image); }.bind(this));
		
		if (this.images.length > 0)
		{
			//fade in the first slide and after it's finished, start the slideshow
			$( this.images[0] ).appear({ duration:4, afterFinish: (function (){ this.slideNext(); }).bind(this) });
		}
	},
	start: function()
	{
		
	},
	slideNext: function()
	{
		$( this.images[this.index] ).fade({ duration:4 });
		
		//add 1 to i 
		this.index++;
		
		//check if we've reached the end of our slides, if so, rewind i to 0		
		if (this.index == this.images.length) { this.index = 0; } 
		
		//fade in the next slide and after it's finished, loop this function
		$( this.images[this.index] ).appear({ duration:10, afterFinish: (function (){ this.slideNext(); }).bind(this) });
	}
});


var VideoPlayer = Class.create(
{
	initialize: function()
	{
		
	},
	play: function(source, target, width, height, prerollimage)
	{
		var flashvars = {
			flvpFolderLocation: "/flvplayer/",
			flvpAutoStartMovie: false,
			flvpPreRollImage: prerollimage,
			flvpVideoSource: source,
			flvpWidth: width,
			flvpHeight: height,
			flvpTurnOnCorners: false,
			flvpShowbInfo: false,
			flvpShowbCc: false,
			flvpShowbMenu: false,
			flvpShowTimerText : false,
			flvpInterfaceDisplay : "autohide",
			flvpBackButtonRollOverColor: "0x546472",
			flvpPlayButtonRollOverColor: "0x546472",
			flvpPauseButtonRollOverColor: "0x546472",
			flvpStopButtonRollOverColor: "0x546472",
			flvpForwardButtonRollOverColor: "0x546472",
			flvpInfoButtonRollOverColor: "0x546472",
			flvpCCButtonRollOverColor: "0x546472",
			flvpFullscreenButtonRollOverColor: "0x546472",
			flvpMenuButtonRollOverColor: "0x546472",
			flvpCloseMenuButtonRollOverColor: "0x546472",
			flvpScrubBarDragRollOverColor: "0x546472",
			flvpVolumeButtonOnRollOverColor: "0x546472",
			flvpVolumeButtonOffRollOverColor: "0x546472",
			flvpVolumeDragRollOverColor: "0x546472",
			flvpScrubBarFrontColor : "0x546472",
			flvpVolumeFrontColor : "0x546472"
		};
		
		var params = {
			wmode: "transparent",
			menu: "true", 
			allowfullscreen: "true"
		};
		
		swfobject.embedSWF("/flash/flvplayer.swf", target, width, height, "9.0.0", "/flash/expressInstall.swf", flashvars, params);
	}
});

var Doneer = Class.create(
{
	initialize: function()
	{
		if ($('donation_button') && $('donation_button_1') && $('donation_button_2'))
		{
			Event.observe('donation_button', 'mouseover', function(){ this.mouseOver(); }.bind(this));
			Event.observe('donation_button', 'mouseout', function(){ this.mouseOut(); }.bind(this));
		}
	},
	mouseOver: function()
	{
		$('donation_button_1').hide();
		$('donation_button_2').show();
	},
	mouseOut: function()
	{
		$('donation_button_1').show();
		$('donation_button_2').hide();
	}
});

var Poll = Class.create(
{
	initialize: function()
	{
	if ($('poll_button'))
	{
		Event.observe('poll_button', 'mouseover', function(){ $('poll_button').src = '/images/poll_active.gif'; }.bind(this));
		Event.observe('poll_button', 'mouseout', function(){ $('poll_button').src = '/images/poll_inactive.gif'; }.bind(this));
	}
	}
});

var Resizer = Class.create(
{
	initialize: function()
	{
	if ($('size1') && $('size2') && $('size3'))
	{
		Event.observe('size1', 'click', function(){ this.clearAllSizeClasses(); $(document.body).addClassName('size_1'); }.bind(this));
		Event.observe('size2', 'click', function(){ this.clearAllSizeClasses(); $(document.body).addClassName('size_2'); }.bind(this));
		Event.observe('size3', 'click', function(){ this.clearAllSizeClasses(); $(document.body).addClassName('size_3'); }.bind(this));
	}
	},
	clearAllSizeClasses: function()
	{
		$(document.body).removeClassName('size_1');
		$(document.body).removeClassName('size_2');
		$(document.body).removeClassName('size_3');
	}
});

var Menu = Class.create(
{
	initialize: function()
	{
		this.ul	= null;
		this.id	= 'topmenu';
		
		// find root ul
		this.findroot();
		
		// all
		this.ul.childElements().each(function(li)
		{
			// div's 
			var div = li.down('div'); //if(div) { div.hide(); }
			
			var menuitem	= new MenuItem(li, div);
			
			if (li.hasClassName('active'))
			{
				menuitem.activated = true;
			}
			
			this.addBehaviour(menuitem);
			
		}.bind(this));
	},
	findroot: function()
	{
		var ul = null;
		
		//findroot vind uit het ul element aan de hand van het id
		if($(this.id).tagName != "UL")
		{
			this.id = $(this.id).down('ul').id;
			var ul = $(this.id);
		}
		else
		{
			var ul = $(this.id);
		}
		
		ul.childElements().each(function(li)
		{
			if (li.hasClassName('active'))
			{
				this.ul = li.down('ul');
			}
		}.bind(this));
	},
	addBehaviour: function(menuitem)
	{
		if (menuitem.animationcontainer)
		{
			Event.observe(menuitem.id, 'mouseover', function(event) { menuitem.slideOut(); }.bind(this));
			Event.observe(menuitem.id, 'mouseout', function(event) { menuitem.onmouseover = false; window.setTimeout(function(){menuitem.slideIn();}.bind(this), 100); }.bind(this));
		}
	}
});

var MenuItem = Class.create(
{
	initialize: function(elm, animationcontainer)
	{
		this.elm				= elm;
		this.id					= elm.id;
		
		this.opened				= false;
		this.closed				= true;
		
		this.onmouseover		= false;
		
		this.activated			= false;
		
		this.animationcontainer	= animationcontainer;
		
		if (this.animationcontainer != undefined)
		{
			// aantal li's berekenen
						
			this.animationcontainer.down('ul').style.height = (this.animationcontainer.down('ul').childElements().length * 20) + 30 + 'px';
		}
		
		this.parentid;
	},
	slideOut: function()
	{
		this.onmouseover = true;
		
		if (this.opened == false && this.closed == true)
		{
			this.elm.addClassName('hover');
			
			this.closed = false;
			this.opened = true;
						
			Effect.SlideDown(this.animationcontainer,{duration:0.1, queue: { position: 'end', scope: this.id, limit:0 }});
		}
	},
	slideIn: function()
	{
		if (this.onmouseover == false && this.opened == true && this.closed == false)
		{
			
			this.closed = true;
			this.opened = false;
			
			Effect.SlideUp(this.animationcontainer,{duration:0.1, queue: { position: 'end', scope: this.id, limit:0 }});
			
			if (!this.activated)
			{
				this.elm.removeClassName('hover');
			}
		}
	}
});

function showFaq(id)
{
	if (!$('faq_text_' + id).visible())
	{
		$('faq_text_' + id).show();
	}
	else
	{
		$('faq_text_' + id).hide();
	}
	
}

function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}
