/*=============INTRO===============*/
$(document).ready (function() {
    $("#main_intro").css("height","0");
    $("#main_intro").css("width","0");
    $("#logo_intro").css("display","none");    
});

function lance_animation() {setTimeout("animation()",3000);}
function animation () 
{
    $("#loader_intro").fadeOut(500);
        $("#main_intro").animate({ height: 640 }, 800, function () {
            $("#main_intro").animate({ width: 960 }, 1000, function () {        
                $("#logo_intro").slideDown(1000);                               
            });
        });
}


var _effect_out = 500;
var _effect_in = 350;

/*=============SOUS MENUS===============*/
$(document).ready (function() {
	$(".sub_menu").bind("click", function() {
		$("#sub_menu_a_partager").hide(_effect_out);
		$("#sub_menu_ambiance").hide(_effect_out);
		$("#sub_menu_esprit").hide(_effect_out);
		$("#sub_menu_vintage").hide(_effect_out);
		$("#sub_menu").show(_effect_in);
	});
	/*$(document).bind("click", function() {
		$("#sub_menu").hide(1000);
	});*/
});

/*=============SOUS MENUS===============*/
$(document).ready (function() {
    /*if(page == 'partager')
    {
		$("#sub_menu_a_partager").show(2000);
	}*/

	$(".sub_menu_a_partager").bind("click", function() {
		$("#sub_menu").hide(_effect_out);
		$("#sub_menu_ambiance").hide(_effect_out);
		$("#sub_menu_esprit").hide(_effect_out);
		$("#sub_menu_vintage").hide(_effect_out);
		$("#sub_menu_a_partager").show(_effect_in);
		
	});
	/*$(document).bind("click", function() {
		$("#sub_menu_a_partager").hide(1000);
	});*/
});

/*=============SOUS MENUS===============*/
$(document).ready (function() {
    /*if(page == 'partager')
    {
		$("#sub_menu_a_partager").show(2000);
	}*/

	$(".sub_menu_esprit").bind("click", function() {
		$("#sub_menu").hide(_effect_out);
		$("#sub_menu_ambiance").hide(_effect_out);
		$("#sub_menu_a_partager").hide(_effect_out);
		$("#sub_menu_vintage").hide(_effect_out);
		$("#sub_menu_esprit").show(_effect_in);
	});
	/*$(document).bind("click", function() {
		$("#sub_menu_esprit").hide(1000);
	});*/
});

/*=============SOUS MENUS===============*/
$(document).ready (function() {
    
    /*if(page == 'ambiances' || page == 'ambiances2')
    {
        $("#sub_menu_ambiance").show(2000);   
    }*/
	
	$(".sub_menu_ambiance").bind("click", function() {
		$("#sub_menu").hide(_effect_out);
		$("#sub_menu_esprit").hide(_effect_out);
		$("#sub_menu_a_partager").hide(_effect_out);
		$("#sub_menu_vintage").hide(_effect_out);
		$("#sub_menu_ambiance").show(_effect_in);
	});
	/*$(document).bind("click", function() {
		$("#sub_menu_ambiance").hide(1000);
	});*/
});

/*=============SOUS MENUS===============*/
$(document).ready (function() {
    
    /*if(page == 'ambiances' || page == 'ambiances2')
    {
        $("#sub_menu_ambiance").show(2000);   
    }*/
	
	$(".sub_menu_vintage").bind("click", function() {
		$("#sub_menu").hide(_effect_out);
		$("#sub_menu_esprit").hide(_effect_out);
		$("#sub_menu_a_partager").hide(_effect_out);
		$("#sub_menu_ambiance").hide(_effect_out);
		$("#sub_menu_vintage").show(_effect_in);
	});
	/*$(document).bind("click", function() {
		$("#sub_menu_vintage").hide(1000);
	});*/
});

