Event.observe(window, 'load', function() {
	$$('ul.school_list_yo li a').invoke('observe', 'click', function(e) { 
		Event.stop(e);
		new Ajax.Updater($('ajax_container'), this.href, {
			onComplete: function() {
				new Effect.Move($('ajax_wrapper'), {
					x: -527
				});
				$$('.back').invoke('observe', 'click', function(e) { 
					Event.stop(e);
					new Effect.Move($('ajax_wrapper'), { x: 527 } );
				});  
			}
		});
	});
	
	$$('.update_results').invoke('observe', 'click', function(e) {
		var form = $('yo_search_form');
		var aofa = false;
		var hanken = false;
		var hse = false;
		var tkk = false;
		var sibelius = false;
		var theatre = false;
		var uoaadh = false;
		var uoh = false;
		var amount = 0;
		
		form.getInputs('checkbox').each(function(e) {				 
			if(e.checked == true) {
				if(e.value == 0) {
					aofa = true;
					hanken = true;
					hse = true;
					tkk = true;
					sibelius = true;
					theatre = true;
					uoaadh = true;
					uoh = true;
				} else if(e.value == 1) {
					tkk = true;
					uoh = true;
				} else if(e.value == 2) {
					uoh = true;
					uoaadh = true;
					sibelius = true;
					aofa = true;
					theatre = true;
				} else if(e.value == 3) {
					tkk = true;
					uoh = true;
				} else if(e.value == 4) {
					tkk = true;
					hanken = true;
					hse = true;
					uoh = true;
				} else if(e.value == 5) {
					tkk = true;
				} else if(e.value == 6) {
					tkk = true;
					uoh = true;
				} else if(e.value == 7) {
					tkk = true;
					uoh = true;
				}
			}
		} );
		
		var ret_str = '';
		amount = 0;
		if(aofa == true) {
			ret_str += '<li><a href="aofa.html">Academy of Fine Arts</li>';
			amount++;
		}
		if(hanken == true) {
			ret_str += '<li><a href="hanken.html">Hanken School of Economics</a></li>';
			amount++;
		}
		if(hse == true) {
			ret_str += '<li><a href="hse.html">Helsinki School of Economics (HSE)</a></li>';
			amount++;
		}
		if(tkk == true) {
			ret_str += '<li><a href="tkk.html">Helsinki University of Technology (TKK)</a></li>';
			amount++;
		}
		if(sibelius == true) {
			ret_str += '<li><a href="sibelius.html">Sibelius Academy</a></li>';
			amount++;
		}
		if(theatre == true) {
			ret_str += '<li><a href="theatre.html">Theatre Academy</a></li>';
			amount++;
		}
		if(uoaadh == true) {
			ret_str += '<li><a href="uoaadh.html">University of Art and Design Helsinki</a></li>';
			amount++;
		}
		if(uoh == true) {
			ret_str += '<li class="last"><a href="uoh.html">University of Helsinki</a></li>';
			amount++;
		}
		$('amount').innerHTML = '(' + amount + ' found)'
		$('school_list').innerHTML = ret_str;
		
		$$('ul.school_list_yo li a').invoke('observe', 'click', function(e) { 
			Event.stop(e);
			new Ajax.Updater($('ajax_container'), this.href, {
				onComplete: function() {
					new Effect.Move($('ajax_wrapper'), {
						x: -527
					});
					$$('.back').invoke('observe', 'click', function(e) { 
						Event.stop(e);
						new Effect.Move($('ajax_wrapper'), { x: 527 } );
					});  
				}
			});
		});
	});
	
	$$('.select_search input').invoke('observe', 'click', function(e) {
		if(this.value != 0)
			$('search_all').checked = false;
		else
			$$('.select_search input').each(function(e) { if(e.value != 0) e.checked = false; });
	});
});

