// 拼团活动弹窗报名
$(function(){
    // pintuan_a();
    $('.puleft_ico').on('click',function(){
        pintuan_a();
    })

    $('.pintuanBox_bg,.pintuanBox_gb a').on('click',function(){
        $('.pintuanBox').hide();
        $('.pintuanBox_bg').hide();
        $('.puleft_ico').show(10);
    })
    //报名验证提交的调用
    PublicAction.AjaxSend({CORID:'in_buttom_c'/*操作ID*/});
    $('.pintuanBox .submit_area .in_buttom_c').on('click',function(){
        setTimeout(function(){
            var _html = $('.alert-container .alert-content').html();
            if(_html == '提交成功'){
                $('.pintuanBox input[type="text"]').val('');
                $('.pintuanBox').hide();
                $('.pintuanBox_bg').hide();
                $('.puleft_ico').show(10);
            }
            // console.log(_html);
        },2000)  
     
    })
    function pintuan_a(){
        $('.pintuanBox_main .lptitle').html($('.basic_box h1').text())
        $('.puleft_ico').hide();
        $('.pintuanBox').show(10);
        $('.pintuanBox_bg').show();
    }


    scrollFloor({
        floorClass : '.scroll-floor',       //楼层盒子class;默认为'.scroll-floor'
        navClass : '.scroll-nav',           //导航盒子class;默认为'.scroll-nav'
        activeClass : 'active',             //导航高亮class;默认为'active'
        delayTime:300,                      //点击导航,滚动条滑动到该位置的时间间隔;默认为200
        activeTop:200,                      //楼层到窗口的某个位置时,导航高亮(设置该位置);默认为100
        scrollTop:0                         //点击导航,楼层滑动到窗口的某位置;默认为100
      });
})