/*=============LES PRODUITS && RECHERCHE===============*/
$(document).ready (function() {
    if((page == 'univers') || (page == 'search'))
    {
        /*$('.produits_btn').hover(function(){
                $(this).find('.nom_produit_bg').animate({marginTop: '170px', height: '70px'},{queue:false, duration:500});
            }, function(){
                $(this).find('.nom_produit_bg').animate({marginTop: '240px', height: '0px'},{queue:false, duration:500});
        });*/
		$('.produits_btn').mouseover(function(){
               /*if($.contains(this, e.relatedTarget) == false) {
					$(this).css('display', 'none');
				}*/
				
				$(this).parent().children('.nom_produit_bg').stop(true,true).animate({marginTop: '170px', height: '70px'},{queue:false, duration:500});
            });
		$('.produits_btn').mouseout(function(e){
				if($(e.relatedTarget).attr('class')!='nom_produit' && $(e.relatedTarget).attr('class')!='nom_produit_bg') {
					$(this).parent().children('.nom_produit_bg').stop(true,true).animate({marginTop: '240px', height: '0px'},{queue:false, duration:500});
				}
                
        });
    }
});


/*=============LES PRAUTIONS PRESSE===============*/
$(document).ready (function() {
    if(page == 'presse')
    {
        /*$('.presse_btn').hover(function(){
                $(this).find('.nom_presse_bg').animate({marginTop: '170px', height: '70px'},{queue:false, duration:500});
            }, function(){
                $(this).find('.nom_presse_bg').animate({marginTop: '240px', height: '0px'},{queue:false, duration:500});
        });*/
		
		$('.presse_btn').mouseover(function(){
               /*if($.contains(this, e.relatedTarget) == false) {
					$(this).css('display', 'none');
				}*/
				
				$(this).parent().children('.nom_presse_bg').stop(true,true).animate({marginTop: '170px', height: '70px'},{queue:false, duration:500});
            });
		$('.presse_btn').mouseout(function(e){
				if($(e.relatedTarget).attr('class')!='nom_presse' && $(e.relatedTarget).attr('class')!='nom_presse_bg') {
					$(this).parent().children('.nom_presse_bg').stop(true,true).animate({marginTop: '240px', height: '0px'},{queue:false, duration:500});
				}
                
        });
    }
});


/*=============LES AMBIANCES===============*/
$(document).ready (function() {
    if(page == 'ambiances' )
    {
        $('.salon_btn').hover(function(){
                $(this).find('.nom_salon_bg_position').animate({height: '390px'},{queue:false, duration:400});
            }, function(){
                $(this).find('.nom_salon_bg_position').animate({height: '438px'},{queue:false, duration:350});
        });
    }
});


/*=============PANIER===============*/
function afficher(id) 
{
    document.getElementById(id).style.display = 'block';
}
function cacher(id) 
{
    document.getElementById(id).style.display = 'none';
}
/*$(function() {
    $('.next').click(function(){
        alert('on passe à la page suivante');
    });
});

$(function() {
    $('#visu_panier').click (function() {
        alert('toto');
    });
});*/



/*=============TPL_GLOBAL===============*/
$(document).ready (function() {        
    $('#tpl_global').ready(function(){
        $('#tpl_global').show(600, function() {
            /* effet de la page un esprit */
            if(page == 'esprit' || page == 'partager' || page == 'ambiances2')
            {
                $('#infos_esprit').fadeIn(1000, function() {
                    $('#photo').slideDown(1000);                          
                });
            }    
            /* effet de la page un contact */
            if(page == 'contact')
            {
                $('#infos_contact').fadeIn(1000, function() {
                    $('#photo').slideDown(1000);                          
                });
            }    
            /* effet de la page les ambiances */
            if(page == 'ambiances')
            {
                $('.salon_btn').show(600);
            }
            /* effet de la page de boutiques */
            if(page == 'boutiques')
            {    
                $('#google_map').show(800, function() {
                    $('#pointsVentes').fadeIn(1200);
                });
            }
        });
    });
});


