
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 ) {
    Shadowbox.open({player:'iframe',content:_page,height:800,width:950, options:{fadeDuration:0.1, resizeDuration:0.1, animSequence:"sync"}});
}

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

function openShadowboxVideo( _lecteur ) {
    Shadowbox.open({player:'flv',content:_lecteur, height:450,width:600,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 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 += "Cliquez sur l'image pour l'afficher dans l'écran.<br/>Cliquez sur la loupe pour zoomer sur l'image.";
            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('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) + 10) + "px");
            }); 
    });
}


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;
    }

    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 });
}