$(function(){


    /*
    *   这里用于解决从 http://m.qww.com/zt/zhhant 专题进入楼盘首页修改为800的电话
    */
   //获取GET请求参数
    function getParams(url) {
        var theRequest = new Object();
        if (!url)
            url = location.href;
        if (url.indexOf("?") !== -1)
        {
            var str = url.substr(url.indexOf("?") + 1) + "&";
            var strs = str.split("&");
            for (var i = 0; i < strs.length - 1; i++)
            {
                var key = strs[i].substring(0, strs[i].indexOf("="));
                var val = strs[i].substring(strs[i].indexOf("=") + 1);
                theRequest[key] = decodeURI(val) ;  // decodeURI 解决中文字符乱码问题
            }
        }
        return theRequest;
    }

    var url = window.location.href;

    var params = getParams(url); //获取get请求的参数
    if(params.hasOwnProperty('ty')){
       // console.log(params.ty)
       if(params.ty == 'hk'){
          $('.y_housetel span').html('800-960298');
          $('.y_telimg a').attr('href','tel:800960298');
          $('#feng_citytel').html('800960298');
       }
    }

    /*-------------------------------------------------------------------------------------*/

    // 轮播图
    // var mySwiper1 = new Swiper('#swiper1',{
    //     autoplay:true,  //自动切换
    //     loop : true,    //循环
    //     pagination: '.swiper-pagination',
    //     paginationType : 'fraction',
    //     paginationFractionRender: function (swiper, currentClassName, totalClassName) {
    //         return '<span class="' + currentClassName + '"></span>' +
    //                ' / ' +
    //                '<span class="' + totalClassName + '"></span>';
    //     }
        
    //     })



 
    // 资讯分类
    var swiper2 = new Swiper('#swiper22',{
        loop : true,
        spaceBetween: 20,
        centeredSlides: true,
        slidesPerView: 'auto',
        touchRatio: 0.5,
        slideToClickedSlide: true
    });







    $('.feng_album').on('click',function () {
        var _this = $(this);
        $('.feng_album').removeClass('on')
        _this.addClass('on');
        // album_id: "6"
        // create_at: "1529718710"
        // del: "1"
        // hid: "3161"
        // id: "22830"
        // img: "5d1a58c5533e195ee9fffcbfa6472493.jpg"
        // sort: "0"
        // state: "1"
        // title: "富力布里斯本一号-交通图"
        // update_at: "1529718710"
        $.ajax({
            type: 'POST',
            // url: '/house/albumsid',
            data:{id:_this.attr('value'),hid:_this.attr('data-id'),csrf_token_m:csrfToken},
            dataType: 'json',
            success: function(data){
                var result = '';
                var result_pagination = '';
                if(data.code == 200){

                    result += '<div class="swiper-container" id="swiper1">';
                    result += '<div class="swiper-wrapper">';

                    $.each(data.data,function (k,v) {
                        result += '<div class="swiper-slide" data-swiper-autoplay="3000"><a href="/house/album/'+v.hid+'/"><img src="'+v.img+'" alt=""></a></div>';
                    })

                    result += '</div>';
                    result_pagination += '<div class="swiper-pagination"></div>';
                    result += '</div>';

                    // $('#swiper1 .swiper-wrapper').html('');
                    $('.swiper_container_box').html(result);
                    $('.m_swiper-pagination_box').html(result_pagination);
                   new Swiper('#swiper1',{
                        autoplay:true,  //自动切换
                        loop : true,    //循环
                        pagination: '.swiper-pagination',
                        paginationType : 'fraction',
                        // paginationFractionRender: function (swiper, currentClassName, totalClassName) {
                        //     return '<span class="' + currentClassName + '"></span>' +
                        //         ' / ' +
                        //         '<span class="' + totalClassName + '"></span>';
                        // }

                    })
                }

            },
            error: function(xhr, type){
            }
        });
    })
    // 点击第一个
    $('.result a.feng_album').eq(0).click();


$('.lp_box').on('click','li',function(){
  album_click();
})
$('.lp_box ul li').eq(0).click();
    

function album_click(){
    $("#lightgallery").lightGallery();
      // $('.optionMore').html('');
     // var Getoption = $('.find_nav_list');
     // $('.optionMore').append(Getoption.clone(true));
     // $('.optionMore').find('.find_nav_list').addClass('find_nav_list2');
     // $('.find_nav_list2 ul li').on('click',function(){
     //    var _value = $(this).attr('value')
     //    $('.find_nav_list ul li').each(function(){
     //      var _vl = $(this).attr('value');
     //      if(_value == _vl){
     //        $(this).addClass('in').siblings().removeClass('in');
     //      }
     //    })
     // })
}

// 展开
// $('.lp_unfold').on("click",function(){
//     $(this).html('收起');
//     $('.lp_ctn').css({'height':'auto','overflow':'inherit'})
//     if(!$(this).hasClass('in')){
//         $(this).addClass('in');
//     }else{
//         $(this).removeClass('in');
//     }
//     if($(this).hasClass('in')){
//         // console.log($(this).hasClass('in'))
//         $(this).html("展开");
//         $('.lp_ctn').css({'height':'105px','overflow':'hidden'})
//     }
    
// })


  // $('.m_lpAnalysis_text_box .m_lpAnalysis_text').eq(0).show();
  // $('.m_lpAnalysis .m_lpAnalysis_li').eq(0).find('span').attr('class','on');
  // $('.m_lpAnalysis .m_lpAnalysis_li').eq(0).find('i').attr('class','on');

  // $('.m_lpAnalysis .m_lpAnalysis_li').on('click',function(){
      
  //     var idQH = $(this).attr('qhid')
  //     $('.m_lpAnalysis_text').hide();

  //     $('.m_lpAnalysis_text[qhid="'+idQH+'"]').show();
  //     $(this).find('span').attr('class','on').parent().siblings().find('span').attr('class','');
  //     $(this).find('i').attr('class','on').parent().siblings().find('i').attr('class','');

  // })


var _lpid = $('.lp_gd').attr('lpid');   //获取楼盘ID

var _Width = $('#lightgallery li').outerWidth();  //获取 LI 宽度

var _margin = parseInt( $('#lightgallery li').css('marginRight'));   //获取 LI 的 margin

var ulWidth= $('#lightgallery').outerWidth();  // UL 的 宽度

var liLength= $('#lightgallery li').length;   //获取 LI的 个数


     var Total_length =  _margin * (liLength -1)+(_Width * liLength) + 70 - ulWidth;
   // console.log(Total_length);

// 资讯分类

if(liLength >= 3){
    // 户型
    var swiper3 = new Swiper('#swiper23',{
        slidesPerView : 'auto',
        slidesPerGroup : 2,

        onTouchEnd: function(swiper){  // 移动松开后 跳转
            TR=swiper.translate
            // console.log(TR);
            if(TR < -Total_length){ 

            swiper.setWrapperTranslate(TR);
                    location.href ="http://m.qianwuwang.com/house/housetype/"+_lpid+"/";
            };
        },

        onTouchMove: function(swiper){   // 移动执行 
            TR=swiper.translate
    
            if(TR<-Total_length){
               $('.lp_gd').attr('id','lp_gd1');
               $('.lp_gd').show();
            }else{
               $('.lp_gd').attr('id','lp_gd');
               $('.lp_gd').hide();
            }
        }
    });  
}


var _zxWidth = $('#swiper_feng ul li').outerWidth();  //获取 LI 宽度

var _zxmargin = parseInt( $('#swiper_feng ul li').css('marginRight'));   //获取 LI 的 margin

var zxulWidth= $('#swiper_feng ul').outerWidth();  // UL 的 宽度

var _zxlength = $('#swiper_feng ul li').length;

var feng_length =  _zxmargin * (_zxlength -1)+(_zxWidth * _zxlength) + 70 - zxulWidth;
        // console.log(feng_length);
// 资讯分类

if(_zxlength > 1){
    var aaaa =  new Swiper('#swiper_feng',{
        slidesPerView : 'auto',
        slidesPerGroup : 1,

        onTouchEnd: function(swiper){  // 移动松开后 跳转
            TR=swiper.translate
        
            if(TR < -feng_length){ 

            swiper.setWrapperTranslate(TR);
                    location.href ="http://m.qianwuwang.com/house/summary/"+_lpid+"/";
            };
        },

        onTouchMove: function(swiper){   // 移动执行 
            TR=swiper.translate
               console.log(TR);
            if(TR<-feng_length){
               $('.classify_gd').attr('id','classify_gd');
               $('.classify_gd').show();
            }else{
               $('.classify_gd').attr('id','classify_gd');
               $('.classify_gd').hide();
            }
        }
    });
}





   
   // 汇率弹窗
   $('.m_conversion').on('click',function(){
       $('.exchange_rate_box').fadeIn(100);
   })

   $('.exchange_gb').on('click',function(){
       $('.exchange_rate_box').fadeOut(100);
   })


})

