/**
 * 
 * PROMO $.la.promo.showSkin(params) $.la.promo.localCss(params)
 * $.la.promo.localCssAfter(params) $.la.promo.wreportRefresh()
 * $.la.promo.bannerRefresh(uri) $.la.promo.adLoad(index)
 * $.la.promo.adsProcess() $.fn.adRegister(id,defer) ** GOOGLE ADSENSE
 * $.la.promo.google.adsense._createHtml.container(sId)
 * $.la.promo.google.adsense.execute()
 * $.la.promo.google.adsense.display(google_ads, google_info) ** PUB IFRAME
 * $.la.promo.pub_iframe.isVisible(elt) $.la.promo.pub_iframe.calcIframeSize()
 */

(function($){

    $.la = $.la||{};
    
    $.la.modules.require('la.utils');

    $.extend(true, $.la,
    {
        modules:{
            la :{
                modules:{
                	promo: {
                		active: true
                	}
                }
            }
        },
        promo: {

             showInterstitiel: function (obj) {

                       var opts = $.extend(true, $.la.promo.interstitiel.defaultValues, obj);

                       $.la.promo.interstitiel.show(opts);
                   },
                   interstitiel:{
                        /*
                        //Flash classique en 994px
                        javascript:jQuery.la.promo.showInterstitiel({time:20,bodybgcolor:'#000000',bodybgimage:'http://video.premiere.fr/regiepub/Premiere/prehome/bg_interstitiel_topbottom.png',mediaType:'swf',mediaUrl:'http://video.premiere.fr/regiepub/Premiere/interstitiels/laproie.swf', mediaWidth:'994',mediaHeight:'470',url:'http://www.premiere.fr/film/toto',newwindow:1,seanceUrl:'http://people.premiere.fr',newwindowseance:1});
                        //Image
                        javascript:jQuery.la.promo.showInterstitiel({time:20,bodybgcolor:'#000000',bodybgimage:'http://video.premiere.fr/regiepub/Premiere/prehome/bg_interstitiel_topbottom.png',mediaType:'img',mediaUrl:'http://cdn-premiere.ladmedia.fr/var/premiere/storage/images/cinema/news-cinema/affaire-dsk-a-quand-le-film-2751870/43919512-1-fre-FR/Affaire-DSK-a-quand-le-film.jpg', mediaWidth:'470',mediaHeight:'318',url:'http://www.premiere.fr/film/toto',newwindow:1,seanceUrl:'http://people.premiere.fr',newwindowseance:1});
                        //Iframe
                        javascript:jQuery.la.promo.showInterstitiel({time:20,iframe: 'http://video.premiere.fr/regiepub/Premiere/interstitiels/megamind/index.htm'});

                        */

                       container:'#container',
                        visible:false,
                        callback:'',
                        interstitielLoaded:false,
                       defaultValues:{topObjectHeiht:'60', bottomObjectHeiht:'60', bodybgimage:'http://video.premiere.fr/regiepub/Premiere/prehome/bg_interstitiel_topbottom.png', bodybgcolor:'#000000',mediaWidth:'994',mediaHeight:'470',newwindow:0,newwindowseance:0},

                        show:function(obj) {

                            var css = '';
                            // avant
                            css += this.localCss(obj);
                            //
                            css += this.getHeadStyle(obj);
                            //
                            css += this.localCssAfter(obj);

                            $('head').append('<style class="la-promo-interstitiel-style" type="text/css">' + css + '</style>');

                            $.la.promo.interstitiel.write(obj);
                            $.la.promo.interstitiel.interstitielLoaded = true;
                            $("#la-promo-interstitiel-div .bloc_interstitiel_top a").click(function() {
                               $.la.promo.interstitiel.remove();
                            });
                        },
                        localCss:function(obj){
						    return '';
					    },
                            localCssAfter:function(obj){
                            return '';
                        },

                        getHeadStyle:function(obj){

                          if ($('#la-promo-showskin-a').length > 0) {
                              $('#la-promo-showskin-a').hide();
                          }

                            width = parseInt(obj.mediaWidth) < 994 ? 994: obj.mediaWidth;
                            height = parseInt(obj.mediaHeight) + parseInt(obj.topObjectHeiht) + parseInt(obj.bottomObjectHeiht) + 10;
                            margin = parseInt(height / 2);

                            css =  'body {overflow:hidden}\n' +
                                    '#la-promo-interstitiel-div {height:100%; width:100%; z-index:9999; position: fixed; top: 0; left: 0; overflow: hidden; background-color:' + obj.bodybgcolor +'; }\n' +
                                   '#la-promo-interstitiel-div-container {position:absolute; top:50%; left:50%; width:' + width + 'px; height:' +  height + 'px; margin:-' + parseInt(height / 2) + 'px 0 0 -' + parseInt(width / 2) + 'px;}\n' +
                                   '#la-promo-interstitiel-div-container .bloc_interstitiel_top, #la-promo-interstitiel-div-container .bloc_interstitiel_bottom{height:' + obj.topObjectHeiht + 'px;background:url(' + obj.bodybgimage + ') left top no-repeat; margin: auto; width: 994px;}\n' +
                                   '#la-promo-interstitiel-div-container .bloc_interstitiel_bottom {background-position:left -75px; margin-top:10px;}\n' +
                                    '#la-promo-interstitiel-div-container .bloc_interstitiel_top .logo{float:left;width:230px;height:55px;}\n' +
                                    '#la-promo-interstitiel-div-container .bloc_interstitiel_top .link{float:right;width:230px;height:55px;}\n' +
                                    '#la-promo-interstitiel-div-container .bloc_interstitiel_bottom .link{float:right;width:220px;height:29px;}\n' +
                                    '.bloc_interstitiel_cnt {width:994px; text-align:center}';

                            return css;

                          },
                          write:function(obj) {
                              //$('html').addClass('html_interst');
                              //$('#container').addClass('interst_hide');
                              $('body').append($.la.promo.interstitiel.getHtml(obj));
                              $.la.promo.interstitiel.visible = true;
                              window.setTimeout('$.la.promo.interstitiel.remove();', obj.time * 1000);
                          },
                          getHtml:function(obj){
                              html =  '<div id="la-promo-interstitiel-div" class="bloc_interstitiel">\n';
                              if (obj.iframe) {
                                html +=  '<iframe src="' + obj.iframe + '" width="100%" height="1000px"></iframe>';

                              } else {
                                target='';
                                if(obj.newwindow){
                                    target = ' target="_blank"';
                                  }

                                html += '<div id="la-promo-interstitiel-div-container">\n' +
                                        '   <div class="bloc_interstitiel_top"><a href="javascript:void(0);" class="logo"></a><a href="javascript:void(0);" class="link"></a></div>\n' +
                                        '   <div class="bloc_interstitiel_cnt">\n';
                                if (obj.mediaType == 'swf') {
                                   html += '       <object width="' + obj.mediaWidth + '" height="' + obj.mediaHeight + '" type="application/x-shockwave-flash" data="' + obj.mediaUrl + '" id="inter_flash" style="visibility: visible;">\n' +
                                        '           <param name="movie" value="' + obj.mediaUrl + '">\n' +
                                        '           <param name="allowScriptAccess" value="always">\n' +
                                        '	        <param name="quality" value="high">\n' +
                                        '	        <param name="wmode" value="transparent">\n' +
                                        '	        <param name="flashvars" value="clickTag=' + obj.url + '">\n' +
                                        '       </object>\n' ;
                                } else if(obj.mediaType == 'img') {
                                        html += ' <a href="' + obj.url + '"' + target + '><img src="' + obj.mediaUrl + '" width="' + obj.mediaWidth + '" height="' + obj.mediaHeight + '" /></a>\n';
                                  }
                                    html +=     '   </div>\n' +
                                        '   <div class="bloc_interstitiel_bottom" id="bloc_seance">';
                                   if (obj.seanceUrl) {
                                  html += '<a href="' + obj.seanceUrl+ '" class="link" id="findSeance"';
                                    if (obj.newwindowseance == 1) {
                                        html += ' target=_blank';
                                    }
                                    html += '></a>';
                                   }
                                    html += '</div>\n' +
                                        '</div>\n';
                              }

                               html += '</div>\n';

                             return html;
                            },
                            remove:function() {
                                 if ($.la.promo.interstitiel.visible == true) {
                                    if ($('#la-promo-showskin-a').length > 0) {
                                        $('#la-promo-showskin-a').show();
                                    }
                                    $('#la-promo-interstitiel-div').remove();
                                    $('la-promo-interstitiel-style').remove();
                                    $('body').css('overflow', 'visible');
                                   // $('.interst_hide').removeClass('interst_hide');
                                   // $('html').removeClass('html_interst');
                                    $.la.promo.interstitiel.visible = false;
                                    $.la.promo.interstitiel.interstitielLoaded = false;
                                }
                            }
                    },
            
            skinLoaded:false,
            skinData:null,
            container:'#container',
            containerBody:'body',
            aMethod:'prepend',

            localCss:function(obj){
                return '';
            },
            localCssAfter:function(obj){
                return '';
            },
            setASkinStyle:function(obj){
            	var height_css=$(document).height();
            	if (obj.height_sup)
            		height_css+=obj.height_sup;            		
            	var css = 'a#la-promo-showskin-a{z-index:1;position:absolute;top:0;left:0;width:100%;height:'+height_css+'px;}';
                css += 'body{height:'+height_css+'px;}';
                $('head').append('<style class="la-promo-showskin-style" type="text/css">' + css + '</style>');
            },

            	setSkinBodyStyle:function(obj){
				var bgattach="center";
				if(obj.bgfixed){
				    bgattach="fixed";
				}

                var sBodyStyle = '\nbody{background:' + obj.bodybgcolor + ' url(' + obj.bodybgimage + ') '+bgattach+' top no-repeat !important;}\n'
                                    + $.la.promo.containerBody +'{\n'
                                    + '  position:relative !important;\n\
                                        z-index:1 !important;\n\
                                    }\n\
                                    ' + $.la.promo.container + '{\n';

                if (!(obj.swf && obj.swfWidth && obj.swfHeight)) {
                     strPx = '';
                    if (   obj.top.indexOf('px') == -1) {
                        strPx = 'px';
                    }
                    sBodyStyle +=   'top:' + obj.top + strPx +' !important;';
                }
                sBodyStyle +=  ' position:relative;\n\
                                        z-index:1;\n\
                                    }\n';
                return sBodyStyle;
            },
            setSwfStyle:function(obj) {

                return '#la-promo-showskin-divswf { width:994px; height:' +  obj.swfHeight + 'px; margin:0px auto 0px; position:relative;}\n'
                        + '#la-promo-showskin-swf { position:absolute; top:0; right:0; z-index:1}';
            },
            appendSkinA:function(obj){

                 if (obj.url){
                     var o = obj;
                     $(document).ready( function(){

                         $($.la.promo.container).css({
                             position:'relative'
                         });
                         var target = '';
                         if(o.newwindow){
                            target = ' target="_blank"';
                         }

                         var a = '<a id="la-promo-showskin-a" href="' + o.url + '"' + target ;
                         if ($('#la-promo-interstitiel-div').length > 0) {
                            a += ' style="display:none"';
                         }
                         a += '>';
                         a += '</a>';

                         if (obj.swf && obj.swfWidth && obj.swfHeight) {
                            var swfDiv = '<div id="la-promo-showskin-divswf">'
                                +'   <object id="la-promo-showskin-swf" class="vjs-flash-fallback" width="' + o.swfWidth + '" height="' + o.swfHeight + '" type="application/x-shockwave-flash" data="' + o.swf + '">\n'
                                +'      <param name="movie" value="' + o.swf + '" />\n'
                                +'      <param name="wmode" value="transparent" />\n'
                                +'      <param name="allowfullscreen" value="true" />\n'
                                +'      <param name="allowscriptaccess" value="always" />\n'
                                +'      <param name="flashvars" value="clickTag=' + o.url +'" />\n'
                                +'      </object>\n'
                                +'</div>\n';
                            $($.la.promo.container).before(swfDiv);
                         }

                         if($.la.promo.aMethod == 'prepend'){
                             $($.la.promo.containerBody ).prepend(a);
                         }
                         else{
                             $($.la.promo.containerBody ).append(a);
                         }
                         $.la.promo.setASkinStyle(obj);
                     });

                 }
            },

            showSkin:function(obj){
                /*
				 * PARAMS obj.bodybgcolor obj.bodybgimage obj.top obj.url
				 * obj.newwindow obj.gabarit obj.bgfixed
				 * 
				 * Function régie : 
				 * 		jQuery.la.promo.showSkin({bodybgcolor:'#123456',bodybgimage:'http://video.premiere.fr/regiepub/habillages/bgd_habillage_mdc_cosmo_250k_v2.jpg',top:'143px',url:'http://www.google.com',newwindow:true})
				 * test navigateur :
				 * 		javascript:jQuery.la.promo.showSkin({bodybgcolor:'#123456',bodybgimage:'http://video.premiere.fr/regiepub/habillages/bgd_habillage_mdc_cosmo_250k_v2.jpg',top:'143px',url:'http://www.google.com',newwindow:true})
				 * 
				 */
                this.skinLoaded=true; // $.la.promo.skinLoaded
                this.skinData=obj;
                var container = obj.container;
                if(typeof container == 'undefined'){
                    container = $.la.promo.container;
                }
                $.la.promo.container = container;
                var containerBody = obj.containerBody;
                if(typeof containerBody == 'undefined'){
                    containerBody = $.la.promo.containerBody;
                }
                $.la.promo.containerBody = containerBody;

                var css = '';
                // avant
                css += this.localCss(obj);
                //
                css += this.setSkinBodyStyle(obj);

                 if (obj.swf) {
                    css += this.setSwfStyle(obj);
                 }
                //
                css += this.localCssAfter(obj);
                $('head').append('<style class="la-promo-showskin-style" type="text/css">' + css + '</style>');
                this.appendSkinA(obj);
            },

            removeSkin:function() {
                $('.la-promo-showskin-style').remove();
                $('#la-promo-showskin-a').remove();
                $.la.promo.skinLoaded = false;
                this.skinData=null;
            },

            wreportRefresh: function(){
                if(wreport_ok==1){
                    var w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
                    w_counter.add_content(WRP_CONTENT);
                    w_counter.count();
                }
            },

            bannerRefresh: function(uri,gestionHauteur){
                if(typeof gestionHauteur == 'undefined'){
                    gestionHauteur = 'gestionHauteur';
                }
                if($('#'+gestionHauteur).length  > 0){
                    $('#'+gestionHauteur).html('<iframe scrolling="no" frameborder="0" width="728" height="90"  border="0" marginheight="0" marginwidth="0" noresize="true" vspace="0" framespacing="0"  src="' + $.la.sHost + '/ajaxext/pub?publicite=banniere&uri='+uri+'"></iframe>');
                }
            },

            flashAnimate: function( prop, speed, easing, callback ) {
                var optall = jQuery.speed(speed, easing, callback);

                return this[ optall.queue === false ? "each" : "queue" ](function(){

                    var opt = jQuery.extend({}, optall), p,
                    hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
                    self = this;

                    for ( p in prop ) {
                        if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
                            return opt.complete.call(this);

                        if ( ( p == "height" || p == "width" ) && this.style ) {
                            // Store display property
                            opt.display = jQuery.css(this, "display");

                            // Make sure that nothing sneaks out
                            opt.overflow = this.style.overflow;
                        }
                    }

                    /*
					 * if ( opt.overflow != null ) this.style.overflow =
					 * "hidden";
					 */

                    opt.curAnim = jQuery.extend({}, prop);

                    jQuery.each( prop, function(name, val){
                        var e = new jQuery.fx( self, opt, name );

                        if ( /toggle|show|hide/.test(val) )
                            e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
                        else {
                            var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
                            start = e.cur(true) || 0;

                            if ( parts ) {
                                var end = parseFloat(parts[2]),
                                unit = parts[3] || "px";

                                // We need to compute starting value
                                if ( unit != "px" ) {
                                    self.style[ name ] = (end || 1) + unit;
                                    start = ((end || 1) / e.cur(true)) * start;
                                    self.style[ name ] = start + unit;
                                }

                                // If a +=/-= token was provided, we're doing a
                                // relative animation
                                if ( parts[1] )
                                    end = ((parts[1] == "-=" ? -1 : 1) * end) + start;

                                e.custom( start, end, unit );
                            } else
                                e.custom( start, val, "" );
                        }
                    });

                    // For JS strict compliance
                    return true;
                });
            },

            adRefresh: function(index, callback){
            	if( typeof $.la.promo._settingsList != 'undefined' && typeof $.la.promo._settingsList[index] != 'undefined' )
            	{
            		iframeStr = '<iframe style="border:0;" src="/extension/lajavascript/design/standard/lib/pub.html?id='+$.la.promo._settingsList[index].id+'&r='+Math.floor(Math.random()*100000)+'&cb='+callback+'"></iframe>';
            		$('#'+$.la.promo._settingsList[index].elt).html(iframeStr);
            	}
            	
            },
            
            // Ads
            a2dToRegister:{},
            a2dUrlSup:'',

            _adList:[],
            _settingsList:[],
            _adListForConsole:[],
            _a2dRandom:Math.random(),

            // * à surcharger dans son siteacces si besoin*/
            _adDefaultDefer:false,
            _adDefaultZoneDefer:{},
            _adDefaultForceDefer:null,
            _adDefaultForceZoneDefer:{},

            _adHost:'http://fr.a2dfp.net',
            _testA2d:{},


            // obsolete remplacé par adSetZone
            prependRegister:function(placement,id,defer){
                if(id != ''){
                    $.la.promo.a2dToRegister[placement]={
                        id:id,
                        defer:defer
                    };
                }
            },

            adSetZone:function(placement,id){
                if(id != ''){
                    $.la.promo.a2dToRegister[placement]={
                        id:id
                    };
                }
            },

            adLoad:function(index){
                if(typeof $.la.promo._adList[index] != 'undefined'){
                    $.la.promo._adWrite($.la.promo._adList[index].id);
                }
            },

            adsProcess:function() {

                for(var i = 0; i< $.la.promo._adList.length;i++){
                    if(typeof $.la.promo._adList[i] != 'undefined'){
                        if($.la.promo._adList[i].defer == 'ready'){
                            var index = i;
                            $.la.promo._deferProcess(index);

                        }else{
                            $('#'+$.la.promo._adList[i].elt)._adProcess(i);
                        }
                    }
                }
            },

            testA2d:function(idCampaign){
                var url = document.location.href.replace('&testA2d=' + idCampaign,'');
                url = url.replace('\?testA2d=' + idCampaign,'\?');
                url = url.replace('?testA2d=' + idCampaign,'?');

                if(document.location.href.indexOf('?') != -1){
                    document.location.href = url + '&testA2d=' + idCampaign;
                }
                else{
                    document.location.href = url + '?testA2d=' + idCampaign;
                }
            },

            removeTestA2d:function(idCampaign){
                document.location.href = document.location.href.replace(document.location.search,'');
            },

            _adRegister:function(id, defer){

                /**
				 * settings : defer : 'fasle' ou '' : chargement immédiat;
				 * 'bottom' : en bas de page (default) 'ready' : on document
				 * ready
				 */

                // compatibilité version précédente
                if(typeof id != 'object'){
                    settings = {};
                    settings.id = id;
                    settings.defer = defer;
                    settings.zone = null;
                }
                // new implementation
                else if(typeof id == 'object'){
                    settings = id; // first param
                }


                // on récupère les infos dans l'objet stocké dans
                // a2dToRegister de la zone
                if(typeof settings.zone != 'undefined' && typeof $.la.promo.a2dToRegister[settings.zone] == 'object' ){
                    settings.id = $.la.promo.a2dToRegister[settings.zone].id;
                    settings.defer = $.la.promo.a2dToRegister[settings.zone].defer;
                }

                if(typeof settings.defer == 'undefined' || (settings.defer == '' && settings.defer !== false) || settings.defer == '{defer}'){
                    // le defer n'est pas pr?cis? dans l'appel de la
                    // fonction
                    if(typeof $.la.promo._adDefaultZoneDefer[settings.zone] != 'undefined'){
                        settings.defer = $.la.promo._adDefaultZoneDefer[settings.zone];
                    }
                    else  if($.la.promo._adDefaultDefer != null){
                        settings.defer = $.la.promo._adDefaultDefer;
                    }
                    // Rien n'est d?fini : on passe tout ? false'
                    else{
                        settings.defer = false;
                    }

                }



                // valeurs par d?faut si non d?fini
                if(typeof settings.defer == 'undefined' || settings.defer == '' || settings.defer == '{defer}'){
                    // on a d?fini un defer par d?faut pour une zone
                    if(typeof $.la.promo._adDefaultZoneDefer[settings.zone] != 'undefined'){
                        settings.defer = $.la.promo._adDefaultZoneDefer[settings.zone];
                    }
                    // on a d?fini un defer par d?faut pour toutes les zones
                    else if(typeof $.la.promo._adDefaultDefer != 'undefined'){
                        settings.defer = $.la.promo._adDefaultDefer;
                    }
                    // on a rien d?fini
                    else{
                        settings.defer = $.la.promo._adDefaultDefer;
                    }
                }
                // Urgence : on force la valeur sur une zone
                if(settings.zone != null && $.la.promo._adDefaultForceZoneDefer != null && typeof $.la.promo._adDefaultForceZoneDefer[settings.zone] != 'undefined'){
                    settings.defer = $.la.promo._adDefaultForceZoneDefer[settings.zone];
                }
                // Mega urgence : on force la valeur partout !
                else if($.la.promo._adDefaultForceDefer != null){
                    settings.defer = $.la.promo._adDefaultForceDefer;
                }

                // on nettoye un peu
                // 'false' => false
                if(settings.defer == 'false'){
                    settings.defer = false;
                }

                settings.elt = $(this).attr('id');

                // un test a2d ?
                if($.la.utils.httpGet('testA2d') && typeof $.la.promo._testA2d[$.la.utils.httpGet('testA2d')] != 'undefined'){
                    if($.la.promo._testA2d[$.la.utils.httpGet('testA2d')][settings.zone] != ''){
                        settings.id = $.la.promo._testA2d[$.la.utils.httpGet('testA2d')][settings.zone];
                    }
                }

                if(settings.defer == false){
                    $.la.promo._adWrite(settings.id);
                    $.la.promo._adListForConsole[$.la.promo._adListForConsole.length] = settings;
                }
                else{
                    $.la.promo._adList[$.la.promo._adList.length] = settings;
                    $.la.promo._adListForConsole[$.la.promo._adListForConsole.length] = settings;
                }
                $.la.promo._settingsList[$.la.promo._settingsList.length] = settings;


            },

            _adProcess:function(id){
                var prefix = 'preload_ad_';
                try{
                    var me = $(this)[0];
                    me.appendChild($('div[id="'+prefix+id+'"]')[0]);
                }
                catch(e){
                    return;
                }
            },

            _adWrite:function(id){
                try{
                    if($.la.promo.a2dUrlSup!='')
                        document.write('<scr' + 'ipt type="text\/javascript" src="' + $.la.promo._adHost + '\/ad?s=' + id + '&m=js&ncb=' + $.la.promo._a2dRandom + '&kw='+ $.la.promo.a2dUrlSup + '"><\/scr'+'ipt>');
                    else
                        document.write('<scr' + 'ipt type="text\/javascript" src="' + $.la.promo._adHost + '\/ad?s=' + id + '&m=js&ncb=' + $.la.promo._a2dRandom + '"><\/scr'+'ipt>');
                }
                catch(e){

                }
            },

            _deferProcess:function(index){
                var i = index;
                $(function(){
                    $('#'+$.la.promo._adList[i].elt)._adProcess(i);
                });
            },

            /* GOOGLE */
            google: {
                adsense: {
                    _scriptUrl: 'http://pagead2.googlesyndication.com/pagead/show_ads.js',

                    _params: {
                        google_ad_client: null,
                        google_ad_channel: null,
                        google_ad_output: "js",
                        google_max_num_ads: null,
                        google_ad_type: "text",
                        google_language: null,
                        google_encoding: "utf8",
                        google_feedback: "on",
                        google_adtest: "off",
                        google_analytics_domain_name: null
                    },

                    _createHtml: {
                        container: function (sId) {
                            return '<div id="' + sId + '"></div>';
                        },
                        title: null,
                        flash: null,
                        image: null,
                        html: null,
                        text: null
                    },

                    _sContainerId: 'googleAdsense',

                    _ads: null,
                    _info: null,

                    _iDisplayNumber: 0,
                    _iBlocNumber: 0,

                    execute: function(aParams) {
                        $.extend(true, this._params, aParams);
                        if (this._iBlocNumber == 0) {
                            document.write('<script type="text/javascript">var google_adnum = 0;</script>');
                            document.write('<script type="text/javascript">//<![CDATA[\n'
                                + 'function google_ad_request_done(google_ads) {\n'
                                + '  jQuery(document).ready(function() { $.la.promo.google.adsense.display(google_ads, google_info); });\n'
                                + '}\n'
                                + '//]]></script>');
                        }
                        document.write('<script type="text/javascript">\n'
                            + 'google_ad_output = "' + this._params.google_ad_output + '";\n'
                            + 'google_ad_type = "' + this._params.google_ad_type + '";\n'
                            + 'google_encoding = "' + this._params.google_encoding + '";\n'
                            + 'google_feedback = "' + this._params.google_feedback + '";\n'
                            + 'google_language = "' + this._params.google_language + '";\n'
                            + 'google_skip = ' + ( this._iBlocNumber * this._params.google_max_num_ads ) + ';\n'
                            + '\n'
                            + 'google_ad_client = "' + this._params.google_ad_client + '";\n'
                            + 'google_ad_channel = "' + this._params.google_ad_channel + '";\n'
                            + 'google_max_num_ads = "' + this._params.google_max_num_ads + '";\n'
                            + 'google_adtest = "' + this._params.google_adtest + '";\n'
                            + (this._params.google_analytics_domain_name != null ? 'google_analytics_domain_name = "' + this._params.google_analytics_domain_name + '";\n' : '')
                            + '</script>');
                        document.write('<script type="text/javascript" src="' + this._scriptUrl + '?iNumber=' + this._iBlocNumber + '"></script>');

                        document.write( this._createHtml.container( this._sContainerId + this._iBlocNumber ) );

                        this._iBlocNumber++;
                    },

                    display: function(google_ads, google_info) {
                        this._ads = google_ads;
                        this._info = google_info;

                        if (this._ads.length == 0) {
                            return ;
                        }

                        var s = '';

                        if (this._createHtml.title != null) s += this._createHtml.title( this );

                        switch (this._ads[0].type) {
                            case 'flash':
                                if (this._createHtml.flash != null) s += this._createHtml.flash( this );
                                break;
                            case 'image':
                                if (this._createHtml.image != null) s += this._createHtml.image( this );
                                break;
                            case 'html':
                                if (this._createHtml.html != null) s += this._createHtml.html( this );
                                break;
                            case 'text':
                                if (this._createHtml.text != null) s += this._createHtml.text( this );
                                break;
                        }
                        if (this._ads[0].bidtype == "CPC") {
                            google_adnum = google_adnum + this._ads.length;
                        }
                        $( '#' + this._sContainerId + this._iDisplayNumber ).html(s);
                        this._iDisplayNumber++;
                    },

                    nbGoogleAds: function(){
                        var nbGoogleAds = 0;
                        var aGoogleAdsUrl = ['http://googleads.g.doubleclick.net/aclk'];
                        try{
                            for(var i=0; i< aGoogleAdsUrl.length; i++){
                                nbGoogleAds += ($('a[href^="'+aGoogleAdsUrl[i]+'"]').length)/2;
                            }
                        }
                        catch(e){
                            // erreur de parsing
                            nbGoogleAds = -1;
                        }
                        return nbGoogleAds;

                    }
                }
            },

            /* PUB IFRAME */
            pub_iframe: {
                initialWidth: 0,
                initialHeight: 0,
                refresh: 42,
                iFrameSelector: '#iframe_pub_droite',
                iFrameContainerSelector : '#pub_a2d_pave',
                eltSupSelectors : new Array('#pmExpandContainer','#pmExpandContainer6178_1'),
                sPosition:'absolute',
                sTop : '0',
                sRight : '0',

                /*
				 * on cherche à savoir si un element de type "object" est
				 * visible
				 */
                isVisible: function (elt){
                    if(elt.css('display') == 'none'){
                        return false;
                    }
                    else if(elt.css('visibility') == 'hidden'){
                        return false;
                    }
                    else if(elt.css('visibility') == 'visible'){
                        return true;
                    }
                    else{
                        var parent = elt.parent();
                        if(typeof parent == 'object' && parent.get(0).nodeName.toLowerCase() != 'body'){
                            return top.jQuery.la.promo.pub_iframe.isVisible(parent);
                        }
                    }
                    return true;
                },

                /*
				 * on change la taille de l'iframe selon la taille d'un element
				 * a l'interieur la fonction doit être appelée de l'iframe
				 */
                calcIframeSize: function (){
                    var width = 0;
                    var height = 0;
                    var changed = false;

                    if(top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).length>0 && top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument.body!=null){
                        // on cherche des elements particuliers
                    	for(var i=0;i<top.jQuery.la.promo.pub_iframe.eltSupSelectors.length;i++){
	                        if(!changed){
	                        	top.jQuery(top.jQuery.la.promo.pub_iframe.eltSupSelectors[i],top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
	                                width = Math.max(width,parseInt(top.jQuery(this).css('width')));
	                                height = Math.max(height,parseInt(top.jQuery(this).css('height')));
	                                changed = true;
	                            });
	                        }
	                    }

	                    // sinon, on cherche un element de type "object"
	                    if(!changed){
	                        top.jQuery('object',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
	                            if(top.jQuery.la.promo.pub_iframe.isVisible(top.jQuery(this))){
	                                width = Math.max(width,parseInt(top.jQuery(this).css('width')));
	                                height = Math.max(height,parseInt(top.jQuery(this).css('height')));
	                                changed = true;
	                            }
	                        });
	                    }
	                    // sinon, on cherche un element de type "embed"
	                    if(!changed){
	                        top.jQuery('embed',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
	                            if(top.jQuery.la.promo.pub_iframe.isVisible(top.jQuery(this))){
	                                width = Math.max(width,parseInt(top.jQuery(this).css('width')));
	                                height = Math.max(height,parseInt(top.jQuery(this).css('height')));
	                                changed = true;
	                            }
	                        });
	                    }
	                    // sinon, on cherche un element de type "img"
	                    if(!changed){
	                        top.jQuery('img',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
	                            var w = this.width;
	                            var h = this.height;
	                            width = Math.max(width,w);
	                            height = Math.max(height,h);
	                            changed = true;
	                        });
	                    }
	                    // sinon, on cherche un element de type "iframe"
	                    if(!changed){
	                        top.jQuery('iframe',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
	                            var w = this.width;
	                            var h = this.height;
	                            width = Math.max(width,w);
	                            height = Math.max(height,h);
	                            changed = true;
	                        });
	                    }
	                    // et on change la taille de l'iframe
	                    if(width != top.jQuery.la.promo.pub_iframe.initialWidth || height != top.jQuery.la.promo.pub_iframe.initialHeight){
	                    	top.jQuery.la.promo.pub_iframe.initialWidth = width;
	                        top.jQuery.la.promo.pub_iframe.initialHeight = height;
	                        top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).attr('width',width);
	                        top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).attr('height',height);
	                        top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).attr('allowtransparency','true');
	                        if (top.jQuery.la.promo.pub_iframe.sPosition != '')
	                            top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).css('position',top.jQuery.la.promo.pub_iframe.sPosition);
	                        if (top.jQuery.la.promo.pub_iframe.sTop != '')
	                            top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).css('top',top.jQuery.la.promo.pub_iframe.sTop);
	                        if (top.jQuery.la.promo.pub_iframe.sRight != '')
	                            top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).css('right',top.jQuery.la.promo.pub_iframe.sRight);
                        }
                        top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameContainerSelector).css('position','relative');
                        top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameContainerSelector).css('height',height + 'px');
                    }
                    // et on relance le script
                    window.setTimeout(top.jQuery.la.promo.pub_iframe.calcIframeSize, top.jQuery.la.promo.pub_iframe.refresh);
                }
            }

        }
    });
})(jQuery);

// plugins
jQuery.fn.adRegister = jQuery.la.promo._adRegister;
jQuery.fn._adProcess = jQuery.la.promo._adProcess;
jQuery.fn.flashAnimate = jQuery.la.promo.flashAnimate;
