// 头部搜索 ----------------------------------------
$('.seekinput_search span').on('mousemove', function () {     //显示切换框
    $('.seekinput_option').show();
})

$('.seek_box').on('mouseleave', function () {   //隐藏切换框
    $('.seekinput_option').hide();
})

$('.seekinput_option span').eq(1).attr('class', 'on');  //默认
$('.seekinput_search input[qhid="2"]').show();  //默认

$('.seekinput_option span').on('click', function () {

    $('.seekinput_search input[type="text"]').hide();
    var _html = $(this).html();
    $('.seekinput_search span i').html(_html);
    $('.seekinput_option').hide();

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


    var _qhid = $(this).attr('qhid');

    $('.seekinput_search input[qhid="' + _qhid + '"]').show();       //选中的搜索输入框
    $('.seek_input input[type="button"]').attr('buttonid', _qhid);  //选中的 类型 1为 楼盘列表   2为 视频列表

    $('.seekinput_search input[type="text"]').val("");   //清空input 内容
})


$('.seek_input input[type="button"]').on('click', function () {     //搜索跳转操作

    var _buttonid = $(this).attr('buttonid');

    var txt = $('.seek_input input[qhid="' + _buttonid + '"]').val();
    console.log(_buttonid);
    console.log(txt);
    if (txt != '') {

        switch (_buttonid) {
            case '1':
                window.open('/house/search?name=' + txt);
                break;
            case '2':
                window.open('/video/videosearch?name=' + txt);
                break;
        }

    }
    ;

})

$(document).keydown(function (event) {
    if (event.keyCode == 13) {
        $('.seek_input input[type="button"]').click();
    }
});


// 头部搜索 ----------------------------------------


// 视频看房 ------------------------------------------------------
var videoid = $('.m_videolist_dh .videoclick').eq(0).attr('videoid');

$('.m_videolist_dh .videoclick').eq(0).addClass('on');

ajax_qy();

var being = true;

$('.m_videolist_dh .videoclick').on('mouseover', function () {

    if (videoid != $(this).attr('videoid')) {
        being = true;
    }

    videoid = $(this).attr('videoid');

    if (being == true) {
        ajax_qy();
        being = false;
    }

    $(this).addClass('on').siblings().removeClass('on');


    $('.videolist_option p').removeClass('on');
})

$('.videolist_option p').on('mouseover', function () {

    if (videoid != $(this).attr('videoid')) {
        being = true;
    }

    videoid = $(this).attr('videoid');

    if (being == true) {
        ajax_qy();
        being = false;
    }

    $(this).addClass('on').siblings().removeClass('on');

    $('.m_videolist_dh .videoclick').removeClass('on');
})


$('.gdclick').on('mousemove', function () {
    $('.videolist_option').show();
})
$('.gdclick').on('mouseleave', function () {
    $('.videolist_option').hide();
})

function ajax_qy() {

    var html = '';
    $.ajax({
        url: "/video/videolisthouse",  // 索取
        data: {city: videoid},  //传ID
        type: "GET",
        dataType: "json",
        success: function (data) {//请求成功完成后要执行的方法
            var style = $('.m_videolistdata').attr('style');

            if (data.code == 200) {

                $.each(data.data, function (i, data) {

                    html += '<li>';
                    html += '<a target="_blank" href="/video/videodetails/' + data.id + '">';
                    html += '<div class="m_videolist_img">';
                    html += '<img class="img" src="' + data.thumb + '" alt="">';
                    html += '<i class="type">' + data.type + '</i>';
                    html += '<img class="imgtb" src="./image/videolist_5.png" alt="">';
                    html += '<div class="text_box">';
                    html += '<div class="text">';
                    html += '<p class="Price">约¥' + data.price + '' + data.price_nuit + '</p>';
                    html += '<p class="sj">' + '(有效期:' + data.time + ')' + '</p>';
                    html += '<i class="region"><img src="./image/videolist_6.png" alt="">' + data.city_name + '</i>';
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                    html += '<div class="m_videolist_text">';
                    html += '<em>' + data.name + '</em>';
                    html += '<p>';
                    html += '<span>' + data.main_units + '</span>';
                    html += '<i>|</i>';
                    html += '<span style="' + style + '">参考收益 ' + data.rent.proportion + '</span>';
                    html += '</p>';
                    html += '</div>';
                    html += '</a>';
                    html += '</li> ';

                });


            }


            $('.m_videolist ul').html(html);

            var _length = data.data.length;

            if (_length > 6) {
                $('.m_videolist').addClass('on');
            } else {
                $('.m_videolist').removeClass('on');
            }

        }
    });

}// 视频看房 ------------------------------------------------------


// 玩转海外 ------------------------------------------------------
var _overseasid = $('.m_overseasdh .overseasdhclick').eq(0).attr('overseasid');

