/*
*   Dans ce JS (pour page détail): 
* criteo_ld3.js

* detail.js
*/
/*---------------------------------------------------------criteo_ld3.js-------------------------------------------------------*/
/* CRITEO Widgets Loader Version 1.1e */
var CRITEO=function(){var G={I:[],M:function(){if(arguments.callee.bo){return;}arguments.callee.bo=true;for(var i=0;i<G.I.length;i++){G.I[i]();}},N:function(aR){this.I[this.I.length]=aR;if(document.addEventListener){document.addEventListener("DOMContentLoaded",G.M,null);}if(/KHTML|WebKit/i.test(navigator.userAgent)){var bi=setInterval(function(){if(/loaded|complete/.test(document.readyState)){clearInterval(bi);delete bi;G.M();}},10);}/*@cc_on@if(@_win32||@bz)var bV="src='javascript:void(0)'";if(location.protocol=="https:")bV="src=//:";document.write("<scr"+"ipt id=__cto_ie_onload defer "+bV+"><\/scr"+"ipt>");var s=document.getElementById("__cto_ie_onload");s.onreadystatechange=function(){if(this.readyState=="complete"){G.M();}};@end@*/;if(typeof window.onload!='function'){window.onload=G.M;}else{var aI=window.onload;window.onload=function(){G.M();if(aI){aI();}};}}};function ab(s){if(document.getElementsByTagName){var F=document.getElementsByTagName('head')[0];if(!F){F=document.createElement('HEAD');document.documentElement.appendChild(F);}if(F&&F.appendChild){F.appendChild(s);}}};function aj(){if(typeof(window.encodeURIComponent)==='undefined'){var R={bk:function(K){K=""+K;var c,s,C="",i=0;while(i<K.length){c=K.charCodeAt(i++);if(c>=0xDC00&&c<0xE000){continue;}if(c>=0xD800&&c<0xDC00){if(i>=K.length){continue;}s=K.charCodeAt(i++);if(s<0xDC00||c>=0xDE00){continue;}c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;}if(c<0x80){C+=String.fromCharCode(c);}else if(c<0x800){C+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));}else if(c<0x10000){C+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));}else{C+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));}}return C;},aU:"0123456789ABCDEF",ak:function(n){return R.aU.charAt(n>>4)+R.aU.charAt(n&0xF);},aV:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"};window.encodeURIComponent=function(s){s=R.bk(s);var C="";for(var i=0;i<s.length;i++){if(R.aV.indexOf(s.charAt(i))== -1){C+="%"+R.ak(s.charCodeAt(i));}else{C+=s.charAt(i);}}return C;};}};function bD(){if(document.getElementsByTagName){var n=1;var t=[];var l=[];var V,L,T,bp,aQ,as,J;var a=document.getElementsByTagName('div');var an=false;for(var i=0;i<a.length;i++){if(a[i].id&&a[i].id.substring(0,3).toLowerCase()=="cto"&&a[i].childNodes){V=L=T=bp=as=J=null;aQ=2;for(var j=0;j<a[i].childNodes.length;j++){var c=a[i].childNodes[j];if(c&&c.tagName&&c.tagName.toLowerCase()=="div"&&c.className&&c.className.substring(0,3).toLowerCase()=="cto"){var O=(c.textContent?c.textContent:(c.innerText?c.innerText:null));switch(c.className.toLowerCase()){case 'ctowidgetserver':V=O;break;case 'ctodatatype':L=O;break;case 'ctowidgettype':T=O;break;case 'ctoparams':bp=O;break;case 'ctoversion':aQ=O;break;case 'ctodata':as=c.innerHTML;break;case 'ctokeyword':J=O;break;}}}if(V&&((!L&&T)||(L&& !T))){var u="v="+aQ;if(bp){u+="&"+bp;}u="p"+n+"="+encodeURIComponent(u);if(as){u+="&d"+n+"="+encodeURIComponent(as);}if(T){u+="&w"+n+"="+T;}else{u+="&t"+n+"="+L;}if(J){u+="&kw="+encodeURIComponent(J);}if(an==false){try{u+='&ref='+encodeURIComponent(document.referrer);}catch(e){}try{u+='&sc_r='+encodeURIComponent(screen.width+'x'+screen.height);}catch(e){}try{u+='&sc_d='+encodeURIComponent(screen.colorDepth);}catch(e){}an=true;}var s;for(s=0;s<t.length;s++){if(t[s]==V){break;}}if(s!=t.length&&l[s]&&(l[s].length+u.length)>2000){CRITEO.au(l[s]);l[s]=null;}if(s==t.length|| !l[s]){t[s]=V;l[s]=V+"display.js?";}else{l[s]+="&";}l[s]+=u;n++;}}}for(var H=0;H<l.length;H++){if(l[H]){CRITEO.au(l[H]);}}}};function ad(){aj();bD();};return{N:function(){if(typeof(CRITEO_Loaded)!="undefined"){return;}CRITEO_Loaded=1;G.N(function(){ad();});},bG:function(def){if(document.createElement){var s=document.createElement('style');if(s){s.setAttribute('type','text/css');ab(s);if(s.styleSheet){try{s.styleSheet.cssText=def;}catch(e){}}else{var c=document.createTextNode(def);s.appendChild(c);}}}},au:function(u){if(document.createElement){var s=document.createElement('script');if(s){s.type='text/javascript';s.src=u.substring(0,2000);ab(s);}}},aG:function(a,u){if(document.createElement){var bj=document.createElement('IMG');if(bj){if(a){var d=document.getElementById(a);if(d===null){d=document.createElement('DIV');d.id=a;d.style.display="none";document.body.appendChild(d);}if(d!==null&&d.appendChild){d.appendChild(bj);}}bj.src=u;}}},ac:function(m){var g="";for(var i=0;i<m;i++){g+=Math.floor(Math.random()*0xF).toString(0xF);}return g+"";}};}();var CRITEO_Loaded;CRITEO.N();

