
window.addEvent('domready', function() {

	/** Menu (ergonomie) **/
	var menu = $('Menu');
	if(menu != null) {
		var items = menu.getElements('li');
		items.each( function(item) {
			item.addEvent('mouseover', function() {
				hideAllSubs();
				var sub = item.getElement('ul');
				if (sub != null) sub.setStyle('display', 'block');
			});
		});
	}
	var inner = $('Inner');
	if(inner != null) inner.addEvent('mouseover', hideAllSubs);
	var rA = $('RetourAccueil');
	if(rA != null) rA.addEvent('mouseover', hideAllSubs);

	/** Liens activés en ajax **/
	var menu = $('Menu');
	if(menu != null) {
		menu.getElements('a').each(function(item) {
			item.addEvent('click', function() {
				activeThisMenu(item);
			});
		});
	}
	var menu = $('Pied');
	if(menu != null) {
		menu.getElements('a').each(function(item) {
			item.addEvent('click', function() {
				activeThisMenu(item);
			});
		});
	}
	var menu = $('MenuTop');
	if(menu != null) {
		menu.getElements('a').each(function(item) {
			item.addEvent('click', function() {
				activeThisMenu(item);
			});
		});
	}

	/** Player **/
	// http://www.orchestre-avignon.com/Home/1/Reservation/Son/tanguy_incanto.mp3
	var flashvars = {
		title: "WA Mozart - Cor - 2ème mouvement              ",
		file: "http://www.orchestre-avignon.com/Home/1/Reservation/Son/tanguy_incanto.mp3",
		autoplay: "0"
	}; 
	swfobject.embedSWF("/Skins/Olrap2011/Swf/AudioPlayer.swf", "AudioPlayerSwf", "340", "20", "9.0.0", "/Skins/Olrap2011/Swf/expressInstall.swf", flashvars);

});

/*** Referme tous les sous menus ***/
function hideAllSubs () {
	var items = $('Menu').getElements('li');
	items.each( function(item) {
		var sub = item.getElement('ul');
		if (sub != null) sub.setStyle('display', 'none');
	});
}

/** Passe un menu en Current et désactive les autres sauf si parent ***/
function activeThisMenu( item ) {
	document.body.getElements('a.Current').each(function(item) {
		item.removeClass('Current');
	});
	item.addClass('Current');
	var parent = item.getParent('li');
	if(parent != null) var parent2 = parent.getParent('li');
	if(parent2 != null) var a = parent2.getFirst('a');
	if(a != null) a.addClass('Current');
}
