Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};
function utf8_decode(utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;
 
    while ( i < utftext.length ) {
 
        c = utftext.charCodeAt(i);
 
        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        }
        else if((c > 191) && (c < 224)) {
            c2 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        }
        else {
            c2 = utftext.charCodeAt(i+1);
            c3 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
 
    }
 
    return string;
}


var map;
var markers = new Array();


var infowindow = new Array();
   


function ajax_map_change(store_locations) {
    // Create an array of styles.
    var size = Object.size(store_locations);
    var pinkParksStyles = [
    {
        featureType: "all",
        stylers: [{
            saturation: -80
        }]
    },
    {
        featureType: "poi.park",
        stylers: [{
            hue: "#000000"
        },

        {
            saturation: -50
        }
        ]
    }
    ];
 
    var map_center = new google.maps.LatLng(48.8668229,2.3298144);
    var image = 'http://clients.pennylane.fr/c_vendome/wp-content/themes/vendome/images/marker.png';
    var myOptions = {
        zoom: 16,
        center: map_center,
        mapTypeControl: true,
           
        zoomControl: true,
        zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
            mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'pink_parks']
        }
    }
    var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,
    {
        name: "Pink Parks"
    });
    map = new google.maps.Map(document.getElementById("interactive_map"), myOptions);
    map.mapTypes.set('pink_parks', pinkMapType);
    map.setMapTypeId('pink_parks');
    for(i=1;i<=size;i++)
    {
        markers[i] = new google.maps.Marker(
        {
            position: new google.maps.LatLng(store_locations[i]["_pronamic_google_maps_latitude"],store_locations[i]["_pronamic_google_maps_longitude"]),
            map: map,
            title: store_locations[i]["_pronamic_google_maps_title"],
            icon: image
        } );
        
        var adresse =store_locations[i]["boutique_adresse"].split('|');
        var adresseString="";
        for(var k=0; k<adresse.length; k++){
            adresseString = adresseString+"<p class='google_adresse'>" +adresse[k]+"</p><br>";
        }
        var tel =store_locations[i]["boutique_telephone"].split('|');
        var telString="";
        for(var l=0; l<tel.length; l++){
            telString = telString+tel[l]+" - ";
        }
        telString = telString.substring(0,telString.length-5);
        /*if(store_locations[i]["google_image"]!=undefined){
        var contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+store_locations[i]["_pronamic_google_maps_title"]+"</p><p class='google_adresse'>"+adresseString+"</p><p class='google_telephone'> "+telString+"</p></div><a href='' class='google_image'><img src='http://clients.pennylane.fr/c_vendome/wp-content/files_mf/"+store_locations[i]["google_image"]+"' /></a></div>"
        } else {
        }*/
        var contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+store_locations[i]["_pronamic_google_maps_title"]+"</p><p class='google_adresse'>"+adresseString+"</p><p class='google_telephone'> "+telString+"</p></div></div>"
      
        bindInfoWindow(markers[i],contenu);
        google.maps.event.addListener(markers[i], 'click', 
            function() {
            //  infowindow[i].open(map, this);
            //   map.set_center(new google.maps.LatLng(store_locations[i]["_pronamic_google_maps_latitude"],store_locations[i]["_pronamic_google_maps_longitude"]));
            //  map.set_zoom(16);
            } );
    }
} 
function bindInfoWindow(marqueur, info) {
    google.maps.event.addListener(marqueur, 'click', function() {
        for(var i =0; i<infowindow.length; i++){
            infowindow[i].close(map, marqueur);
        }
        infowindow[i] = new google.maps.InfoWindow();
        infowindow[i].setContent(info);
        infowindow[i].open(map, marqueur);
    });
}


