

function fenexy( nom, x, y, sc ) {
	strhei = "HEIGHT=" + y
	strwid = "WIDTH=" + x
	if( sc ==null )  sc = 0
	scrol = "scrollbars=" + sc
	strf = strhei + "," + strwid + "," + scrol
	window.open(nom,"", strf)
}



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, liste ) {
		if( $chk(groupe) ) { 
			this.groupTag = groupe; 
			$(this.groupTag).setStyle( 'width', this.width ); 
		}
		if( $chk(liste) ) { this.listeTag = liste; }
		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"><img src="images/indicator_snake.gif" /><br/>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.setLightBoxOnComplete	= false;
		this.disableWait			= 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: '400px',
							left: '500px',
							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.disableWait ? '' : this.showLoad(),
											method: this.onCompleteOptions.method,
											postBody: this.param,
											update: this.onCompleteOptions.targetBloc,
											onComplete : function() { $('tb_load').remove(); }
									 }).request();
	},


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

			
		//	alert( $(this.blocResult) );
		//	this.blocAction = this.blocResult;
		//	this.blocResult = '';

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


		}
		//alert( $(this.blocAction) + ' : ' + $(this.blocOnComplete) );


	},


/*	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 ) {
			//alert( this.script );
			if( this.script=='' ) {
				//alert( el.value );
				this.script = $(el).id != '' ? $(el).id : el.href;
				this.param = el.name + '=' + el.value;
				
				/*if( $(this.blocAction).getProperty( 'ajaxscript' ) ) {
					this.script = $(this.blocAction).getProperty( 'ajaxscript' );
				} else {
					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.disableWait ? '' : 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});
		this.toggleBar.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: d,
			fixedHeight: false,
			onActive: function(toggler, element){
				//toggler.setStyle('background-color', '#000' );
				//toggler.removeClass( 'flechedroite' );
				//toggler.addClass( 'flechebas' );
				//alert( toggler.getProperty( 'rel' ) );
			/*	globShow = element.getProperty( 'rel' );*/
			},

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

} );








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


	// Eviter les conflics entre Mootools et jQuery
	//
	jQuery.noConflict();
	
	// Initialiser le menu horizontal
	//
	jQuery(function() { 
		jQuery(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 })
	});
		
	
	if( $('moteur') ) {
		var accord = new accordeon( $('moteur') );
		accord.toggleBar = 'h3.atStart';
		accord.elementBloc =  'div.atStart';
		accord.start( $('moteur').getProperty( 'rel' ) );
	}	

	
	
	/*if( $('blocDivertir') ) {
		var liste = new listeToggle2({
			'width': '150px',
			'height': 'auto',
			'duration': 200,
			'showDelay': 100,
			'groupTag': 'grListe1',
			'listeTag': 'listeId1',
			'listeStyle': { overflow:'hidden'}
		});
		liste.clickAction( 'sListe1', 'grListe1', 'listeId1' );
		liste.clickAction( 'sListe2', 'grListe2', 'listeId2' );
		liste.clickAction( 'sListe3', 'grListe3', 'listeId3' );
	}*/	
	
	if( $('degustation') ) {

		var mySlide = new Fx.Slide('liste');
		 
	 	mySlide.toggle();
		$('toggle2').addEvent('click', function(e){
			e = new Event(e);
			mySlide.toggle();
			e.stop();
		});	
	}

	if( $('grListe1') ) {
		var liste = new listeToggle2({
			'width': '150px',
			'height': 'auto',
			'duration': 200,
			'showDelay': 100,
			'groupTag': 'grListe1',
			'listeTag': 'listeId1',
			'listeStyle': { overflow:'hidden'}
		});
		liste.clickAction( 'sListe1', 'grListe1', 'listeId1' );
	}
	
	var Tips1 = new Tips($$('.Tips1'), { offsets: {'x': 20, 'y': -20} });	
	
	


	if( $('formHebe') ) {
		var contenu2 = new blocRefresh( 'typeHeb', '_classement_' );
		contenu2.eventListenType = 'change';
		contenu2.ciblingTag = 'select';
		contenu2.disableWait = true;
		contenu2.setOnComplete( {	scriptOnComplete:'classement.php3',	
									evTypeOnComplete:'change', 
									actionBloc: 'typeHeb', 
									targetBloc: '_classement_',
									method: 'post' } );	
		var script = $('typeHeb').getProperty( 'ajaxscript' );
		if( script != null ) {
			contenu2.ajaxAction( script );
		}
	}	
	
	if( $('formActivite') ) {
		var contenu2 = new blocRefresh( 'typeActi', '_themeacti_' );
		contenu2.eventListenType = 'change';
		contenu2.ciblingTag = 'select';
		contenu2.disableWait = true;
		contenu2.setOnComplete( {	scriptOnComplete:'themeactivite.php3',
									evTypeOnComplete:'change', 
									actionBloc: 'typeActi', 
									targetBloc: '_themeacti_',
									method: 'post' } );	
		var script = $('typeActi').getProperty( 'ajaxscript' );
		if( script != null ) {
			contenu2.ajaxAction( script );
		}
	}	
	
	
	/*
	if( $('_moteurheber_' ) ){
		$('_moteurheber_' ).addEvent('click', function(e){
			$('form1').submit();
		});
	}	*/

	
	if( $('listeResultat') ) {
		var contenu1 = new blocRefresh( 'listeResultat', 'listeResultat' );
		contenu1.ciblingTag = 'a';
		contenu1.blocOnComplete = 'numPage';
		contenu1.setLightBoxOnComplete = true;
		contenu1.setTipsOnComplete = true;
		contenu1.method = 'post';
		var script = $('listeResultat').getProperty( 'ajaxscript' );
		if( script != null ) {
			contenu1.ajaxAction( script );
		}
	}
	
	
	if( $('_envoyer_') ) {
		//var form = $(document.body).getElement('form');
		var form = $('commentform');
		//alert( form.action );
		$('_envoyer_').addEvent('click', function(e){
			form.submit();	
		});
	}	
	

});