/*
**************************************************************
function: for POI
returns: Object POI
created by: Anne-Laure HOAREAU
**************************************************************
*/
var c_det = {}; //for POI
c_det.initPOI2 = function(){

    var c_det = this,
        test_omniture = true;
    $j('#det_box_situation a').not('#partenariat_qype a').click(function () {

        var rel = $j(this).attr('rel').split('_');
        Map.SetIcon({
            url : 'http://static.poliris.com/z/portail/svx/portals/sv6_annonces/images/picto_prox.png',
            height: 36,
            width: 29
        });
        Map.SetMarker({
            latitude: rel[1],
            longitude: rel[2]
        });
        return false;
    });
    /* Pass the map object to the POI object */
    if (c_det.POI !== undefined) {
        c_det.POI.setMap(Map);
        
        $j('#POI input:checkbox,#POI_light input:checkbox').change(function () {
            if(test_omniture){ // track omniture
                current_omniture.omnitureLead("L023","event9");
            }
        
            // differentiate between master poi and regular pois
            if ($j(this).attr('name') == 'poi_type') {
                c_det.POI.getPOI($j(this).val(), $j(this).is(':checked'), $j(this).parent('li').text(), true);
                // uncheck the master category attached if there's one
                if ((! $j(this).is(':checked')) && $j(this).parent('li').parent('ul').attr('class') == "poi_sub_list") {
                    $j(this).parent('li').parent('ul').parent('li').children('input:checkbox').attr('checked', '');
                }
            } else {
                c_det.POI.getPOIFromMaster($j(this));
            }
            test_omniture = false;
        });
    }
}
/*
**************************************************************
function: Set the loader up
returns: void
parameters:
status: { type: string | defaults: empty string | function: the statuts ("on" and "off") of the loader, to check if it's visible or not }
created by: Anne-Laure HOAREAU
**************************************************************
*/
POILocator.prototype.setLoader = function(status) {
    if (status) {
        if (this.loader_status != 'on') {
            this.loader_status = 'on';
            $j('#layer_over,#refiner_loading').show();
        }
    } else {
        this.loader_status = 'off';
        $j('#layer_over,#refiner_loading').hide();
    }
}
/*------------------------------------------------------ detail ---------------------------------------------------------*/
var detail = (function(){

    /*initialisation de la map*/
     /*
     var map9 = new carto();
     map9.initMap($$PROGDETAIL:LATITUDE replace , .$$, $$PROGDETAIL:LONGITUDE replace , .$$);
     */
     var lat = document.getElementById("latitudeDetail").value;
     var longitude = document.getElementById("longitudeDetail").value; 
     Map.default_box_options = {
        title: "",
        description: "",
        showPointer: true,
        showCloseButton: true,
        zIndex: 100,
        offset: new Microsoft.Maps.Point(0, 0),
        visible: false
    }
    
    Map.Init({
        container_id: 'programme_carte',
        marker_ok: true,
        latitude: lat,
        longitude: longitude,
        //zoom: 15,
        marker: {
            latitude: lat,
            longitude: longitude
        },
        icon :{
            url:"http://static.poliris.com/z/portail/svx/portals/sv6_annonces/images/picto_prox.png"
        }
    });
}) ();

