function openPopup(){

	
	var arr_popupLinks = $(document.body).getElements("a.openPopup");
	
	
	arr_popupLinks.each(function(el){
		el.addEvent('click', function(e) {
			// On stoppe le pointage naturel du lien pour ne pas recharger la page
			e = new Event(e).stop();

			
			var req = new Request({
				url: el.href,
				onSuccess: function(e){
					$('popup_center').set('html', e);
					
					$('popup_container').setStyles({
						'visibility':'hidden',
						'display':'block'
					});
					var wH = window.getSize().y;
					var popH = $('popup_container').getSize().y;
					var topY = window.getScroll().y;
					var posY = topY + ((wH-popH)/2);
					posY = (posY<0) ? 0 : posY;
					
					$('popup_container').setStyles({
						'top':posY,
						'visibility':'visible',
						'opacity':0
					});
					
					var diapo = e.indexOf("diaporama_container");

					if(diapo!=-1){
						// diaporama
						$('diapo').setStyles({
							'display':'none',
							'visibility':'visible'
						});
						
						var arr_photos = $$('ul#diapo li img');
						var arr_photos_src = new Array();
						arr_photos.each(function(el){
							arr_photos_src.push(el.src);
						});
						
						var myShow = new Slideshow("show", arr_photos_src, {controller: true, height: "309px", hu: "", paused: true, width: "659px"});
					
					}

					$('popup_container').reveal({
						onComplete:function(){
							$('overlay').addEvent('click',function(){
								$$('.fechar').fireEvent('click');
							});
						}
					});	
					
				},
				onFailure: function(){
					$('popup_center').set('text', 'The request failed.');
				}
			});
			
			
			
			$('popup_center').erase('html');

			var myFx2 = new Fx.Elements($('overlay'), {
				onComplete: function(){
					req.send();
				}
			}).start({
				'0': {
					'opacity': [0,.8]
				}
			});

		});
	});
}