function test(latitude,longitude,boutique,adresse,img,tel,adresse2,tel2) {
  

    // Create an array of styles.
    var pinkParksStyles = [
    {
        featureType: "all",
        stylers: [
        {
            saturation: -80
        }
        ]
    },
    {
        featureType: "poi.park",
        stylers: [
        {
            hue: "#000000"
        },
        {
            saturation: -50
        }
        ]
    }
    ];
    var map_center = new google.maps.LatLng(latitude,longitude);
    var myLatlng = new google.maps.LatLng(latitude,longitude);
    var image = 'http://clients.pennylane.fr/c_vendome/wp-content/themes/vendome/images/marker.png';  
    var myOptions = {
        zoom: 16,
        center: map_center,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControlOptions: {
            mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'pink_parks']
        }
    }
    var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,
    {
        name: "Pink Parks"
    });
    map = new google.maps.Map(document.getElementById("interactive_map"), myOptions);
    map.mapTypes.set('pink_parks', pinkMapType);
    map.setMapTypeId('pink_parks');

    var markers = new google.maps.Marker(
    {
        position: myLatlng,
        map: map,
        title: utf8_decode(unescape(boutique)),
        icon:image
    } );
    //   boutique = boutique.replace("%20"," "); Le & menacher passe comme un nouveau parametre
    var contenu="";
    if(adresse2==undefined){
        //contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+utf8_decode(unescape(boutique))+"</p><p class='google_adresse'>"+utf8_decode(unescape(adresse))+"</p><p class='google_telephone'> "+unescape(tel)+"</p></div><a href='' class='google_image'><img src='http://clients.pennylane.fr/c_vendome/wp-content/files_mf/"+img+"' width='50' height='50'/></a></div>"
        contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+utf8_decode(unescape(boutique))+"</p><p class='google_adresse'>"+utf8_decode(unescape(adresse))+"</p><p class='google_telephone'> "+unescape(tel)+"</p></div></div>"
    } else {
        if(tel2!=undefined){
            contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+utf8_decode(unescape(boutique))+"</p><p class='google_adresse'>"+utf8_decode(unescape(adresse))+"</p><p class='google_adresse' style='clear:both; margin-top:0px;'>"+utf8_decode(unescape(adresse2))+"</p><p class='google_telephone' style='clear:both;'> "+unescape(tel)+" - "+unescape(tel2)+"</p></div></div>"
        
        //contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+utf8_decode(unescape(boutique))+"</p><p class='google_adresse'>"+utf8_decode(unescape(adresse))+"</p><p class='google_adresse' style='clear:both; margin-top:0px;'>"+utf8_decode(unescape(adresse2))+"</p><p class='google_telephone' style='clear:both;'> "+unescape(tel)+" - "+unescape(tel2)+"</p></div><a href='' class='google_image'><img src='http://clients.pennylane.fr/c_vendome/wp-content/files_mf/"+img+"' /></a></div>"
        } else{
            contenu="<div class='google_infobox'><div class='google_adresse'><p class='google_titre'>"+utf8_decode(unescape(boutique))+"</p><p class='google_adresse'>"+utf8_decode(unescape(adresse))+"</p><p class='google_adresse' style='clear:both; margin-top:0px;'>"+utf8_decode(unescape(adresse2))+"</p><p class='google_telephone'> "+unescape(tel)+"</p></div></div>"
        }   
    }
  
       
    var infowindow = new google.maps.InfoWindow({
        content: contenu
    });
    google.maps.event.addListener(markers, 'click', 
        function() {
            infowindow.open(map, markers);
            map.set_center(myLatlng);
            map.set_zoom(16);
        } );
 
    
} 
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function initialize(){
    if(getUrlVars()["poslat"]!=null){
        if(getUrlVars()["adresse2"]!=null){
            if(getUrlVars()["tel2"]!=null){
                test(getUrlVars()["poslat"],getUrlVars()["poslong"],getUrlVars()["boutique"],getUrlVars()["adresse"],getUrlVars()["img"],getUrlVars()["tel"],getUrlVars()["adresse2"],getUrlVars()["tel2"]);
            }else{
                test(getUrlVars()["poslat"],getUrlVars()["poslong"],getUrlVars()["boutique"],getUrlVars()["adresse"],getUrlVars()["img"],getUrlVars()["tel"],getUrlVars()["adresse2"]);
            }
        }
        else{
            test(getUrlVars()["poslat"],getUrlVars()["poslong"],getUrlVars()["boutique"],getUrlVars()["adresse"],getUrlVars()["img"],getUrlVars()["tel"]);
        }
    }
    else{
        $.ajax({
            type: "GET",
            url: "http://comite-vendome.fr/traitement-ajax/", 
            data: "type_boutique=joaillerie_horlogerie_orfevrerie,mode_accessoires_parfums,culture,palaces_hotels_gastronomie,finance_immobilier_avocats", 
            success: function(msg){ 
                var myObject = eval('(' + msg + ')');
                ajax_map_change(myObject)
            }
        });
    }
   
}

function loadScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
    document.body.appendChild(script);
}
  
window.onload = loadScript;


$(document).ready(function() {
    $(".notebook-full").colorbox({
        iframe:true, 
        innerWidth:825, 
        innerHeight:574
    });
    
    $(".notebook").colorbox({
        iframe:true, 
        innerWidth:825, 
        innerHeight:574
    });
    
    $(".notebook-full").hover(function(){
        $(this).append("<div class='hover-notebook-full'>« Le Carnet Vendôme <br/> est&nbsp;en&nbsp;vente&nbsp;à&nbsp;la&nbsp;librairie&nbsp;Galignani,<br/> 224, rue de Rivoli,<br/> Paris 1er » <a href='#' class='know_more_2'>CONSULTEZ ICI</a></div>");
        $(this).find(".hover-notebook-full").fadeIn();
        Cufon.refresh(".hover-notebook,.hover-notebook-full");
    },function(){
        $(this).find(".hover-notebook-full").fadeOut("fast", function() {
            $(this).remove(".hover-notebook-full");
        }    
        );
       
        
    });
    
    $(".notebook").hover(function(){
        $(this).append("<div class='hover-notebook'>« Le Carnet Vendôme <br/> est&nbsp;en&nbsp;vente&nbsp;à&nbsp;la&nbsp;librairie&nbsp;Galignani,<br/> 224, rue de Rivoli, Paris 1er » <a href='#' class='know_more_2'>CONSULTEZ ICI</a></div>");
        $(this).find(".hover-notebook").fadeIn();
        Cufon.refresh(".hover-notebook,.hover-notebook-full");
    },function(){
        $(this).find(".hover-notebook").fadeOut("fast", function() {
            $(this).remove(".hover-notebook");
        }    
        );
       
        
    });
    $(".show-boutique").click(function(){
        if($(this).hasClass("active-link")){
            $(".membre-liste").fadeOut();
            $(this).removeClass("active-link");
        }
        else{
            if( $(".show-boutique-categ").hasClass("active-link")){
                $(".membre-liste-categ").fadeOut();
                $(".show-boutique-categ").removeClass("active-link");
                
            }
            $(".membre-liste").fadeIn();
            $(this).addClass("active-link");
            
        }
        $(".about-page-full").css("height","1012px");
        return false;
    });
    
    $(".show-boutique-categ").click(function(){
        if($(this).hasClass("active-link")){
            $(".membre-liste-categ").fadeOut();
            $(this).removeClass("active-link");
            $(".about-page-full").css("height","1012px");
        }
        else{
            if( $(".show-boutique").hasClass("active-link")){
                $(".membre-liste").fadeOut();
                $(".show-boutique").removeClass("active-link");
                $(".about-page-full").css("height","1012px");
            }
            $(".membre-liste-categ").fadeIn();
            $(this).addClass("active-link");
            $(".about-page-full").css("height","auto");
        }
        return false;
    });
    
    
    function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
var slice;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
     var ieversion=new Number(RegExp.$1);
     if (ieversion<=8){
    slice = 1750;
    }
    else{
    slice = 2000
}
}
else{
    slice = 2000
}
    
  $(".mentions-legals #legals-content").expander({
        slicePoint: slice,
        expandText: 'voir la suite',
        userCollapseText: 'reduire',
        beforeExpand: function() {
            $(".about-page-full").css("height","auto");
        },
        onCollapse: function(byUser) {
            var by = byUser ? 'user' : 'timer';
            $(".about-page-full").css("height","1012px");
        }
    });
    
    
   
    
    $(".fonctionnement .texte-about").expander({
        slicePoint: 1920,
        expandText: 'voir la suite',
        userCollapseText: 'reduire',
        beforeExpand: function() {
            $(".about-page-full").css("height","auto");
        },
        onCollapse: function(byUser) {
            var by = byUser ? 'user' : 'timer';
            $(".about-page-full").css("height","1012px");
        }
    });
    $(".membres .texte-about").expander({
        slicePoint: 1320,
        expandText: 'voir la suite',
        userCollapseText: 'reduire',
        beforeExpand: function() {
            $(".about-page-full").css("height","auto");
        },
        onCollapse: function(byUser) {
            var by = byUser ? 'user' : 'timer';
            $(".about-page-full").css("height","1012px");
        }
    });
    $(" .actions .texte-about").expander({
        slicePoint: 2800,
        expandText: 'voir la suite',
        userCollapseText: 'reduire',
        beforeExpand: function() {
            $(".about-page-full").css("height","auto");
        },
        onCollapse: function(byUser) {
            var by = byUser ? 'user' : 'timer';
            $(".about-page-full").css("height","1012px");
        }
    });
    
    $(" .le-coeur-historique-de-paris .texte-about").expander({
        slicePoint: 1320,
        expandText: 'voir la suite',
        userCollapseText: 'reduire',
        beforeExpand: function() {
            $(".about-page-full").css("height","auto");
        },
        onCollapse: function(byUser) {
            var by = byUser ? 'user' : 'timer';
            $(".about-page-full").css("height","1012px");
        }
    });
   
    
    
    /*****SCROLL BAR HOME***/
    var listitems = new Array();
    var dataSent="";
    $(".bijoux").click( function() {
        dataSent="";
        if($(this).attr('checked')){
            listitems[0] = "joaillerie_horlogerie_orfevrerie";
            for(var i = 0; i<listitems.length; i++){
                if(listitems[i]!=null){
                    dataSent = dataSent + listitems[i] +",";
                }
            }
        }
        else{
            delete listitems[0];
            for(var j = 0; j<listitems.length; j++){
                if(listitems[j]!=null){
                    dataSent = dataSent + listitems[j] +",";
                }
            }
        }
        $.ajax({
            type: "GET",
            url: "http://comite-vendome.fr/traitement-ajax/", 
            data: "type_boutique="+dataSent, 
            success: function(msg){ 
                var myObject = eval('(' + msg + ')');
                ajax_map_change(myObject)
            }
        });
        
    });
    $(".perfumes").click( function() {
        dataSent="";
        if($(this).attr('checked')){
         
            listitems[1] = "mode_accessoires_parfums";
            for(var i =0; i<listitems.length; i++){
                if(listitems[i]!=null){
                    dataSent = dataSent + listitems[i] +",";
                }
            }
        } else{
            delete listitems[1];
            for(var j = 0; j<listitems.length; j++){
                if(listitems[j]!=null){
                    dataSent = dataSent + listitems[j] +",";
                }
            }
        }
        $.ajax({
            type: "GET",
            url: "http://comite-vendome.fr/traitement-ajax/", 
            data: "type_boutique="+dataSent, 
            success: function(msg){ 
                var myObject = eval('(' + msg + ')');
                ajax_map_change(myObject)
            }
        });
    });
  
    $(".cultureInput").click( function() {
        dataSent="";
        if($(this).attr('checked')){
         
            listitems[2] = "culture";
            for(var i =0; i<listitems.length; i++){
                if(listitems[i]!=null){
                    dataSent = dataSent + listitems[i] +",";
                }
            }
        } else{
            delete listitems[2];
            for(var j = 0; j<listitems.length; j++){
                if(listitems[j]!=null){
                    dataSent = dataSent + listitems[j] +",";
                }
            }
        }
        $.ajax({
            type: "GET",
            url: "http://comite-vendome.fr/traitement-ajax/", 
            data: "type_boutique="+dataSent, 
            success: function(msg){ 
                var myObject = eval('(' + msg + ')');
                ajax_map_change(myObject)
            }
        });
    });
    $(".hotels").click( function() {
        dataSent="";
        if($(this).attr('checked')){
         
            listitems[3] = "palaces_hotels_gastronomie";
            for(var i =0; i<listitems.length; i++){
                if(listitems[i]!=null){
                    dataSent = dataSent + listitems[i] +",";
                }
            }
        } else{
            delete listitems[3];
            for(var j = 0; j<listitems.length; j++){
                if(listitems[j]!=null){
                    dataSent = dataSent + listitems[j] +",";
                }
            }
        }
        $.ajax({
            type: "GET",
            url: "http://comite-vendome.fr/traitement-ajax/", 
            data: "type_boutique="+dataSent, 
            success: function(msg){ 
                var myObject = eval('(' + msg + ')');
                ajax_map_change(myObject)
            }
        });
    });
    $(".funds").click( function() {
        dataSent="";
        if($(this).attr('checked')){
         
            listitems[4] = "finance_immobilier_avocats";
            for(var i =0; i<listitems.length; i++){
                if(listitems[i]!=null){
                    dataSent = dataSent + listitems[i] +",";
                }
            }
        } else{
            delete listitems[4];
            for(var j = 0; j<listitems.length; j++){
                if(listitems[j]!=null){
                    dataSent = dataSent + listitems[j] +",";
                }
            }
        }
        $.ajax({
            type: "GET",
            url: "http://comite-vendome.fr/traitement-ajax/", 
            data: "type_boutique="+dataSent, 
            success: function(msg){ 
                var myObject = eval('(' + msg + ')');
                ajax_map_change(myObject)
            }
        });
    });
 
        
        
    $(".news ul").scrollbar();
    /******FONT*****/            
    
    
    $("#top_links ul li").hover(function(){
        if($(this).children("ul").size() > 0 ){
            $(this).children("ul").slideDown();
        } 
    },function(){
        $(this).children("ul").slideUp(); 
    });
    
    /******SLIDER*****/
    $('#bouton_slide a').click(function(){
        if(!$(this).hasClass("active")){
            $(this).siblings().removeClass("active");
            $(this).addClass("active");
            var slideClass = $(this).attr("class");
            var slide = slideClass.split(" ");
            $("#slideshow img").fadeOut();
            $("#slideshow ."+slide[0]+"").fadeIn();
        }
        return false;
    });
   


    /******HOME CIRCUIT ANIMATION ******/
    $('.circuit ul li').hover(function(){
        $(this).animate({
            marginRight: "15px"
        }, 200 );
    },function(){
        $(this).animate({
            marginRight: "0px"
        }, 200 );
    });

    /*******SLIDER OTHER BOUTIQUE*****/

    var position = 0;
    $('#down-other-boutique').click(function(){
        //alert($(this).prev(".other-boutique").children("ul").height());
        if(position < $(this).prev(".other-boutique").children("ul").height()-400){
            position = position+300;
        //  alert(position);
        }
        $('.other-boutique').animate({
            scrollTop: position
        }, 400); 
    
        return false;
    });
    $('#up-other-boutique').click(function(){
        // alert($(this).prev("ul").height());
        if(position>0){
            position = position-300;
        }
        $('.other-boutique').animate({
            scrollTop: position
        }, 400); 
   
        return false;
    });


    $('#circuit_etape a').click(function(){
        if(!$(this).hasClass("on")){
            $(this).siblings().removeClass("on");
            $(this).addClass("on");
            var slideClass = $(this).attr("id");
            var slide = slideClass.split(" ");
            $("#slide_circuit div").fadeOut();
            $("#slide_circuit ."+slide[0]+"").fadeIn();
        }
        return false;
    });
   
   
   
   
});
