// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function hide_stuff() {
	$$('.hidden-on-load').each(function(el){el.hide()});
	//console.log('hiding stuff');
}
Event.observe(window, 'load', hide_stuff);


function toggleOpenClose(el) {
	var the_a = Element.previous(el.element).down().next().next()
	if(el.element.visible()){
		the_a.innerHTML = $$('html')[0].readAttribute('lang') == 'fr' ? 'Fermer' : 'Close';
	}else{
		the_a.innerHTML = $$('html')[0].readAttribute('lang') == 'fr' ? 'Lire +' : 'More';
	}; 
}

function toggleEventOpenClose(el) {
	var the_a = Element.previous(el.element).down();
	if(el.element.visible()){
		the_a.innerHTML = $$('html')[0].readAttribute('lang') == 'fr' ? 'Fermer' : 'Close';
	}else{
		the_a.innerHTML = $$('html')[0].readAttribute('lang') == 'fr' ? 'Lire +' : 'More';
	}; 
}

function setup_calendar_toggler() {
	$$('.toggler').each(function(tog){
		Event.observe(tog, 'click', function(e){
			var caldata = Event.element(e).next();
			Effect.toggle(caldata, 'slide', {duration:0.5, afterFinish:toggleCalendarOpenClose});
			Event.stop(e);
			//return false;
		})
	})
	
}
Event.observe(window, 'load', setup_calendar_toggler);

function toggleCalendarOpenClose(ev) {
	//console.log($(ev.element).previous());
	var the_toggler = $(ev.element).previous();
	if($(ev.element).visible()) {
		the_toggler.style.backgroundImage = 'url(/images/triangle_open.png)';
	} else {
		the_toggler.style.backgroundImage = 'url(/images/triangle_closed.png)';
	}
}
