// JavaScript Document

var mediaTag3811 = mediaTag3811 || {};
    
    mediaTag3811 = {
        major : 2,
        minor : 0,
    
        // ------------------------------------------------------------
        // Propri??t??s internes
        // ------------------------------------------------------------
    
        window : null,
        index : 0,
    
        // ------------------------------------------------------------
        // D??finie les diff??rentes propri??t??s
        // ------------------------------------------------------------
    
        utc         : '',
        width       : 0,
        height      : 0,
        type        : 0,
        position     : 1,
        alignH         : 1,
        alignV         : 2,
        bypass         : 0,
    
        render : function(utc, type, width, height, position, alignH, alignV, bypass) {
            this.utc        = utc;
            this.type       = type;
            this.width      = width;
            this.height     = height;
            this.position   = position;
            this.alignH     = alignH;
            this.alignV     = alignV;
            this.bypass     = bypass;

            this.openWindow();    // 1  Essaye une ouverture via un window.open ;          
            if  (navigator.userAgent.toLowerCase().indexOf('win')>0)
            {
                this.openDialog();    // 2  Essaye une ouvertue via un dialogue (IE uniquement)
                //this.openWM();          // 4  Essaye une ouverture via windows media (IE uniquement)
                this.openDEC();            // 8  Essaye une ouverture via le contr?＞le DHTML (IE uniquement)
            }
            this.captureEvent();  // 16 Essaye en capturant l'??v?：nement click dans une page
            this.overrideLinks(); // 32 Surcharge les liens onclick en cas d'??chec
        },
        
        // ------------------------------------------------------------
        // Callback ?  sur les ??vn?：nements onclick
        // ------------------------------------------------------------

        callback : function() {
            mediaTag3811.render(
                mediaTag3811.utc,
                mediaTag3811.type,
                mediaTag3811.width,
                mediaTag3811.height,
                mediaTag3811.position,
                mediaTag3811.alignH,
                mediaTag3811.alignV,
                0
            );
        },
        
        // ------------------------------------------------------------
        // Tente l'ouverture d'une fen?atre via un window.open classique
        // ------------------------------------------------------------
    
        openWindow : function() {
            if (this.bypass & 1) return;
            // Si la fen?atre n'a pas d??j?  ??t?? ouverte
            if (this.isOpen()) return;
            // Obtient les coordonn??es d'affichage
            var _bound = this.getBound();
            // On ouvre la fen?atre
            var _window = window.open(((this.type==0) ? this.utc : 
'about:blank'),'',
                        'top=' + _bound[0] + ',' +
                        'left=' + _bound[1] + ',' +
                        'width=' + _bound[2] + ',' +
                        'height=' + _bound[3] +
                        ((this.type==0) ? ',scrollbars=1, resizable=1, toolbar=1, location=1, menubar=1, status=1, directories=0' : ',resizable=0')
                    );

            // Si la fen?atre est ouverte
            if (_window==null) return
            // On d??place la fen?atre
            if (this.type==1) _window.document.write(this.utc);
            // On mets derri?：re la fen?atre
            if (this.position==1) { _window.blur(); window.focus(); }
            // On indique qu'on a r??ussi ?  l'ouvrir
            this.window = _window;
        },
        
        // ------------------------------------------------------------
        // Tente l'ouverture d'une fen?atre de dialogue
        // ------------------------------------------------------------
    
        openDialog : function() {
            if (this.bypass & 2) return;
            // Si la fen?atre n'a pas d??j?  ??t?? ouverte
            if (this.isOpen()) return;
            // Si showModelessDialog n'est pas accessible
            if (typeof window.showModelessDialog =='undefined' ||
this.type!=0) return;
            // Obtient les coordonn??es d'affichage
            var _bound = this.getBound();
            // On ouvre la fen?atre modale
            try {
                var _window = window.showModelessDialog(this.utc,'',
                    'dialogTop:' + _bound[0] + 'px;' +
                    'dialogLeft:' + _bound[1] + 'px;' +
                    'dialogWidth:' + _bound[2] + 'px;' +
                    'dialogHeight:' + _bound[3] + 'px'
                );
                // On indique qu'on a r??ussi ?  l'ouvrir
                this.window = true;
            } catch(e) { }
        },
        
        // ------------------------------------------------------------
        // Tente l'ouverture via windows media
        // ------------------------------------------------------------

        openWM : function() {
            if (this.bypass & 4) return;
            // Si la fen?atre n'a pas d??j?  ??t?? ouverte
            if (this.isOpen()) return;
            // On insert l'objet
            document.write('<object id="mediaRender3720wm" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" width="0" height="0" style="position:absolute; top:0; left:0"></object>');
            // Obtient l'instance de l'objet
            var _vm = this.$('mediaRender3720wm');
            // Si null on sort
            if (_vm==null || this.type!=0) return;
            // Sinon on execute l'url
            try {
                _vm.launchURL(this.utc);
                // On indique qu'on a r??ussi ?  l'ouvrir
                this.window = true;
            } catch(e) { }
        },
        
        // ------------------------------------------------------------
        // Tente l'ouverture via le composant DHTML
        // ------------------------------------------------------------

        openDEC : function() {
            if (this.bypass & 8) return;
            // Si la fen?atre n'a pas d??j?  ??t?? ouverte
            if (this.isOpen()) return;
            //if(window.navigator.userAgent.indexOf("SV1") != -1){
            document.write('<object id="RendermediaTag3811" classid="clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A" width="1" height="1" style="position:absolute; top:0; left:0"></object>');
            // Obtient l'instance de l'objet
            var _dec = this.$('RendermediaTag3811');
            // Si null on sort
            if (_dec==null) return;
            // Sinon
            _dec.ActivateApplets = '1';
            _dec.ActivateActiveXControls = '1';
            // On passe les commandes ?  ouvrir
            setTimeout("var _dec = mediaTag3811.$('RendermediaTag3811');if (_dec.DOM!=null) { _dec.DOM.Script.open('" + this.utc + "'); mediaTag3811.window = true }", 1000);
        },
        
        // ------------------------------------------------------------
        // Capture l'??v?：nement click de la page
        // ------------------------------------------------------------

        captureEvent : function() {
            if (this.bypass & 16) return;
            // Si la fen?atre n'a pas d??j?  ??t?? ouverte
            if (this.isOpen()) return;
            // On capture l'??v?：nement click
            if (typeof Event != 'undefined') {
                window.captureEvents(Event.CLICK);
                window.onclick = this.callback;
            } else { // IE
                document.onclick = this.callback;
            }
        },
        
        // ------------------------------------------------------------
        // Sur charge les liens d'une fonction onclick
        // ------------------------------------------------------------
    
        overrideLinks : function() {
            if (this.bypass & 32) return;
            // Si la fen?atre n'a pas d??j?  ??t?? ouverte
            if (this.isOpen()) return;
            // Attends le chargement de la page
            this.addLoadEvent(
                function() {
                    // On r??cup?：re l'ensemble des tags A de la page
                      var _tags = document.getElementsByTagName('a');
                    // Pour chaque lien
                        for (var _i=0; _i<_tags.length; _i++)
                        // Si l'??l??ment onclick n'est pas d??j?  d??fini, et qu'il n'y a pas d'attribut target
                           if ((typeof _tags[_i].onclick == 'undefined' || _tags[_i].onclick == null) && _tags[_i].target == '')
                            // On surchage les liens avec notre fonction d'ouverture de fen?atre
                            _tags[_i].onclick = mediaTag3811.callback;                
                }
            );
        },
    
        // ------------------------------------------------------------
        // Attends le chargement de la page est appel la fonction func
        // ------------------------------------------------------------
    
        addLoadEvent : function(func) {
            var oldonload = window.onload;
            if (typeof func == 'undefined') return false;
               if (typeof window.onload != "function") {
                  window.onload = func;
               } else {
                  window.onload = function() {
                     if (oldonload) oldonload();
                     func();
                  };
               }
        },
                writeCookie : function (nom, valeur)
        {
            
            var argv=this.writeCookie.arguments;
            var argc=this.writeCookie.arguments.length;
            var expires=(argc > 2) ? argv[2] : null;
            var path=(argc > 3) ? argv[3] : null;
            var domain=(argc > 4) ? argv[4] : null;
            var secure=(argc > 5) ? argv[5] : false;
            document.cookie=nom+'='+escape(valeur)+
            ((expires==null) ? '' : ('; expires='+expires.toGMTString()))+
            ((path==null) ? '' : ('; path='+path))+
            ((domain==null) ? '' : ('; domain='+domain))+
            ((secure==true) ? '; secure' : '');
        },

        getCookieVal : function (offset)
        {
            var endstr=document.cookie.indexOf (';', offset);
            if (endstr==-1) endstr=document.cookie.length;
            return unescape(document.cookie.substring(offset, endstr));
        },
        readCookie : function (nom)
        {
            var arg=nom+'=';
            var alen=arg.length;
            var clen=document.cookie.length;
            var i=0;
            while (i<clen)
            {
            var j=i+alen;
            if (document.cookie.substring(i, j)==arg) return this.getCookieVal(j);
            i=document.cookie.indexOf(' ',i)+1;
            if (i==0) break;

            }
            return null;
        },
        // ------------------------------------------------------------
        // V??rifie si la fen??tre est ouverte
        // ------------------------------------------------------------
    
        isOpen : function() {
            if (this.readCookie('isAllwayopen')!=null)
                return true;    
                        
            if(this.window==null) return false;
            
            try {
                
                if (!this.window.closed) {
                    this.writeCookie('isAllwayopen','1');
                    return true;
                }
                
                return !this.window.closed;
            } catch(e){
                return false;
            }
        },
        
        // ------------------------------------------------------------
        // Retourne le rectangle d'affichage
        // ------------------------------------------------------------
    
        getBound : function() {
            // On g?：re le positionnement de la fen?atre
            var _clientWidth  = screen.availWidth;
            var _clientHeight = screen.availHeight;
                
            var _top = 0;
            var _height = this.height;
            
            //Si height vaut z??ro, on affiche en pleine hauteur
            if (this.height==0) {
                _height = _clientHeight;
            } else {
                if (this.alignV == 1) _top = (_clientHeight - this.height)/2;    
                if (this.alignV == 2) _top = _clientHeight - this.height - 46;
            }
    
            var _left = 0;
            var _width = this.width;
                
            //Si width vaut z??ro, on affiche en pleine largeur
            if (this.width==0) {
                _width = _clientWidth;
            } else {
                if (this.alignH == 1) _left = (_clientWidth - this.width)/2;
                if (this.alignH == 2) _left = _clientWidth - this.width - 10;
            }
            
            // Retourne les donn??es
            return [_top, _left, _width, _height];
        },
        
        // ------------------------------------------------------------
        // Retourne l'??lement dont l'id est pass?? en param?：tre
        // ------------------------------------------------------------

        $ : function(id) {
            return document.getElementById(id);
        }        
    }
    
    // ------------------------------------------------------------
    // Effectue l'affichage de la banni?：re
    // ------------------------------------------------------------
    
    mediaTag3811.render("http://www.bargamzik.com/", 0 , 0,0,1,1,1,0);
                 
                