function initDetail() {
    launchGallery(imageArray);
    // Set up radio clicks
    /*
    $j('.radio_typebien').click(function () {
        update_fields($j(this));
    });
    */

    /* creation of a vertical carousel*/
    if(imageArray.length > 0){
        $j(".vertical .jCarouselLite").jCarouselLite({
            btnNext: ".vertical #next",
            btnPrev: ".vertical #prev",
            vertical: true,
            circular:false
        });
    }
    update_form();
    
    // si Newsletter coché > on coche optIn   
    $j("#news").change(function(){
        $j(this).is(':checked') ? $j('#optIn').attr('value',1) : $j('#optIn').attr('value','');
    });

    /*
    $j("form.form_demdoc").submit(function () {
        if ($j('#bTerrain, #bAppt, #bMais').val() == "") {
            $j(".radio_typebien").each(function () {
                if ($j(this).is(':checked')) {
                    update_fields($j(this));
                }
            });
        }
        return true;
    });
    */

    // Retour aux résultats de recherche après un envoi de demande de doc si query dispo en cookie
    /*
    if (url_referer == "" || url_referer === undefined) {
        url_referer = getCookie("recherche_referer");
    } else {
        setCookie("recherche_referer", url_referer);
    }
    $j('#lien_retour_resultats_dem_doc, .detail_nav_middle').click(function(){
        if (url_referer != "" && url_referer !== undefined) {
            $j(this).attr('href', url_referer);
        } else {
            return false;
        }
    });
    */
    // Afficher les coordonnées promoteur
    var idannonce = $j("#idannonceprogramme").val();
    var typeTransaction = $j("#typetransaction").val();
  
    if( typeTransaction != 9){
        // test du domaine, la variable domaine_criteo est définie dans l'incl_haut_def_rep.htm
        if (domaine_criteo == 1){
          var coord_domaine = "http://immo.selogerneuf.com/";
        }else{
          var coord_domaine = "http://www.selogerneuf.com/";
        };
        $j.ajax({
            
                url: coord_domaine + idannonce + '/' + "detail,incl_coord_annonceur.htm",
                success: function(data) {
                    $j("#coordonnees_annonceur").html(data);
                },
                error: function () {
                    $j("#coordonnees_annonceur").html('<p>Impossible d\'afficher les coordonnées demandées.</p>');
                }
        });
    }
}/* fin initDetail */
/*
function update_fields(radioObject) {
    var nb_pieces = radioObject.attr('title');
    var type_bien = radioObject.val();
    if (type_bien.match('Terrain')) {
        $j('#bTerrain').attr('value', '1');
    } else {
        $j('#Pieces').attr('value', nb_pieces);
        // fill out hidden fields
        if (type_bien.match('Appartement') || type_bien.match('Studio') || type_bien.match('Duplex')) {
            $j('#bAppt').attr('value', '1');
            $j('#bMais').attr('value', '0');
        }
        if (type_bien.match('Maison') || type_bien.match('Mas')) {
            $j('#bAppt').attr('value', '0');
            $j('#bMais').attr('value', '1');
        }
    }
}
*/

