// 顶部检索栏
$(window).scroll(function (){
    var st = $(this).scrollTop();
    if(st >10){
        $('.w_top').addClass('w-top-bg');
    }else{
        $('.w_top').removeClass('w-top-bg');
    }
});                               


//轮播图片
var mySwiper1= new Swiper(".swiper-container1",{
        loop : true,
        loopedSlides:4,
        autoplay:5500,
        autoplayDisableOnInteraction : false,
        // 如果需要分页器
        pagination: '.swiper-pagination',
        slidesPerView :"auto"
    });
    var regIon= new Swiper(".swiper-container2",{
        loop : false,
        loopedSlides:4,
        pagination: '.swiper-pagination',
        autoplayDisableOnInteraction : false,
        slidesPerView :"auto"
    });


// 品牌馆
var mySwiper1= new Swiper("#yw_swiper_5",{
    loop : false,
    // autoplay:5500,
    slidesPerGroup : 2,
    autoplayDisableOnInteraction : false,
    slidesPerView :"auto"
});



    // 品房头条
    function autoScroll(obj){
        $(obj).find("ul").animate({
            marginTop : "-30px"
        },500,function(){
            $(this).css({marginTop : "0px"}).find("li:first").appendTo(this);
        })
    }
    $(function(){
        setInterval('autoScroll(".headle_right .content")',5000);
    })


    // 2018-10-11 轮播图
    var mySwiper1= new Swiper("#yw_swiper",{
        loop : true,
        loopedSlides:4,
        // autoplay:5500,
        autoplayDisableOnInteraction : false,
        // 如果需要分页器
        pagination: '.yw_swiper-pagination',
        slidesPerView :"auto"
    });

    




    $(window).scroll(function (){
        var st = $(this).scrollTop();
        if(st >196){
            $('.suspension').fadeIn().addClass('xungua');
            $('.header').fadeOut();
        }else{
            $('.suspension').fadeOut();
            $('.header').fadeIn();
        }
    });
    $('.suspension').on('click',function(){
        $('body,html').animate({ scrollTop: 0 }, 1000);
        return false;
    })


    var trend = $('.y_quyou_list ul.list_m li').eq(0).find('a').attr('CityData');

     index_trend ();

$(function(){

    var Citya = $('.y_quyou_list ul.list_m li').eq(0).find('a').text();
    $('.y_quyou em a').text(Citya);
    $('.y_quyou_list ul.list_m li').eq(0).attr('class','on');

    $('.y_quyou em').on('click',function(){
        $('.y_quyou_list_bg').fadeIn();
        $('.y_quyou_list').slideDown("slow");
    })
    $('.y_quyou_list_bg').on('click',function(){
        $(this).fadeOut();
        $('.y_quyou_list').fadeOut();
    })
    $('.y_quyou_list').on('click',function(){
        $(this).fadeOut();
        $('.y_quyou_list_bg').fadeOut();
    });

    $('.y_quyou_list ul.list_m li a').on('click',function(){
        $(this).parent().addClass('on').siblings().removeClass('on');
        var oAtexe=$(this).text();
        $('.y_quyou em a').text(oAtexe);
        // console.log(oAtexe);
        trend = $(this).attr('CityData');

        index_trend ();
       
    })
});


function index_trend (){
 // var html = '';
 // var _html ='';
 //    $.ajax({
 //      url: "/index/cityprice",
 //      data:{id:trend},
 //      type: "POST",
 //      dataType: "json",
 //      success: function(data) {//请求成功完成后要执行的方法
 //        if(data.code == 200){
 //          html+=  '<p class="y_jg"><span>'+data.data.price+'</span><em>元/m²</em></p>';
 //          html+=  '<p class="y_text">'+ data.data.city_name + data.data.price_at +'房价均价</p>';
 //          if(data.data.trend == 1){
 //              _html+= '<img src="/image/fall1.png" alt=""><span class="red">上升'+data.data.contrast+'</span>';
 //          } else if(data.data.trend == 2){
 //              _html+= '<img src="/image/fall.png" alt=""><span class="lr">下跌-'+data.data.contrast+'</span>';   //上升下跌
 //          }
 //        }
 //          $('.y_houspic_text').html(html);
 //          $('.fall').html(_html);
 //      }
 //  });
}

