



var sendToPop = new Class( {

	initialize: function( el ) {

		this.element	= el;
		this.script 	= '';
		this.widthPop	= '750';
		this.heightPop	= '600';
		this.scrollPop	= 'auto';
		this._param		= '';

	},

	active: function( event, script ) {
		if( script != null ) {
			this.script = script;
		}
		this.element.addEvent( event, this.sendPop.bindAsEventListener(this) );
	},


	popup: function ( script ) {
		strhei = "height=" + this.heightPop;
		strwid = "width=" + this.widthPop;
		if( script!=null ) {
			this.script = script;
		}
		scrol = "scrollbars=" + this.scrollPop;
		strf = strhei + "," + strwid + "," + scrol;
		window.open( this.script + this._param, '', strf );
	},


	sendPop: function() {
		if( this.element.getValue() != 0 ) {
			this._param = '?id=' + this.element.getValue();
			this.element.options[0].selected = true;
		}
		this.popup();
	}

} );








var listeToggle2 = new Class( {

	initialize: function(options) {
		this.listeTag	= '';
		this.groupTag	= '';
		this.width		= '100px';
		this.height		= 'auto';
		this.duration	= 300;
		this.showDelay  = 5000;
		this.options	= {};
		this.setParam(options);

	},

	setParam: function(options) {
		if( $chk( options ) ) {
			this.options = options;
		}
		if( $chk(this.options.groupTag) ) {
			this.groupTag = this.options.groupTag;
		}
		if( $chk(this.options.listeTag) ) {
			this.listeTag = this.options.listeTag;
		}
		if( $chk(this.options.height) ) {
			this.height = this.options.height;
		}
		if( $chk(this.options.width) ) {
			this.width = this.options.width;
		}
		if( $chk(this.options.duration) ) {
			this.duration = this.options.duration;
		}
		if( $chk(this.options.showDelay) ) {
			this.showDelay = this.options.showDelay;
		}
		if( $chk(this.options.listeStyle) ) {
			this.listeStyle = this.options.listeStyle;
		}
		$(this.groupTag).setStyle( 'width', this.width );
		$(this.listeTag).setStyle( 'height', this.height );
		$(this.listeTag).setStyle( 'width', this.width );

		$(this.listeTag).setStyles( this.listeStyle );
	},




	clickAction: function( link, groupe ) {
		if( $chk(groupe) ) { this.groupTag = groupe; }
		var sDelay = this.showDelay;
		var grTag = $(this.groupTag);
		var closeT;
		var fx = new Fx.Slide($(this.listeTag), {duration: this.duration});
		fx.hide();
		//alert( $(this.listeTag).getStyle('height') );
		/*if( $(this.listeTag).getStyle('height') == '0px' ) {
				alert( fx.vertical() );
		}*/
		$(link).addEvent('click', function(){
			fx.clearTimer();
			fx.toggle();
			grTag.addEvent( 'mouseout', function() {
				closeT = $clear(closeT);
				closeT = function() { fx.slideOut(); }.delay(sDelay);
			});
			grTag.addEvent( 'mouseover', function() {
				closeT = $clear(closeT);
			});
			//var closeT = function() { fx.toggle(); }.delay(sDelay);
		});
	}

});











