function formHandler(form) {
  var url = form.site.options[form.site.selectedIndex].value;
  if (url != "") { location.href = url; }
}

function lieu(url) {
  win_filles = window.open(url, 'filles', 'scrollbars=yes,resizable=yes,status=yes,width=400,height=300');
  win_filles.focus();
}

function video(url, winw, winh) {
	winw = winw+50; winh = winh+120;
  win_filles_video = window.open(url, 'fillesvideo', 'scrollbars=no,resizable=yes,status=yes,width='+winw+',height='+winh);
  win_filles_video.focus();
}

function retour(url) {
  opener.location.href = url;
}

function pouf() {
  window.close();
}

function jwRotator(playerDivId, playerUrl, playlistUrl, width, height) {
	var so = new SWFObject(playerUrl, 'rotator', width, height, '7');
	so.addVariable('width', width);
	so.addVariable('height', height);
	so.addVariable('file', playlistUrl);
	so.addVariable('height',height);
	so.addVariable('width',width);
	so.addVariable('transition','lines');
	so.addVariable('shuffle','true');
	so.addVariable('backcolor','0x000000');
	so.addVariable('rotatetime','5');
	so.addVariable('kenburns','true');
	so.addVariable('shownavigation','true');
	so.write(playerDivId);
}

var initGrilleHoraire = function(div) {
	var maxHeight = 0;
	
	div.down('ul').childElements().each(function(li) {
		li.setStyle({ 'height': 'auto' });
		var liHeight = li.getHeight() - 10;
		if(liHeight > maxHeight) maxHeight = liHeight;
	});

	div.down('ul').childElements().each(function(li) {
		li.setStyle({ 'height': maxHeight + 'px' });
	});
}

var initPlus = function(ul) {
	if(ul.select('li.plus').any()) {
		ul.select('li.plus').each(function(li) { li.hide(); });
		ul.previous('h2').insert({ bottom: '<span class="btn-plus"><a href="#">+</a></span>' });
		var btnPlus = ul.previous('h2').down('span.btn-plus a');
		btnPlus.state = false;

		Event.observe(btnPlus, 'click', function(event) {
			var btnPlus = event.element();
			btnPlus.blur();
			btnPlus.state = !btnPlus.state;
		
			if(btnPlus.state) {
				ul.select('li.plus').each(function(li) { li.show(); });
				btnPlus.innerHTML = '-';

			} else {
				ul.select('li.plus').each(function(li) { li.hide(); });
				btnPlus.innerHTML = '+';
			}
			
			event.stop();
		});
	}
}

var initEvenListByBio = function(ul) {
	ul.select('ul').each(function(li) { li.hide() });
	
	ul.childElements().each(function(li) {
		if(li.tagName == 'LI') {
			li.down('a').insert({ after: '<span class="btn-plus"><a href="#">+</a></span>' });
			var btnPlus = li.down('span.btn-plus a');
			btnPlus.store('state', false);

			Event.observe(btnPlus, 'click', function(event) {
				var btnPlus = event.element();
				btnPlus.blur();
				btnPlus.store('state', !btnPlus.retrieve('state'), false);
			
				if(btnPlus.retrieve('state')) {
					btnPlus.up('li').down('ul').show();
					btnPlus.innerHTML = '-';
	
				} else {
					btnPlus.up('li').down('ul').hide();
					btnPlus.innerHTML = '+';
				}
				
				event.stop();
			});
		}
	});
}

var initSiteDomLoaded = function(event) {
//	if($$('ul.even-list-by-bio')) {
//		$$('ul.even-list-by-bio').each(initPlus);
//	}
	
	if($$('ul.even-list-by-bio')) {
		$$('ul.even-list-by-bio').each(initEvenListByBio);
	}
	
	if($$('div.grille-horaire')) {
		$$('div.grille-horaire').each(initGrilleHoraire);
	}
}

var initSiteAllLoaded = function(event) {
}

Event.observe(document, 'dom:loaded', initSiteDomLoaded, false);
Event.observe(window, 'load', initSiteAllLoaded, false);