$('.m_overseasdh .overseasdhclick').eq(0).addClass('on');

ajax_overseas();

var mbeing = true;

$('.m_overseasdh .overseasdhclick').on('mouseover', function () {

    if (_overseasid != $(this).attr('overseasid')) {
        mbeing = true;
    }

    _overseasid = $(this).attr('overseasid');

    if (mbeing == true) {
        ajax_overseas();
        mbeing = false;
    }

    $(this).addClass('on').siblings().removeClass('on');


    $('.overseasdh_option p').removeClass('on');
})

$('.overseasdh_option p').on('mouseover', function () {

    if (_overseasid != $(this).attr('overseasid')) {
        mbeing = true;
    }

    _overseasid = $(this).attr('overseasid');

    if (mbeing == true) {
        ajax_overseas();
        mbeing = false;
    }

    $(this).addClass('on').siblings().removeClass('on');

    $('.m_overseasdh .overseasdhclick').removeClass('on');
})


$('.overseasdgj').on('mousemove', function () {
    $('.overseasdh_option').show();
})
$('.overseasdgj').on('mouseleave', function () {
    $('.overseasdh_option').hide();
})

function ajax_overseas() {

    var html = '';
    $.ajax({
        url: "/video/videolistbottom",  // 索取
        data: {city: _overseasid},  //传ID
        type: "GET",
        dataType: "json",
        success: function (data) {//请求成功完成后要执行的方法

            if (data.code == 200) {

                $.each(data.data, function (i, data) {

                    html += '<li>';
                    html += '<a target="_blank" href="/video/relevantvideo/' + data.id + '">';
                    html += '<img src="' + data.thumb + '" alt="">';
                    html += '<p>';
                    html += '<span>' + data.title + '</span>';
                    html += '</p>';
                    html += '</a>';
                    html += '</li>';

                });


            }


            $('.m_overseas ul').html(html);


        }
    });

}// 玩转海外 ------------------------------------------------------