/*=============PRECHARGEMENT D'IMAGES===============*/
function MM_preloadImages() {
          var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
MM_preloadImages('/images/bg_tpl_global.png', '/images/ambiances/01_07.jpg', '/images/ambiances/09_07.jpg', '/images/ambiances/01_08.jpg', '/images/ambiances/01_09.jpg');


function PopupCentrer(page,name,largeur,hauteur,options) 
{
    var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;
    window.open(page,name,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
    
function openShadowbox( _page, _width, _height, _player) {

    if(typeof(_width) == 'undefined' ){
        _width = 950;
    }
    if(typeof(_height) == 'undefined'){
        _height = 800;
    }        
    if(typeof(_player) == 'undefined'){
        _player = 'iframe';
    }    
    Shadowbox.open({player:_player, content:_page, height:_height, width:_width, options:{fadeDuration:0.1, resizeDuration:0.1, animSequence:"sync"}});
}

function openShadowboxImg( _url) 
{
    Shadowbox.open({player:'img', content:_url, options:{fadeDuration:0.1, resizeDuration:0.1, animSequence:"sync"}});    
}

function closeShadowbox( _goto ) {
    Shadowbox.close();
    
    if(typeof(_goto) != 'undefined')
        document.location.replace(_goto);
}

function is_mail(mail){
    var filter_email=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return filter_email.test(mail);
}

function is_date(_date)
{
    var filter_date=/^(01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\/(01|02|03|04|05|06|07|08|09|10|11|12)\/\d{4}$/;
    return filter_date.test(_date);    
}


function initScreenshot() 
{
    
    Dom.getElementsBy(function(e){return e.className=='screenshot';}, 'a', document.body, function(e) {
        YAHOO.util.Event.addListener(e, "mouseover", function(ev) {
            var p = document.createElement('p');
            p.id = 'screenshot';
            p.innerHTML += e.rel;
            document.body.appendChild(p);
            Dom.setStyle(p,'top',(YAHOO.util.Event.getPageY(ev) + 10) + "px");
            Dom.setStyle(p,'left',(YAHOO.util.Event.getPageX(ev) -350) + "px");
            Dom.setStyle(p,'display','block');
            });
        YAHOO.util.Event.addListener(e, "mouseout", function(ev) {
            if(Dom.get('screenshot')) {    
                document.body.removeChild(Dom.get('screenshot'));
            }
            });
        YAHOO.util.Event.addListener(e, "mousemove", function(ev) {
            Dom.setStyle('screenshot','top',(YAHOO.util.Event.getPageY(ev) + 10) + "px");
            Dom.setStyle('screenshot','left',(YAHOO.util.Event.getPageX(ev) -350) + "px");
            }); 
    });
}

function initScreenshot2() 
{
    Dom.getElementsBy(function(e){return e.className=='screenshot2';}, 'a', document.body, function(e) {
        YAHOO.util.Event.addListener(e, "mouseover", function(ev) {
            var p = document.createElement('p');
            p.id = 'screenshot2';
            p.innerHTML += e.rel;
            document.body.appendChild(p);
            Dom.setStyle(p,'top',(YAHOO.util.Event.getPageY(ev) + 10) + "px");
            Dom.setStyle(p,'left',(YAHOO.util.Event.getPageX(ev) + 10) + "px");
            Dom.setStyle(p,'display','block');
            });
        YAHOO.util.Event.addListener(e, "mouseout", function(ev) {
            if(Dom.get('screenshot2')) {    
                document.body.removeChild(Dom.get('screenshot2'));
            }
            });
        YAHOO.util.Event.addListener(e, "mousemove", function(ev) {
            Dom.setStyle('screenshot2','top',(YAHOO.util.Event.getPageY(ev) + 10) + "px");
            Dom.setStyle('screenshot2','left',(YAHOO.util.Event.getPageX(ev) + 10) + "px");
            }); 
    });
}

var t_res;
function preload( t_img ) 
{
    t_res = new Array()
    for(var i=0;i<t_img.length;i++)
    {
        var el = new Image();
        el.src = t_img[i];
        t_res.push( el );
    }
}

function nqToolTip() {
    xOffset = 5;
    yOffset = 5;
    
    Dom.getElementsBy(function(e){return e.className=='screenshot';}, 'a', document.body, function(e) {
        YAHOO.util.Event.addListener(e, "mouseover", function(ev) {
            var p = document.createElement('p');
            p.id = 'screenshot';
            p.innerHTML += "<img src='"+ e.rel +"' />";
            document.body.appendChild(p);
            Dom.setStyle(p,'top',(YAHOO.util.Event.getPageY(ev) + xOffset) + "px");
            Dom.setStyle(p,'left',(YAHOO.util.Event.getPageX(ev) + yOffset) + "px");
            Dom.setStyle(p,'display','block');
            });
        YAHOO.util.Event.addListener(e, "mouseout", function(ev) {
            document.body.removeChild(Dom.get('screenshot'));
            });
        YAHOO.util.Event.addListener(e, "mousemove", function(ev) {
            Dom.setStyle('screenshot','top',(YAHOO.util.Event.getPageY(ev) + xOffset) + "px");
            Dom.setStyle('screenshot','left',(YAHOO.util.Event.getPageX(ev) + yOffset) + "px");
            }); 
    });
    
}

// IMAGE DU HEADER ALEATOIRE
var header_rand; 
function imagealeatoire() { 
    header_rand = Math.floor(4 * Math.random() + 1);
    return header_rand;
}


/********************************************
* fading div
*/
var anim_nq_fade;
function nq_fade(_div_disappear, _div_appear, _time)
{
    anim_nq_fade = new YAHOO.util.Anim(_div_disappear, { opacity: { to: 0} }, _time, YAHOO.util.Easing.easeOut);
    anim_nq_fade.onComplete.subscribe(nq_fade_callback, {div_disappear:_div_disappear, div_appear:_div_appear, time:_time}, true);
    anim_nq_fade.animate();            
}

function nq_fade_callback(_div_disappear, _div_appear, _time)
{
    Dom.setStyle(this.div_disappear, 'display', 'none');
    Dom.setStyle(this.div_disappear, 'visibility', 'hidden');    
    Dom.setStyle(this.div_appear, 'opacity', 0);
    Dom.setStyle(this.div_appear, 'display', 'block');
    Dom.setStyle(this.div_appear, 'visibility', 'visible');        
    
    anim_nq_fade = new YAHOO.util.Anim(this.div_appear, { opacity: { to: 1} }, this.time, YAHOO.util.Easing.easeIn);
    anim_nq_fade.animate();    
}


/********************************************
* accordeon div
*/
var anim_nq_accordeon;
function nq_accordeon(_div_disappear, _div_appear, _time)
{
    anim_nq_accordeon = new YAHOO.util.Anim(_div_disappear, { height: { to: 0} }, _time, YAHOO.util.Easing.easeOut);
    anim_nq_accordeon.onComplete.subscribe(nq_accordeon_callback, {div_disappear:_div_disappear, div_appear:_div_appear, time:_time}, true);
    anim_nq_accordeon.animate();            
}

function nq_accordeon_callback(_div_disappear, _div_appear, _time)
{
    var region = Dom.getRegion(Dom.get(this.div_appear).parentNode);
    
    anim_nq_accordeon = new YAHOO.util.Anim(this.div_appear, { height: { to: region['bottom']-region['top']} }, this.time, YAHOO.util.Easing.easeIn);
    anim_nq_accordeon.animate();    
}


/********************************************
* Scrollbar
*/
function nq_scrollbar(id_curseur_scrollbar, id_fond_scrollbar, id_conteneur_html)
{
    var Dom = YAHOO.util.Dom;

    if(Dom.get(id_conteneur_html).scrollHeight <= parseInt(Dom.getStyle(id_conteneur_html, 'height'), 10) )
    {
        Dom.setStyle(id_fond_scrollbar, 'display', 'none');
        Dom.setStyle(id_fond_scrollbar, 'visibility', 'hidden');        
		
        return;
    }
    else
    {
        //Dom.setStyle(id_fond_scrollbar, 'display', 'block');
        //Dom.setStyle(id_fond_scrollbar, 'visibility', 'visible');                
    }

    var Event = YAHOO.util.Event;
    var dd1;

    YAHOO.example.DDRegion = function(id, sGroup, config) {
        this.cont = config.cont;
        this.cont_html = config.cont_html;
        this.ev = null;
        this.myAnim = new YAHOO.util.Scroll(this.cont_html, { scroll: { to: [0, 0] } }, 0, YAHOO.util.Easing.easeNone);
        YAHOO.example.DDRegion.superclass.constructor.apply(this, arguments);
    };

    YAHOO.extend(YAHOO.example.DDRegion, YAHOO.util.DD, {
        cont: null,
        init: function() {
            //Call the parent's init method
            YAHOO.example.DDRegion.superclass.init.apply(this, arguments);
            this.initConstraints();

            Event.on(window, 'resize', function() {
                this.initConstraints();
            }, this, true);
        },
        

        onDrag: function(e) {
            Event.stopPropagation(this.ev);
            if(!this.myAnim.isAnimated())
            {
                //Get the top, right, bottom and left positions
                var region = Dom.getRegion(this.cont);
    
                //Get the element we are working on
                var el = this.getEl();
    
                //Get the xy position of it
                var xy = Dom.getXY(el);
    
                //Get the width and height
                var height = parseInt(Dom.getStyle(el, 'height'), 10);
    
                //Set top to y minus top
                var top = xy[1] - region.top;
        
                var percent = top / (region.bottom - region.top - height) ;
                //document.title = percent ;
                var height_html = Dom.get(this.cont_html).scrollHeight - parseInt(Dom.getStyle(this.cont_html, 'height'), 10);

                this.myAnim = new YAHOO.util.Scroll(this.cont_html, { scroll: { to: [0, height_html*percent] } }, 0, YAHOO.util.Easing.easeNone);
                this.myAnim.animate();
            }
        },
        
        goTo: function(e) {
            if(Event.getTarget(e).id == this.cont && !this.myAnim.isAnimated())
            {
                //Get the top, right, bottom and left positions
                var region = Dom.getRegion(this.cont);
    
                //Get the xy position of it
                var xy = Event.getXY(e);
            
                var el = this.getEl();                
                
                var height_cont = parseInt(Dom.getStyle(this.cont, 'height'), 10);
                var height_curs = parseInt(Dom.getStyle(el, 'height'), 10);
                var mouse_pos_page = xy[1] - region.top;

                var pos_cur;
                var percent;
                if(mouse_pos_page < height_curs/2){
                    pos_cur = 0;
                    percent = 0;
                }
                else if(mouse_pos_page > height_cont - height_curs/2 ){
                    pos_cur = height_cont - height_curs;
                    percent = 1;
                }
                else{
                    pos_cur = mouse_pos_page - height_curs/2;
                    percent = mouse_pos_page / (region.bottom - region.top) ;
                }
                
                Dom.setY(el, region.top + pos_cur);                
            
                var height_html = Dom.get(this.cont_html).scrollHeight - parseInt(Dom.getStyle(this.cont_html, 'height'), 10);
                
                this.myAnim = new YAHOO.util.Scroll(this.cont_html, { scroll: { to: [0, height_html*percent] } }, 0.3, YAHOO.util.Easing.easeOut);
                this.myAnim.animate();
            }
        },
        
        initConstraints: function() {
            //Get the top, right, bottom and left positions
            var region = Dom.getRegion(this.cont);

            //Get the element we are working on
            var el = this.getEl();
            

            this.ev = YAHOO.util.Event.addListener(this.cont, "click", this.goTo, this, true); 

            //Get the xy position of it
            var xy = Dom.getXY(el);

            //Get the width and height
            var width = parseInt(Dom.getStyle(el, 'width'), 10);
            var height = parseInt(Dom.getStyle(el, 'height'), 10);

            //Set left to x minus left
            var left = xy[0] - region.left;

            //Set right to right minus x minus width
            var right = region.right - xy[0] - width;


            //Set top to y minus top
            var top = xy[1] - region.top;

            //Set bottom to bottom minus y minus height
            var bottom = region.bottom - xy[1] - height;
            
            //Set the constraints based on the above calculations
            this.setXConstraint(left, right);
            this.setYConstraint(top, bottom);
        }
    });
;
    dd1 = new YAHOO.example.DDRegion(id_curseur_scrollbar, '', { cont: id_fond_scrollbar, cont_html:id_conteneur_html });
}

// JavaScript Document
var tab_direction_scroll = new Array();

/***************************************
/ Fonction qui gère les déplacements  des blocs
/ Tous les paramètres sont optionnels et peuvent être remplacés par le booleen false
/ Valeurs possibles
/ sens_scroll : "horizontal" / "vertical" / false
/ direction_scroll : "plus" / "moins" / false
/ timeout_relance : false / un entier représentant le nombre de millisecondes avant le déclanchement
/***************************************/
var nq_scroll = function(id_conteneur, id_contenu, sens_scroll, direction_scroll, timeout_relance) {
    if(!id_conteneur) {id_conteneur = 'nd_conteneur_scroll';}
    if(!id_contenu) {id_contenu = 'nd_contenu_scroll';}
    if(!sens_scroll){
        sens_scroll = 'horizontal';
    }
    if(!direction_scroll){
        direction_scroll = 'plus';
    }
    // on stocke la direction pour ce conteneur pour les futurs appels
    if(typeof(tab_direction_scroll[id_conteneur])=='undefined') {
        tab_direction_scroll[id_conteneur] = direction_scroll;
    }
    if(!timeout_relance){timeout_relance = 0;}
    
    // on commence par récupérer la taille du scroll
    // ensuite on en déduit l'attribut de l'annimation
    // et enfin on calcule la direction pour la prochaine animation du conteneur
    var tabRegionConteneur = Dom.getRegion(id_conteneur);
    var tabRegionContenu = Dom.getRegion(id_contenu);
    if(sens_scroll=='horizontal') {
        var tailleConteneur = tabRegionConteneur['right']-tabRegionConteneur['left'];
        // on calcule l'indice courant et on en déduit l'index suivant
        var index_courant = Math.round(Dom.get(id_conteneur).scrollLeft/tailleConteneur);
        if(tab_direction_scroll[id_conteneur]=='plus'){
            var index_suivant = index_courant+1;
        }
        else {
            var index_suivant = index_courant-1;
        }
        var attributes = {scroll: { to: [index_suivant*tailleConteneur,0]}};
        
        var tailleContenu = tabRegionContenu['right'] - tabRegionContenu['left'];
        if(attributes.scroll.to[0] >= tailleContenu-tailleConteneur) {
            tab_direction_scroll[id_conteneur] = 'moins';
        }
        
        if(attributes.scroll.to[0] ==0)
        {
            tab_direction_scroll[id_conteneur] = 'plus';
        }
    }
    else {
        var tailleConteneur = tabRegionConteneur['bottom']-tabRegionConteneur['top'];
        // on calcule l'indice courant
        var index_courant = Math.round(Dom.get(id_conteneur).scrollTop/tailleConteneur);
        if(tab_direction_scroll[id_conteneur]=='plus'){
            var index_suivant = index_courant+1;
        }
        else {
            var index_suivant = index_courant-1;
        }
        var attributes = {scroll: { to: [0,index_suivant*tailleConteneur]}};
        
        var tailleContenu = tabRegionContenu['bottom'] - tabRegionContenu['top'];
        if(attributes.scroll.to[1] >= tailleContenu-tailleConteneur) {
            tab_direction_scroll[id_conteneur] = 'moins';
        }
        
        if(attributes.scroll.to[1]==0)
        {
            tab_direction_scroll[id_conteneur] = 'plus';
        }
    }
            
    // on anime le scroll
    var anim_scroll_nq = new YAHOO.util.Scroll(id_conteneur, attributes, 1, YAHOO.util.Easing.easeOut);
    anim_scroll_nq.animate();
    
    
    // on relance l'animation si c'est demandé
    if(timeout_relance>0) {
        window.setTimeout('nq_scroll("'+id_conteneur+'", "'+id_contenu+'", "'+sens_scroll+'", false, "'+timeout_relance+'");',timeout_relance);
    }
}


/***************************************
/ Fonction qui parcourt tout les éléments ayant la classe spécifiée de la div spécifiée
/ Elle prend la taille maximale de ces éléments et redimensionne la div conteneur avec cette taille
/ Parametres :
/ id_container
/ content_tagname ('div' / 'td' / 'p' / ...)
/ content_classname
/ resize_width : true / false
/ resize_heigth : true / false
/ animation_duration : 0 pour ne pas animer le resize, temps de l'animation sinon
/***************************************/
var update_container_dimensions = function(id_container, content_tagname, content_classname, resize_width, resize_height, animation_duration) {
    // on déclare les variable qui vont contenir la largeur et la hauteur maximales
    var height=0;
    var width = 0;
    // on récupère tous les contenus du container
    var t_contents = Dom.getElementsBy(function(el){return el.className==content_classname;}, content_tagname, id_container);
    var i,t_current_region,current_width,current_height;
    // on parcourt tous les contenus en ne conservant que la plus grande dimension !
    for(i=0; i<t_contents.length; i++) {
        // on supprime l'éventuelle hauteur et largeur définies
        if(resize_width) {
            Dom.setStyle(t_contents[i], 'width', 'auto');
        }
        if(resize_height) {
            Dom.setStyle(t_contents[i], 'height', 'auto');
        }
        
        // on calcule la région pour avoir la largeur et la hauteur
        t_current_region = Dom.getRegion(t_contents[i]);
        
        // on vérifie si ces dimensions sont supérieures aux précédentes
        if(resize_width) {
            current_width = t_current_region['right']-t_current_region['left'];
            width = Math.max(width,current_width);
        }
        if(resize_height) {
            current_height = t_current_region['bottom']-t_current_region['top'];
            height = Math.max(height,current_height);
        }
    }
    
    // on met tous les contenus à la taille du plus grand contenu
    for(i=0; i<t_contents.length; i++) {
        if(resize_width) {
            Dom.setStyle(t_contents[i], 'width', width+'px');
        }
        if(resize_height) {
            Dom.setStyle(t_contents[i], 'height', height+'px');
        }
    }
    
    // on met pour finir le conteneur à la nouvelle taille
    if(animation_duration==0) {
        if(resize_width) {
            Dom.setStyle(id_container, 'width', width+'px');
        }
        if(resize_height) {
            Dom.setStyle(id_container, 'height', height+'px');
        }
    }
    else {
        var attributes = {};
        if(resize_width) {
            attributes.width = { to: width };
        }
        if(resize_height) {
            attributes.height = { to: height };
        }
        
        var resizeAnim = new YAHOO.util.Anim(id_container, attributes, animation_duration, YAHOO.util.Easing.easeOut);
        resizeAnim.animate();
    }
    
}



var AjaxFormSubmiterObject = {

    handleSuccess:function(o){
        try{
            eval(o.responseText);            
        }catch(e){
            alert('Erreur');    
        }
        
    },

    handleFailure:function(o){
            alert('Erreur');    
    },

    processResult:function(o){

    },

    startRequest:function(formObject) {
        YAHOO.util.Connect.setForm(formObject); 
        YAHOO.util.Connect.asyncRequest('POST', formObject.action, callbackFormSubmit);
    }

};

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callbackFormSubmit= {
    success:AjaxFormSubmiterObject.handleSuccess,
    failure:AjaxFormSubmiterObject.handleFailure,
    scope:AjaxFormSubmiterObject
};    


var AjaxGetterObject = {

    handleSuccess:function(o){
        Dom.get('div_content_text').innerHTML = o.responseText;
        nq_scrollbar('scroll_selector', 'scroll', 'div_content_text');
    },

    handleFailure:function(o){
            alert('Erreur');    
    },

    processResult:function(o){

    },

    startRequest:function(_page) {
        YAHOO.util.Connect.asyncRequest('GET', _page, callbackAjaxGetterObject);
    }

};

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callbackAjaxGetterObject= {
    success:AjaxGetterObject.handleSuccess,
    failure:AjaxGetterObject.handleFailure,
    scope:AjaxGetterObject
};    


function error_handler(_msg)
{
    alert(_msg);    
}

function success_handler_connect()
{
	top.document.location.reload();	
}

function success_handler_inscription(msg)
{
	alert(msg);
	top.$.nyroModalRemove();	
}

function success_handler(_msg, _redirect)
{
    if(_msg != ''){
        alert(_msg);    
    }    
    
    if(_redirect != ''){
        document.location.replace(_redirect);    
    }
}

function align()
{

	var lmt = document.getElementById('main');
	var container = document.documentElement;
	
	if(lmt && container)
	{
	    var containerHeight;
	    if (container.innerWidth)
	    {
            containerHeight = container.innerHeight;
		}
		else
		{
            containerHeight = container.clientHeight;
		}
	    var lmtHeight;
	    if (lmt.innerWidth)
	    {
            lmtHeight = lmt.innerHeight;
		}
		else
		{
            lmtHeight = lmt.offsetHeight;
		}
		var y = Math.ceil((containerHeight - lmtHeight) / 2);
		if(y < 0)
		{
			y = 0;
		}
		lmt.style.position = "relative";
		lmt.style.top = y + "px";
	}

}

function addevent(obj,evt,fn,capt){
	if(obj.addEventListener)
	{
		obj.addEventListener(evt, fn, capt);
		return true;
	}
	else if(obj.attachEvent)
	{
		obj.attachEvent('on'+evt, fn);
		return true;
	}
	else return false;
}

if (document.getElementById && document.getElementsByTagName)
{
	addevent(window, 'load', align, false);
	addevent(window, 'resize', align, false);
}