window.addEvent('domready', function() {
									 
	//init menu
	if($defined($('menu_hover')))$('menu_hover').setProperty('intial_position',$('menu_hover').getStyle('left'));
	position_array=["437px","529px","616px","701px","793px"];
	$$('.top_menu').each(function(item,index){
		if(item.hasClass('selected_item')){
			$('menu_hover').setStyle('left',position_array[index]);
			return;
		}
	});
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if (version < 7){
		$$('.top_menu_img').addEvents({
			'mouseover':function(){
				this.setStyle('margin-top','-35px');
			},
			'mouseout':function(){
				this.setStyle('margin-top','0');
			}
		});
	}
	
								
	//init gmap + bouton gmap
	var myMap = $$('.gmap');
	myMap.setStyles({
		'opacity':0,
		'display':'block',
		'visibility':'hidden'
	});

	if($defined($('gmap_button'))) 
	{
		if($defined($('top_center_title'))) $('top_center_title').setStyles({
			'margin-bottom':'20px'
		});

		$('gmap_button').addEvent('click',function(){
			
			if(myMap.getStyle('opacity')==0){
				
				var myFx = new Fx.Elements(myMap).start({
							'0': {
								'opacity': [myMap.getStyle('opacity'),1]
							}
						});
	
				
				$('gmap_button').set('html','Desactivar o mapa !')
				$('gmap_button').setStyles({
					'color':'#EC6E00',
					'background':'black'
				});
			}
			else{
				var myFx = new Fx.Elements(myMap).start({
							'0': {
								'opacity': [myMap.getStyle('opacity'),0]
							}
						});
				$('gmap_button').set('html','Activar o mapa !')
				$('gmap_button').setStyles({
					'color':'white',
					'background':'#EC6E00'
				});
			}
			return false;
		});
	}

	//affichage gMap sans image principale
	if($defined($('map'))) 
	{
	
		var bgStyles = $('top_center').getStyles('background-image');
		var bg = bgStyles['background-image']; 
		if(bg == "none")
		{
			$('map').setStyle('opacity', 1);
			if($defined($('gmap_button'))) $('gmap_button').setStyle('display', 'none');
		}
	}

	//affichage - masquage de l'image de déco selon la taille de la fenêtre
    displayDecoration = function() {
        var el = $('main_content');
        if (el == null) return;
        if (el.getSize().x <= 1024) {
            if ($defined($('decoration_top'))) $('decoration_top').setStyle('display', 'none');
            if ($defined($('decoration_bottom'))) $('decoration_bottom').setStyle('display', 'none');
        }
        else {
            if ($defined($('decoration_top'))) $('decoration_top').setStyle('display', 'block');
            if ($defined($('decoration_bottom'))) $('decoration_bottom').setStyle('display', 'block');
        }
    }
    window.addEvent('resize', function(e) {
        displayDecoration();
    });
    displayDecoration();


	//initialisation divers boutons
	$$('.clickable_block').addEvents({
        mouseenter: function() {
            this.setStyle('background-color', '#4D331A');
        },
        mouseleave: function() {
            this.setStyle('background-color', '#392C1E');
        }
    });
    $$('.clickable_block2').addEvents({
        mouseenter: function() {
            this.setStyle('background-color', '#4D331A');
        },
        mouseleave: function() {
            this.setStyle('background-color', '#392C1E');
        }
    });

    $$('.para_cima').addEvent('click', function() {
        var myFx = new Fx.Scroll(window).toTop();
        return false;
    });
    $$('#top_center_button').addEvent('click', function() {
        var myFx = new Fx.Scroll(window).toElement($('main_content'));
        return false;
    });



	//définie les liens ouvrant avec la modalBox
	openPopup();
	
	$$('.fechar').addEvent('click',function(){
		$('popup_container').dissolve({
			onComplete:function(){
				$('overlay').setStyle('opacity',0);
				$('overlay').removeEvent('click');
					
			}
		});
		return false;
	});


});



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

	//fond noir pour la modalBox
	if($defined($('page_container'))) 
	{
		var h = $('page_container').getSize().y;
	}else
	{
		var h = 740+ $('highlights').getSize().y;
	}
	var overlay = new Element('div',{'id':'overlay'}).setStyles({
		'display':'block',
		'height':h,
		/*'left':'0',*/
		'position':'absolute',
		'top':'0',
		'width':'100%',
		'background':'black',
		'z-index':'12',
		'opacity':'0'
	});
	
	$(document.body).adopt(overlay);

	//centrage vertical header gauche
	if($defined($('top_center_content_bloc'))) 
	{
		var el = $('top_center_content_bloc');
		var nameClass = el.get('class');
		if(nameClass.indexOf("header_left")!=-1)
		{
			var top = ((375-el.getSize().y)/2)+36;
			el.setStyles({
				'top':top
			});
		}
	}


    //modification de la hauteur des blocs
    var arrBloc = $$('#page_center > div');

    setSameHeightToBlocs = function() {

        var arrElements = new Array();
        var hMax = 0;
        var ligneComplete = 0;


        while (ligneComplete < 3) {
            var el = arrBloc.shift();
            var nameClass = el.get('class');

            if (nameClass != 'col_1' && nameClass != 'col_1-2' && nameClass != 'col_1-3' && nameClass != 'col_2-3' && nameClass != 'cBoth' && arrBloc.length > 0) {
                setSameHeightToBlocs();
                return;
            }
            switch (nameClass) {
                case 'col_1':
                    ligneComplete += 3;
                    break;
                case 'col_1-2':
                    ligneComplete += 1.5;
                    break;
                case 'col_2-3':
                    ligneComplete += 2;
                    break;
                case 'col_1-3':
                    ligneComplete += 1;
                    break;
                case 'cBoth':
                    ligneComplete = 3;
                    break;
                default:
                    break;
            }
            var nextSibling = el.getNext();            
            if (ligneComplete > 3) {
                arrBloc.unshift(el);
            } else {
                var hEl = el.getSize().y;
                hMax = hEl > hMax ? hEl : hMax;
                arrElements.push(el);
                if (nextSibling == null)
                    ligneComplete = 3;
                else if (nextSibling.get('tag') == 'hr') ligneComplete = 3;
            }

        }
        if (arrElements.length > 1) {
            for (var i = 0; i < arrElements.length; i++) {
                if (arrElements[i].get('class') != "cBoth" && arrElements[i].get('class') != "col_1") arrElements[i].setStyle('height', hMax);
            }
        }
        if (arrBloc.length > 1) setSameHeightToBlocs();

    }


    if (arrBloc.length > 0) setSameHeightToBlocs();


});