// 直播看房 -------------------------------------------------------
$(function () {
    var daId = $('.live_nav span').eq(0).attr('data-id')
    var daName = $('.live_nav span').eq(0).attr('data-name')
    $('.live_nav span').eq(0).addClass('on');
    liveajax(daId);
    $('.live_nav').on('click', 'span', function () {
        $(this).addClass('on').siblings().removeClass('on');
        daId = $(this).attr('data-id');
        daName = $(this).attr('data-name');
        liveajax(daId);
    })

    function liveajax(id) {
        var html = '';
        $.ajax({
            url: "/video/livelist",  // 索取
            data: {name: id},  //传ID
            type: "GET",
            dataType: "json",
            success: function (data) {//请求成功完成后要执行的方法
                if (data.code == 200) {
                    $('.main_li ul').html('');
                    $.each(data.data, function (i, data) {
                        switch (data.type) {
                            case 'all':
                                // if(id){
                                // 	html+=  '<li class="swiper-slide ">';
                                // 	html+=  '<div class="pule_list m_live">';
                                // 	html+=  '<a href="">';
                                // 	html+=  '<div class="top_tu">';
                                // 	html+=  '<div class="text-left">';
                                // 	html+=  '<i></i>';
                                // 	html+=  '<span>直播中</span>';
                                // 	html+=  '<em>20:36</em>';
                                // 	html+=  '</div>';
                                // 	html+=  '<p class="bg_img"><img src="/video/image/videolist_4.png" alt=""></p>';
                                // 	html+=  '</div>';
                                // 	html+=  '<div class="bottom_text">';
                                // 	html+=  '<p class="title_m">1帕丁顿商业广场——马尼拉价丁顿商业广场</p>';
                                // 	html+=  '<p class="text_m c">';
                                // 	html+=  '<span class="fl"><i><img src="/video/image/xm_tb16.png" alt=""></i><em>海南 文昌</em></span>';
                                // 	html+=  '<span class="fr"><i><img src="/video/image/xm_tb17.png" alt=""></i><em>156万</em></span>';
                                // 	html+=  '</p>';
                                // 	html+=  '</div>';
                                // 	html+=  '</a>';
                                // 	html+=  '</div>';
                                // 	html+=  '</li>';
                                // }else
                                if (data.livestate === '回放') {
                                    html += '<li class="swiper-slide">';
                                    html += '<div class="pule_list playback">';
                                    html += '<a href="/video/videodetails/' + data.hid + '?type=live&liveid=' + data.id + '">';
                                    html += '<div class="top_tu">';
                                    html += '<div class="text-left">';
                                    html += '<i></i>';
                                    html += '<span>回放</span>';
                                    html += '<em></em>';
                                    html += '</div>';
                                    html += '<p class="pl_img"><img src="/video/image/xm_tb18.png" alt=""></p>';
                                    html += '<p class="bg_img"><img src="' + data.img + '" alt=""></p>';
                                    html += '</div>';
                                    html += '<div class="bottom_text">';
                                    html += '<p class="title_m">' + data.title + '</p>';
                                    html += '<p class="text_m c">';
                                    html += '<span class="fl"><i><img src="/video/image/xm_tb16.png" alt=""></i><em>' + data.parentCity + ' ' + data.city_name + '</em></span>';
                                    // html+=  '<span class="fr"><i><img src="/video/image/xm_tb17.png" alt=""></i><em>156万</em></span>';
                                    html += '</p>';
                                    html += '</div>';
                                    html += '</a>';
                                    html += '</div>';
                                    html += '</li>';
                                } else if (data.livestate === '预告') {
                                    html += '<li class="swiper-slide">';
                                    html += '<div class="pule_list advance">';
                                    html += '<div class="top_tu">';
                                    html += '<a href="javascript:;" class="live_buttom" data-hid="'+data.hid+'">';
                                    html += '<div class="text-left">';
                                    html += '<i></i>';
                                    html += '<span>预告</span>';
                                    html += '<em>' + data.time + '开播</em>';
                                    html += '</div>';
                                    html += '<p class="pl_img">预约</p>';
                                    html += '<p class="bg_img"><img src="' + data.img + '" alt=""></p>';
                                    html += '</a>';
                                    html += '</div>';
                                    html += '<div class="bottom_text">';
                                    html += '<p class="title_m">' + data.title + '</p>';
                                    html += '<p class="text_m c">';
                                    html += '<span class="fl"><i><img src="/video/image/xm_tb16.png" alt=""></i><em>' + data.parentCity + ' ' + data.city_name + '</em></span>';
                                    // html+=  '<span class="fr"><i><img src="/video/image/xm_tb17.png" alt=""></i><em>156万</em></span>';
                                    html += '</p>';
                                    html += '</div>';
                                    html += '</div>';
                                    html += '</li>';
                                }
                                break;
                            case 'advance':
                                html += '<li class="swiper-slide">';
                                html += '<div class="pule_list advance">';
                                html += '<div class="top_tu">';
                                html += '<a href="javascript:;" class="live_buttom" data-hid="'+data.hid+'">';
                                html += '<div class="text-left">';
                                html += '<i></i>';
                                html += '<span>预告</span>';
                                html += '<em>' + data.time + '开播</em>';
                                html += '</div>';
                                html += '<p class="pl_img">预约</p>';
                                html += '<p class="bg_img"><img src="' + data.img + '" alt=""></p>';
                                html += '</a>';
                                html += '</div>';
                                html += '<div class="bottom_text">';
                                html += '<p class="title_m">' + data.title + '</p>';
                                html += '<p class="text_m c">';
                                html += '<span class="fl"><i><img src="/video/image/xm_tb16.png" alt=""></i><em>' + data.parentCity + ' ' + data.city_name + '</em></span>';
                                // html+=  '<span class="fr"><i><img src="/video/image/xm_tb17.png" alt=""></i><em>156万</em></span>';
                                html += '</p>';
                                html += '</div>';
                                html += '</div>';
                                html += '</li>';
                                break;
                        }
                    });
                }
                $('.main_li ul').html(html);

                if (data.data.length > 4) {
                    var mySwiper1 = new Swiper('.main_li', {
                        autoplay: 6000,	//自动切换
                        loop: false,	//循环
                        slidesPerView: 4,
                        observer: true,
                        spaceBetween: 23,
                        prevButton: '.swiper-button-prev',
                        nextButton: '.swiper-button-next',
                    })
                } else {

                    var mySwiper1 = new Swiper('.main_li', {
                        autoplay: false,	//自动切换
                        loop: false,	//循环
                        observer: true,
                        slidesPerView: 4,
                        spaceBetween: 23,
                    })
                }
            }
        });
    }


    // 报名
    $('body').on('click', '.live_buttom', function () {
        var  _hid=$(this).attr('data-hid');
        $('.liveBm_box input[name="hid"]').val(_hid)
        $('.liveBm').show(30);
        $('.liveBm_bg').show();
    })

    $('.liveBm_bg,.liveBm_gb a').on('click', function () {
        $('.liveBm').hide();
        $('.liveBm_bg').hide();
        $('.liveBm_box input[type="text"]').val('')
    })

    //报名验证提交的调用 底下报名
    PublicAction.AjaxSend({CORID: 'ybm_buttom'/*操作ID*/});
    $('.submit_area .ybm_buttom').on('click', function () {
        setTimeout(function () {
            var _html = $('.alert-container .alert-content').html();
            if (_html == '提交成功') {
                $('.liveBm').hide();
                $('.liveBm_bg').hide();
                $('.liveBm_box input[type="text"]').val('');
            }
        }, 1500)

    })

})