function launchGallery(photos) {
    afficheBorder(0); // display a border on the first img (default)
    // this code cache the arrows of a vertical carousel if a number of img > 3   
    if (photos.length <= 3) {
        $j('#next, #prev').hide();
        $j('.picto_visuels').css({margin:"0 0 10px 5px"});
    } 
    /* only if more than one photo */
    if (photos.length > 1) {
        /* set up the navigation arrows */
        $j('#arrow_left').click(function () {
            var indice = parseInt($j('#visuel_big_programme img').attr('rel').substring(9));
            var prev_indice = --indice;
            lienCarou(indice, photos.length);
            $j('#next').removeClass('inactif');
            if (photos[prev_indice]) {
                updateImage(photos[prev_indice][1], 'big_photo' + prev_indice);
            }
            if (prev_indice == 0) {
                $j('#arrow_left').hide();
                $j('#prev').addClass('inactif');
            }
            if (prev_indice < photos.length) {
                $j('#arrow_right').fadeIn(400);
            }
            afficheBorder(indice);
        });
        $j('#arrow_right').click(function () {
            var indice = parseInt($j('#visuel_big_programme img').attr('rel').substring(9));
            var next_indice = ++indice;
            lienCarou(indice, photos.length);
            $j('#prev').removeClass('inactif');
            if (photos[next_indice]) {
                updateImage(photos[next_indice][1], 'big_photo' + next_indice);
            }
            if (next_indice >= 1) {
                $j('#arrow_left').fadeIn(400);
            }
            if (++next_indice >= photos.length) {
                $j('#arrow_right').hide();
                $j('#next').addClass('inactif');
            }
            afficheBorder(indice);
        });
        
        /*carousel vertical*/
        $j(".vertical #next").click( function () {
            var indice = parseInt($j('#visuel_big_programme img').attr('rel').substring(9));
            var next_indice = ++indice;
            if (photos[next_indice]) {
                updateImage(photos[next_indice][1], 'big_photo' + next_indice);
            }
            if (next_indice >= 1) {
                $j('.vertical #next').fadeIn(400);
            }
            affichageFleche(next_indice,photos.length);
            afficheBorder(indice);
        });

        $j('.vertical #prev').click(function () {
            var indice = parseInt($j('#visuel_big_programme img').attr('rel').substring(9));
            var prev_indice = --indice;
            if (indice >= 0) {
                if (photos[prev_indice]) {
                    updateImage(photos[prev_indice][1], 'big_photo' + prev_indice);
                }
                if (prev_indice < photos.length) {
                    $j('.vertical #next').fadeIn(400);
                }
                affichageFleche(prev_indice,photos.length);
                lienCarou(prev_indice, photos.length);
                afficheBorder(indice);
            }
        });     
        /* set up the rollover for each thumbnails */
        $j('.visuels_programme_thumb').each(function () {
            $j(this).mouseover(function () {
                $j('#visuel_big_programme img').hide();
                var indice = $j(this).attr('rel').substring(5);
                /* get the numerical value of the rel attribute, removing the 'thumb' string */
                updateImage(photos[$j(this).attr('rel').substring(5)][1], 'big_photo' + indice);

                /* resize image if needs be */
                if ($j('#visuel_big_programme img').width() > '470') {
                    $j('#visuel_big_programme img').width(470);
                }
                $j('#visuel_big_programme img').fadeIn(400);

                /* Show or hide arrows */
                if (photos[(parseInt($j(this).attr('rel').substring(5)) + 1)]) {
                    $j('#arrow_right').fadeIn(400);
                } else {
                    $j('#arrow_right').hide();
                }
                if (photos[(parseInt($j(this).attr('rel').substring(5)) - 1)]) {
                    $j('#arrow_left').fadeIn(400);
                } else {
                    $j('#arrow_left').hide();
                }
                afficheBorder(indice);
            });
        });
        /* show the right arrow on default */
        $j('#arrow_right').fadeIn(400);
    } else {
        $j('#arrow_left, #arrow_right').hide();
    }
}
/*
*************************************************************
Function: displays or not the border of thumbnails
return: void
parameters: 
    indice: {type: integer | function: can target the img selected } 
creadted by: Anne-Laure HOAREAU
*************************************************************
*/
function afficheBorder(indice){
$j('.visuels_programme_thumb').each(function(){
    $j('.visuels_programme_thumb').css({border: "2px solid #AEB4BB"});
});
    $j('.visuels_programme_thumb:eq('+indice+')').css({border: "2px solid #52525c"}); // display a different border for img selected 
}