var ster = 0;
// 头部导航
   $(window).scroll(function (){
      ster = $(this).scrollTop();
      navign4(ster);

  });

   var dir4 = $(document).scrollTop();  
   navign4(dir4);


  function navign4(st){
      if(st >180){
          $('.y_v3homeNav').show();
          $('.m_top').attr('id','');
      }else{
          $('.y_v3homeNav').hide();
          $('.m_top').attr('id','m_top');


      }
  }



// 楼盘分析

$('.m_lpfx .m_lpAnalysis .m_lpAnalysis_li').eq(0).attr('id','on')

 var _qhid ='';
$('.m_lpfx .m_lpAnalysis .m_lpAnalysis_li').on('click',function(){

    _qhid = $(this).attr('m_qhid');
    _type = $(this).attr('type');


    $(this).attr('id','on').siblings().attr('id','');

    ajax_lp();
    
      

})


  function ajax_lp(){
      var html = '';
      $.ajax({
        url: "/info/getinfo",  // 索取
        data:{hid:_qhid,type:_type,csrf_token_m:csrfToken},  //传ID
        type: "GET",
        dataType: "json",
        success: function(data) {//请求成功完成后要执行的方法
            html+='<div class="m_lpfx_textw">';
          if(data.code == 200){
                 if(data.data.analysis){
                    html+='<div class="m_lpfx_text">'+data.data.analysis+'</div>';
                    
                 }else if(data.data.terms){
                    html+='<div class="m_lpfx_text">'+data.data.terms+'</div>';
                 }else{
                    html+='<div class="m_lpfx_text">';
                    html+='<div class="m_lpfx_text_img">';
                    html+='<img src="/image/lptj01.png" alt="">';
                    html+='<div class="m_lpfx_text_zwsj">暂无数据</div>';
                    html+='</div>';
                    html+='</div>';
                 }
           }else{
              
              html+='<div class="m_lpfx_text">';
              html+='<div class="m_lpfx_text_img">';
              html+='<img src="/image/lptj01.png" alt="">';
              html+='<div class="m_lpfx_text_zwsj">暂无数据</div>';
              html+='</div>';
              html+='</div>';

           }

           html+='</div>';

             $('.m_lpfx_text_box').html(html);
             imgauto();
        }
    });

  }

//处理图片 自动高度
function imgauto(){
  $('.m_lpfx_text img').each(function(){
    $('.m_lpfx_text img').css({'height':'auto'});
  })  
}






var _top = '';

$('.m_commentary').on('click',function(){
    $('.m_lpfx_box').fadeIn(80);
    $('.m_lpfx').animate({bottom:'0%'},400);

    _top = $(window).scrollTop();   // 弹窗开启  遮罩层以外的东西不移动   
    $('body').css("top",-ster+"px");
    $('body').addClass('add');


    $('.m_top').hide();
    $('.m_commentary').hide();


    $('.m_lpAnalysis_li[type="analysis"]').click();
})


