//survols
var TimerId = null;
var Fleche = null;
var Current_survol = null;
function show(survol) {
	//global
	Current_survol = survol;
	//suppression du hide
	clearTimeout (TimerId);
	//on vire la classe de la fleche
	Fleche.set('class','');
	//on affiche le bon sous menu (et on bouge la fleche)
	$('survol').getElements('div.activites').each(function (DOM, index) {
		if (DOM.get('id') == 's_'+survol) {
			DOM.setStyle('display', 'block');
		} else {
			DOM.setStyle('display', 'none');
			/*var t_temp = DOM.get('id').split('_');
			var temp = t_temp[1];
			if (t_temp.length>2) {
				//bug a cause de "tout_compris"
				temp += '_'+t_temp[2];
			}
			if (Fleche.hasClass(temp)) {
				Fleche.removeClass(temp);
			}*/
		}
	});
	//if (!Fleche.hasClass(survol)) {
		Fleche.addClass(survol);
	//}
	//on affiche le bloc
	$('survol').setStyle('display', 'block');
	//on affiche masque le bon tarif
	if (survol == 'groupes') {
		$('dl_tarifs_groupes').setStyle('display', 'block');
	} else {
		$('dl_tarifs_groupes').setStyle('display', 'none');
	}
}
function hide() {
	//global
	Current_survol = null;
	//on cache
	$('survol').setStyle('display', 'none');
}
/*function FireEvent(id,src) {
	$(id).getParent('div.galerie').getElements('a.galerie').each(function(DOM, index) {
		if (DOM.get('href') == src) {
			milkbox.open(id,index);
		}
	});
}*/
window.addEvent('domready', function(){
	//menu deroulant presentation
	if ($('pres_survol')) {
		$('pres_survol').getParent('li').addEvents({
				mouseover: function(){
					$('pres_survol').setStyle('display','block');
				},
				mouseout: function(){
					$('pres_survol').setStyle('display','none');
				}
		});
	}
	//la fleche des survols
	Fleche = $('fleche');
	//les survols liens
	$('header').getElements('a.survol').each(function (DOM, index) {
		var survol =DOM.get('rel')
		DOM.addEvents({
			mouseover: function(){
				show(survol);
			},
			mouseout: function(){
				TimerId = setTimeout("hide()", 750);
			}
		});
	});
	//les survols blocs
	$('survol').addEvents({
		mouseover: function(){
			if (Current_survol != null) {
				show(Current_survol);
			}
		},
		mouseout: function(){
			TimerId = setTimeout("hide()", 750);
		}
	});
	//galerie activites
	milkbox = new Milkbox({ centered:true });
	//galerie dans les news
/*	$$('img.zoomable').each(function(DOM, index) {
		DOM.addEvent('click', function(e){
			FireEvent(DOM.get('id'),DOM.get('src'));
		});
	});
	$$('a.galerie').each(function(DOM, index) {
		DOM.addEvent('click', function(e){
			e.stop();
			$(DOM.get('rel')).set('src',DOM.get('href'));
		});
	});*/
	$$('div.cont_gal').each(function(DOM, index) {
		DOM.setStyle('overflow','hidden');
		var TABLE = $(DOM.getFirst('table'));
		TABLE.setStyle('position','absolute');
		TABLE.setStyle('left',0);
		var DIV = DOM.getParent('div.galerie');
		//left
		var left = new Element('img', {
			'src': '/styles/left.png',
			'alt': 'Precedent',
			'styles': {
				'position': 'absolute',
				'cursor': 'pointer',
				'border': 0,
				'bottom': '15px',
				'left': '5px'
			},
			'events': {
			'click': function(){
					temp = TABLE.getCoordinates(DOM).left + 80;
					if (temp >= 0) {
						temp = 0;
					}
					TABLE.setStyle('left',temp+'px');
				}
			}
		});
		left.inject(DIV);
		//right
		var right = new Element('img', {
			'src': '/styles/right.png',
			'alt': 'Suivante',
			'styles': {
				'position': 'absolute',
				'cursor': 'pointer',
				'border': 0,
				'bottom': '15px',
				'right': '5px'
			},
			'events': {
				'click': function(){
					temp = TABLE.getCoordinates(DOM).left - 80;
					width = TABLE.getCoordinates(DOM).width - 240;
					if (temp <= -width) {
						temp = -width;
					}
					TABLE.setStyle('left',temp+'px');
				}
			}
		});
		right.inject(DIV); 
	});
	//on positionne sur une ancre si on en a une de demandé
	if (goto_anchor!==null) {
		if ($(goto_anchor)) {
			$('bloc_blanc').getFirst('div.scroller').scrollTo(0, ($(goto_anchor).getPosition($('bloc_blanc')).y));
		}
	}
});