var blocRefresh = new Class( {

	initialize: function( blocA, blocR ) {

		this.waitMessage		= '<div id="waiting">Chargement...</div>';
		this.method				= 'get';
		this.blocAction 		= blocA;
		this.blocResult 		= blocR;

		this.tabAction			= [];
		this.tabResult			= [];
		this.EventType			= [];

		this.param 				= '';
		this.ciblingTag 		= '';
		this.script 			= '';

		this.eventListenType 	= 'click';
		this.blocOnComplete		= '';
		this.blocOnComplete2	= '';
		this.setLightBoxOnComplete	= false;

		this.onCompleteOptions	= {};
		this.tempTab = {};
	},




	showLoad: function() {
		if( !$('tb_load') ) {
			new Element('div').setProperty('id', 'tb_load').injectBefore(this.blocResult);
			$('tb_load').innerHTML = '<p align="center"><img src="images/indicator_snake.gif" /><br/>Chargement...</p>';
			this.tbLoadPosition();
		}
	},


	hideLoad: function() {
		if( $('tb_load') ) {
			$('tb_load').remove();
		}
	},


	tbLoadPosition: function() {
		if( $('tb_load') ) {
			$('tb_load').setStyles({
							position: 'absolute',
							top: '450px',
							left: '560px',
							width: '100px',
							margin: '0px auto',
							display: 'block'
					});
		}
	},


	setEventAjax: function( typeEvent ) {
		if( typeEvent != null ) {
			this.eventListenType = typeEvent;
		}
		$(this.blocAction).addEvent( this.eventListenType, this.traiteEvent.bind(this) );
	},

	setEventAjax2: function( typeEvent ) {
		if( typeEvent != null ) {
			this.eventListenType = typeEvent;
		}
		$(this.blocAction).addEvent( this.eventListenType, this.traiteEvent2.bind(this) );
	},

	setOnComplete: function( options ) {
		if( window.ie ) {
			options.evTypeOnComplete = 'click';
		}
		this.onCompleteOptions = options;
	},

	onComplete: function(e) {
		var e = new Event(e).stop();
		var el= e.target;
		this.param = el.name + '=' + el.value;
		new Ajax( this.onCompleteOptions.scriptOnComplete, { 	onStateChange: this.waitMessage,
											method: this.onCompleteOptions.method,
											postBody: this.param,
											update: this.onCompleteOptions.targetBloc }).request();
	},


	onCompleteAction: function(e) {
		this.hideLoad();
		if( this.setLightBoxOnComplete ) {
			window.addEvent('domready', Lightbox.init.bind(Lightbox));
		}
		//initNXGMap(document.getElementById('map'));
		//clearAll();showPoints(-1);
		if( $(this.blocOnComplete) ) {
			$(this.blocOnComplete).addEvent( this.eventListenType, this.traiteEvent.bind(this) );
		} else {
			//alert( $(this.blocResult) );
		//	this.blocAction = this.blocResult;
		//	this.blocResult = '';

			//$(this.blocResult).addEvent( this.eventListenType, this.traiteEvent.bind(this) );

			/*if( $(this.onCompleteOptions.actionBloc) != null ) {
				$(this.onCompleteOptions.actionBloc).addEvent( this.onCompleteOptions.evTypeOnComplete, this.onComplete.bind(this) );
			}*/
		}
		if( $(this.blocOnComplete2) ) {
			$(this.blocOnComplete2).addEvent( this.eventListenType, this.traiteEvent.bind(this) );
		}
	},


/*	onCompleteLightBox: function(e) {
		window.addEvent('domready', Lightbox.init.bind(Lightbox));
	},*/


	traiteEvent: function(e) {
		var e = new Event(e).stop();
		var el= e.target;
	//	alert( el.id + ' : ' + $(el).getTag() + ' : ' + this.ciblingTag );
		//alert( $(el).getParent() );
		if( $(el).getTag() == this.ciblingTag ) {
			if( this.script=='' ) {
				this.script = $(el).id != '' ? $(el).id : el.href;
				//alert( this.script );
				this.ajaxAction( this.script );
			} else {
				el2 = $(el).getTag();
				this.param = el2.name + '=' + el2.value;
			//	alert( this.param );
				this.ajaxAction( this.script );
			}
		} else {
			this.script = $(el).getParent();
			//alert( this.script );
			if( this.script != '[object]' ) {
				this.ajaxAction( this.script );
			} else {
				this.script = '';
			}
		}
	},


	traiteEvent2: function(e) {
		var e = new Event(e).stop();
		var el= e.target;
		//alert( el.id + ' : ' + $(el).getTag() + ' : ' + this.ciblingTag );
		//alert( $(el).getParent() );
		if( $(el).getTag() == this.ciblingTag ) {
			if( this.script=='' ) {
				this.script = $(this.blocAction).getProperty( 'ajaxscript' );
				/*
				this.script = $(el).id != '' ? $(el).id : el.href;
				this.ajaxAction2( this.script );*/
			} else {
				this.param = el.name + '=' + el.value;
				this.ajaxAction2( this.script );
			}
		} else {
			this.script = $(el).getParent();
			this.ajaxAction2( this.script );
		}
	},


	/**
	*	ouvre une boxe
	*/
	lightBoxAction: function( link ) {
		new Ajax( link, { 	onStateChange: this.showLoad(),
							method: this.method,
							update: this.blocResult,
							postBody: this.param,
							onComplete: Lightbox.init.bind(Lightbox)
				}).request();
	},



	ajaxAction: function( link ) {
		/*if( this.setLightBoxOnComplete ) {
			this.lightBoxAction( link );
		} else {*/
			new Ajax( link, { 	onStateChange: this.showLoad(),
								method: this.method,
								update: this.blocResult,
								postBody: this.param,
								onComplete: this.onCompleteAction.bind(this)
					}).request();
		//}
		this.script = '';
	},


	onCompleteAction2: function(e) {
		this.hideLoad();
		initNXGMap(document.getElementById('map2'));
	/*	if( $(this.blocOnComplete) ) {
			$(this.blocOnComplete).addEvent( this.eventListenType, this.traiteEvent2.bind(this) );
		} else {
			$(this.blocResult).addEvent( this.eventListenType, this.traiteEvent2.bind(this) );
		}*/
	},

	ajaxAction2: function( link ) {
		if( this.setLightBoxOnComplete ) {
			this.lightBoxAction( link );
		} else {
			alert( link );
			new Ajax( link, { 	onStateChange: this.showLoad(),
								method: this.method,
								update: this.blocResult,
								postBody: this.param,
								onComplete: this.onCompleteAction2.bind(this)
					}).request();
		}
		this.script = '';
	}


} );