$('.m_lpfx_zhez').on('click',function(){
      $('.m_top').show();
    setTimeout(function(){
    $('.m_commentary').show();
    },400)


    $('.m_lpfx').animate({bottom:'-88%'},400);  

    setTimeout(function(){
        $('.m_lpfx_box').fadeOut(80);
    },400)

    $('body').removeClass('add');//去掉给body的类
    $(window).scrollTop(_top);//设置页面滚动的高度,如果不设置,关闭弹出层时页面会回到顶部。
})

$('.m_lpfx_gb').on('click',function(){
      $('.m_top').show();
    setTimeout(function(){
    $('.m_commentary').show();
    },400)


    $('.m_lpfx').animate({bottom:'-88%'},400);  

    setTimeout(function(){
        $('.m_lpfx_box').fadeOut(80);
    },400)

    $('body').removeClass('add');//去掉给body的类
    $(window).scrollTop(_top);//设置页面滚动的高度,如果不设置,关闭弹出层时页面会回到顶部。
})


// 楼盘分析  购房须知
$('.m_lpfx_text').find('img').each(function(){
    var $that = $(this);
    $that.removeAttr('width');
    $that.removeAttr('height');
    $that.css({'display':'block','width':'100%','height':'auto'});
})



    jQuery(window).bind('scrollstart', function(){
         $('.m_commentary').animate({left:'-43px'},400);
    });
 
    jQuery(window).bind('scrollstop', function(e){
          $('.m_commentary').animate({left:'0px'},400); 
    });
 




// 视频
$('.m_lpvideo_img').on('click',function(){   //处理视频播放图标

  var _video = document.getElementById("myVideo");

      myVideo.play();   //点击图标视频播放
      $('.m_video_sp').attr('controls','controls');    //点击 显示默认的控件
      $(this).hide(); 
})



 
    // 资讯分类
    var m_swiperv2 = new Swiper('#m_swiperv2',{

          // autoplay:true,  //自动切换
          autoplay:5500,
          loop : true,    //循环
          pagination: '.swiper-pagination',
          paginationType : 'fraction',
          paginationFractionRender: function (swiper, currentClassName, totalClassName) {
              return '<span class="' + currentClassName + '"></span>' +
                  ' / ' +
                  '<span class="' + totalClassName + '"></span>';
          }

    });

$(function(){
  $('.timew').html('有效期:'+timew)
})

/*-----------------------------------------百度地图-----------------------------------------------------------*/

$(function(){
  var _lTude= '';
  _lTude =$('#y_lpmap').attr('data-jwd');        //获取经纬度
  if (_lTude != undefined && _lTude != '') {
    var pintx = parseFloat(_lTude.split(',')[0]);
    var pinty = parseFloat(_lTude.split(',')[1]);
    masw(pintx,pinty);
  };
})
function masw(len,lng){
    mapboxgl.accessToken = 'pk.eyJ1IjoicWlhbnd1MTQzNiIsImEiOiJjazZxZ2NyaGYwM3V6M2tueGZpb3FsYTYyIn0.lSEEDlQog3bc59KiDdx61g';
    var map = new mapboxgl.Map({
        container: 'map',
        style: 'mapbox://styles/mapbox/streets-v11',
        center: [len,lng], // starting position [lng, lat]
        zoom: 13 // starting zoom
    });
    map.on('load', function() {
        map.loadImage('/image/home_ico38.png', function(error, image) {
            if (error) throw error;
            map.addImage('cat', image);
            map.addLayer({
                "id": "points",
                "type": "symbol",
                "source": {
                    "type": "geojson",
                    "data": {
                        "type": "FeatureCollection",
                        "features": [{
                            "type": "Feature",
                            "geometry": {
                                "type": "Point",
                                "coordinates": [len,lng],
                            }
                        }]
                    }
                },
                "layout": {
                    "icon-image": "cat",
                    "icon-size": 0.5
                }
            });
        });

    });
}



var  Homeurl=window.location.href
$(function(){
    var telurl=$('.y_modtel .y_modtel_text p.y_call span').html();
    if(Homeurl.indexOf("?source=pc")!=-1){
        return window.location.href = 'tel:'+telurl;
    };
})


// 楼盘解说-展开详情
// $('.js_AnswersB').on('click',function(){
//   $('.js_Answersmain').animate({'bottom':'0px'});
//   $('.js_Answersmain_bg').show();
//
//   $('.js_centerImg img').each(function(){
//     $('.js_centerImg img').css({'height':'auto','width':'100%'});
//   })
// })
//
// $('.js_Answersmain_bg,.js_Answersmain_gb').on('click',function(){
//   $('.js_Answersmain').animate({'bottom':'-100%'});
//   $('.js_Answersmain_bg').hide();
// })