window.addEvent('domready', function() {
	/* MENU */
	var menu = document.id('menu');
	if(menu) {
		var menuitems = menu.getElements('li');
		menuitems.addEvents({
			'mouseenter': function(e) {
				var submenu = this.getElement('.submenu');
				if(submenu) {
					/*submenu.reveal({transitionOpacity: false});*/
					submenu.setStyle('display', 'block');
					this.getElement('a').addClass('active');
				}
			},
			'mouseleave': function(e) {
				var submenu = this.getElement('.submenu');
                		if(submenu) {
		                    	/*submenu.dissolve({transitionOpacity: false});*/
					submenu.setStyle('display', 'none');
					this.getElement('a').removeClass('active');
                		}
			}
		});
	}

	/* Cols*/
	var content = document.id('content');
	if(content) {
		(function() {
			var columns = content.getElements('.col, #news');
			var max_height = 0;
    
    			columns.each(function(item) { 
				max_height = Math.max(max_height, item.getSize().y); 
			});
    			columns.setStyle('height',max_height+10);
		}).delay(1000); // Google Chrome Bugfix
	}
	

	/* BRANDBOX */
	var brandbox = document.id('brandbox');
	if(brandbox) {
		var brandbox_nav = brandbox.getElement('.brandbox_nav');
		var brandbox_category = brandbox.getElements('.brandbox_category');
		var brandbox_navel = brandbox_nav.getElements('a');

		brandbox_navel.addEvent('click', function(e) {
			if(e) e.stop();
			brandbox_navel.removeClass('active');
			this.addClass('active');
			brandbox_category.setStyle('visibility', 'hidden');
			document.id(this.get('href')).setStyle('visibility', 'visible');
		});
	}

	/* GALLERY SELECTION BOX*/
	var yearselection = document.id('yearselection');
	if(yearselection) {
		var year = document.id('year');
		year.addEvent('change', function(e) {
			yearselection.submit();	
		});
	}


	/* SEARCHBOX */
	var searchbox = document.id('searchbox');
	if(searchbox) {
		var opties = searchbox.getElements('.query_part');
		var form = searchbox.getElement('form');
		var query = document.id('query');
		
		opties.addEvent('click', function(e) {
			if(this.get('value') == 'wiki') {
				form.set('action', 'http://www.8-12.info/handigzoeken/hz08+/');
				form.set('target','newwindow');
				query.set('name', 'query');
			} else {
				form.set('action', '/zoeken.php');
				form.set('target','');
				query.set('name', 'query');
			}
		});
	}

	/* WEBPOLL */
	var poll_btn = document.id('poll_btn');
	if(poll_btn) {
		var poll_html = document.id('poll_html');
		poll_btn.addEvents({
			'click': function(e) {
				if(e) e.stop();
				poll_html.toggle();
			}
		});
		poll_html.addEvents({
			'mouseleave': function(e) {
				if(e) e.stop();
				poll_html.toggle();
			} 
		});
	}
});