// function m_hotlp_hyh (rand = null){
//     var cityId = $('#feng_city_id').html();
//     var type = $('#stype').html();
//        var html = '';
//             $.ajax({
//               url: "/index/hothouses",
//               data:{rand:rand,csrf_token_m:csrfToken,city:cityId,type:type},
//               type: "POST",
//               dataType: "json",
//               success: function(data) {
//                // console.log(data);
//                   if(data.code == 200){
//                       $.each(data.data, function (i, data) {
//                           var randomX = 300;
//                           var randomY = 800;
//                           var randvalue = parseInt(Math.random() * (randomX - randomY + 1) + randomY);
//                           html+= '<li>';
//                           html+= '<a href="/house/'+data.id+'/">';
//                           html+= '<div class="sell_img"><img src="'+data.thumb+'/same" alt=""><i class="sell_img_i" style="display:none">视频</i></div>';
//                           html+= '<div class="sell_conter_right">';
//                           html+= '<p class="title">'+data.name+'</p>';
//                            html+= '<p class="jg_ing">'+data.city_name+'</p>';
//                           if(data.sale_price != 0 && data.sale_price != null && data.sale_price != ''){
//                               html+= '<p class="jg_ing jg_ingdd" style="margin-top:6px"><span><em>'+data.sale_price+'</em>'+data.price_unit+'</span></p>';
//                           }else{
//                               html+= '<p class="jg_ing jg_ingdd" style="margin-top:6px"><span><em>待定</em></span></p>';
//                           }
//                           html+= '<p class="jg_ing">有效期:'+time_mina+'</p>';
//                           html+= '<p class="jg_ing" style="display:none">80㎡(一居)、86㎡(二居)</p>';
//                           html+= '</div>';
//                           html+= '<div class="m_gzlx">';
//                           html+= '<p class="attention">已有 <span>'+randvalue+'</span> 人关注</p>';
//                           html+= '<div class="m_gzlx_style">';
//                           for(k in data.characteristic){
//                               html+=  '<i>'+data.characteristic[k]+'</i>';
//                           }
//                           html+= '</div>';
//                           html+= '</div>';
//                           html+= '</a>';
//                           html+= '<div class="cal_price"><a href="tel:'+data.tel+'"><img src="/image/search/w_t.png"></a></div>';
//                           html+= '</li>';
//                       });
//                       $(".sell_conter ul").html(html);
//                   }
//               }
//           });
//     }
//
//
// m_hotlp_hyh();




// console.log(hyh);
$('.m_hotlp_hyh').on('click',function(){ 
     // hyh = $(this).attr('DataId');
     m_hotlp_hyh(1);
})


$('.y_hotnews_bk li').on('click',function(){
    var dataid=$(this).attr('data-id');

})

 // 切换区域
 $('.y_city a').on('click',function(){
      $('#serachBox2').hide();
      $('.footer_copy').hide();
      $('.m_qhcs_box').show();
    });

    $('.m_head_qhcs .m_Return').on('click',function(){
      $('#serachBox2').show();
      $('.m_qhcs_box').hide();
      $('.footer_copy').show();
    });

 // $('.m_City_list li a').on('click',function(){
 //     var Citytext = $(this).html();
 //     $('.y_city a span').html(Citytext);
 //      $('#serachBox2').show();
 //      $('.m_qhcs_box').hide();
 //  });

 // $('.m_City_ul_li a').on('click',function(){
 //     var Citytext2 = $(this).html();
 //     $('.y_city a span').html(Citytext2);
 //      $('#serachBox2').show();
 //      $('.m_qhcs_box').hide();
 //  });



// 有效期 时间加两个自然月
function getNextMonth(date) {
    var arr = date.split('/');  
    var year = arr[0]; //获取当前日期的年份  
    var month = arr[1]; //获取当前日期的月份  
    var day = arr[2]; //获取当前日期的日  
    var days = new Date(year, month, 0);  
    days = days.getDate(); //获取当前日期中的月的天数  
    var year2 = year;  
    var month2 = parseInt(month) + 2;  
    if (month2 > 13) {  
        year2 = parseInt(year2) + 1;
        if (parseInt(month)==11) {
            month2 = 1;
        }else if (parseInt(month)==12) {
            month2 = 2;
        };
    }  
    var day2 = day;  
    var days2 = new Date(year2, month2, 0);  
    days2 = days2.getDate();  
    if (day2 > days2) {  
        day2 = days2;  
    }  
    if (month2 < 10) {  
        month2 = '0' + month2;  
    }
    var t2 = year2 + '/' + month2 + '/' + day2;  
    return t2;  
} 
var myDate = new Date;
var year = myDate.getFullYear(); //获取当前时间年份
var yue = myDate.getMonth()+1;//获取当前时间月份
if (yue<10) {
    yue= '0' + yue; 
};
// 有效期时间 获取当前时间
var time = year+'/'+yue+'/01';
var time_mina= time+'-'+getNextMonth(time);
var getNextMonth= getNextMonth(time);

// $('.sell_conter_right .date').html('有效期 | '+ time_mina);


	 //限制字符个数
	$(".y_style1_text .y_title").each(function(){
	        var maxwidth=35;
	        if($(this).text().length>maxwidth){ $(this).text($(this).text().substring(0,maxwidth)); $(this).html($(this).html()+'…');
	        }
	});

$('.m_region span').eq(1).click();
$('.m_City_box[data-id="1"]').show();
$('.m_region span').on('click',function(){

   var dataid = $(this).attr('data-id');
   $('.m_City_box').hide()
   $('.m_City_box[data-id="'+dataid+'"]').show();

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

})