var accordeon = new Class( {

	initialize: function( masterBloc, options ) {
		this.options			= {};
		this.toggleBar 			= '';
		this.elementBloc 		= '';
		this.masterBloc			= masterBloc;
		this.setParam( options );

		Fx.Morph = Fx.Styles.extend({

			start: function(className){

				var to = {};

				$each(document.styleSheets, function(style){
					var rules = style.rules || style.cssRules;
					$each(rules, function(rule){
					//	alert( rule.selectorText );
						if (!rule.selectorText.test('\.' + className + '$')) return;
						Fx.CSS.Styles.each(function(style){
							if (!rule.style || !rule.style[style]) return;
							var ruleStyle = rule.style[style];
							to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
						});
					});
				});
				return this.parent(to);
			}

		});
	},


	setParam: function( options ) {
		if( $chk( options ) ) {
			this.options = options;
		}
	},

	morph: function( className ) {

		Fx.CSS.Styles = ["backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];

		Fx.CSS.Styles.extend(Element.Styles.padding);
		Fx.CSS.Styles.extend(Element.Styles.margin);

		Element.Styles.border.each(function(border){
			['Width', 'Color'].each(function(property){
				Fx.CSS.Styles.push(border + property);
			});
		});
		var myMorph = new Fx.Morph('morpher', {wait: false});
		$('morph1').addEvent('click', function(e){
			new Event(e).stop();

			myMorph.start(className);

		});

	},

	start: function( d ) {
		var accordion = new Accordion( this.toggleBar, this.elementBloc, {
			opacity: false,
			display: 0,
			fixedHeight: false,
			onActive: function(toggler, element){
				toggler.setStyle('background-color', '#f7c721' );
				toggler.removeClass( 'flechedroite' );
				toggler.addClass( 'flechebas' );
				//alert( toggler.getProperty( 'rel' ) );
			/*	globShow = element.getProperty( 'rel' );*/
			},

			onBackground: function(toggler, element){
				toggler.setStyle('background-color', '#fff' );
				toggler.removeClass( 'flechebas' );
				toggler.addClass( 'flechedroite' );
			}
		}, this.masterBloc );
	}

} );








function init() {


	if( $('diaporama') ) {
		var intro = new gallery($('diaporama'), {
			timed: true,
			slideInfoZoneSlide: true,
			showCarousel: false,
			fadeDuration: 1500,
			delay: 6000,
			embedLinks: false,
			showArrows: false,
			forceSize: true,
			elementWidth: '635px',
			elementHeight: '238px',
			useThumbGenerator: true
		});
	}


	if( $('onglet2') ) {
		myTabs1 = new mootabs('onglet2', {
			width: 			'224px',
			height: 		'162px',
			changeTransition: 	Fx.Transitions.Sine.easeIn,
			duration:		600,
			mouseOverClass: 	'',
			activateOnLoad:		'first'
			/*ajaxOptions: 		{method'get'},
			ajaxLoadingText: 	'Loading...'	*/
		});
	}

	if( $('listeDispo') ) {
		var popVisite = new sendToPop( $('listeDispo') );
		popVisite.scrollPop	= 'yes';
		popVisite.widthPop = '600';
		popVisite.heightPop = '450';
		var script = $('listeDispo').getProperty( 'script' );
		popVisite.active( 'click', script );
	}



	if( $('accordion') ) {
		var accord = new accordeon( $('accordion') );
		accord.toggleBar = 'h3.atStart';
		accord.elementBloc =  'div.atStart';
	//	alert( accord.elementBloc.getProperty( 'rel' ) );
	//	accord.options = { show:2 }
		accord.start( 1 );
	}


	if( $('listeResultat') ) {
		var contenu1 = new blocRefresh( 'listeResultat', 'listeResultat' );
		contenu1.ciblingTag = 'a';
		contenu1.blocOnComplete = 'numPage';
		contenu1.blocOnComplete2 = 'numPage2';
		contenu1.setLightBoxOnComplete = true;
		contenu1.method = 'post';
		var script = $('listeResultat').getProperty( 'ajaxscript' );
		if( script != null ) {
			contenu1.ajaxAction( script );
		}
	}
	
/*	if( $('listeDiapo') ) {
		var contenu1 = new blocRefresh( 'listeDiapo', 'visuel' );
		contenu1.ciblingTag = 'img';
		contenu1.method = 'get';
		contenu1.setLightBoxOnComplete = true;
		contenu1.setEventAjax( 'click' );
	}	*/
	
	if( $('_inscription_' ) ){
		$('_inscription_' ).addEvent('click', function(e){
			$('form1').submit();
		});
	}

	if( $('_moteur1ok_' ) ){
		$('_moteur1ok_' ).setStyle( 'cursor', 'pointer' );
		$('_moteur1ok_' ).addEvent('click', function(e){
			$('crit1').submit();
		});
	}
	if( $('_moteur2ok_' ) ){
		$('_moteur2ok_' ).setStyle( 'cursor', 'pointer' );
		$('_moteur2ok_' ).addEvent('click', function(e){
			$('crit2').submit();
		});
	}	

	var Tips1 = new Tips($$('.Tips1'));




}

Window.onDomReady( init );