/*
*************************************************************
Function: function that links between small and large carousel
return: void
parametres:
    indice: {type: integer | function: to change the position after the top of the carousel img selected}
    nbrPhoto: {type: integer}
creadted by: Anne-Laure HOAREAU
*************************************************************
*/
function lienCarou(indice, nbrPhoto){
    var top = indice * 80;
    if(indice <= nbrPhoto-3){
        $j(".jCarouselLite ul").css("top", -top);
    }
}

/*
*************************************************************
Function: function that displays or not the arrows of the big visual
return: void
parametres: 
    indice: {type: integer}
    nbr: {type: integer}
creadted by: Anne-Laure HOAREAU
*************************************************************
*/
function affichageFleche(indice,nbr){
    if (indice >= nbr-1) {
        $j('#arrow_right').hide();
        $j('#next').addClass('inactif');
    } else {
        $j('#arrow_right').show();
        $j('#next').removeClass('inactif');
    }
    if (indice === 0) {
        $j('#arrow_left').hide();
        $j('#prev').addClass('inactif');
    }else {
        $j('#arrow_left').show();
        $j('#prev').removeClass('inactif');
    }
}


function updateImage(src, rel) {
    $j('#visuel_big_programme img').attr({
        'src': src,
        'rel': rel
    });

       
}

function update_form() {
    $j('.type_biens_tableau').click(function () {
        var rel_arr = $j(this).attr('rel').split('|'),
            prix,
            id_annonce;
        prix = rel_arr[0];
        id_annonce = rel_arr[1];

        if (prix >= 0 && prix <= 8) {
            // checkboxes
            $j('#checkboxes_nb_pieces input[type="checkbox"]').each(function () {
                var checkbox_prix = $j(this).attr('value');
                if (checkbox_prix != "5 et plus") {
                    if (parseInt(checkbox_prix) == parseInt(prix)) {
                        $j(this).attr('checked', true);
                    }
                } else {
                    if (parseInt(prix) >= 5) {
                        $j(this).attr('checked', true);
                    }
                }
            });
        } else {
            // radios
            $j('.radio_typebien').each(function () {
                var id_annonce_lot = $j(this).val();
                if (id_annonce) {
                    if (parseInt(id_annonce_lot) === parseInt(id_annonce)) {
                        $j(this).attr('checked', true);
                    }
                }
            });
        }
        window.location = '#ancre_demdoc';
        return false;
    });
    
    // Retour au formulaire après un envoi de demande de doc => tracking Omniture
    $j('#lien_modif_demdoc').click(function(){
        s.eVar25 = "modif_demdoc";
            var s_code = s.t();
            if (s_code) {
                    document.write(s_code);
                }
        });
}


function affichage_residence_print(nom_de_la_page, nom_interne_de_la_fenetre){
    window.open(nom_de_la_page, nom_interne_de_la_fenetre, config='toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
    } 

/******************************************************************
 Function: display or hide POI
 return: void
 parametres: null
 creadted by: Jessica SIMEON
*******************************************************************/
/* //en commentaire en attendant la mise en place
$j("#POI_header").click(function() {
  if ($j("#POI_onOff").is(":hidden")){                
      $j("#POI_onOff").fadeIn();
  }else {               
      $j("#POI_onOff").fadeOut();
  }		
});	
*/

/******************************************************************
 Function: Tags Omniture on 'Documentation gratuite' button
 return: void
 parametres: null
 creadted by: Jessica SIMEON
*******************************************************************/
tagBtnOmnitureDescription = function() {
    //console.debug("testTag1");
    current_omniture.omnitureLead("L016","event9");
    return true;
}

tagBtnOmnitureCoordonnees = function() {
    //console.debug("testTag2");
    current_omniture.omnitureLead("L017","event9");
    return true;
}

/******************************************************************
 Function: Slideshow 'Detail' with more 
 return: void
 parametres: null
 creadted by: Jessica SIMEON
*******************************************************************/

var carou = (function (){
      
        $j("#mod_carrousel_detail .bounceout .jCarouselLite").jCarouselLite({
            btnNext: "#mod_carrousel_detail .bounceout .next",
            btnPrev: "#mod_carrousel_detail .bounceout .prev",
            visible: 6,
            easing: "backout",
            speed: 1000
        });
      
}) ();


