//列表
function indexList(){
	loading = true;
	var param = {};
	param.currPage = Number( $('#currPage').val() ) + 1;
	$('#goods-list').append('<div class="wst-loading" id="loading"><span class="icon">&nbsp<i class="ui-loading"></i></span><span>加载中</span></div>');
    $.post(WST.U('mobile/index/pageQuery'), param,function(data){
        var json = WST.toJson(data);
        if(json && json.catId){
	        $('#currPage').val(json.currPage);
            var gettpl = document.getElementById('list').innerHTML;
            laytpl(gettpl).render(json, function(html){
                $('#goods-list').append(html);
            });
            goodsWH();
            echo.init();
            $('#loading').remove();
	        WST.imgAdapt('j-imgAdapt');
	        loading = false;
        }else{
        	$('#loading').remove();
        	$('#goods-list').append('<div class="wst-loading" id="loading">已加载完毕</div>');
        }
    });
}
function goodsWH(){
	var goodsw = $('.wst-in-goods').width();
	var goodsh = goodsw*13/9;
	$('.swiper2').css('height',goodsh);
}

var currPage = 0;
var loading = false;
$(document).ready(function(){
	WST.initFooter('home');
	//搜索
    $(window).scroll(function(){
        if( $(window).scrollTop() > 42 ){
            $('#j-header').addClass('active');
            $('#j-searchs').addClass('active');
        }else{
        	$('#j-header').removeClass('active');
        	$('#j-searchs').removeClass('active');
        }
    });
	$('.wst-in-search').on('submit', '.input-form', function(event){
	    event.preventDefault();
	})
	//广告
    new Swiper('.banner', {
        autoplay: true,
        autoHeight: true, //高度随内容变化
        width: window.innerWidth,
        on: {
            resize: function(){
                this.params.width = window.innerWidth;
                this.update();
            },
        } ,
        pagination: {
            el: '.swiper-pagination',
            type: 'bullets',
        },
    });
	//文章
	if($('.wst-in-news a').hasClass("words")){
        new Swiper('.swiper-container1', {
            autoplay: true,
            autoHeight: true, //高度随内容变化
            width: window.innerWidth,
            on: {
                resize: function(){
                    this.params.width = window.innerWidth;
                    this.update();
                }
            }
        });
	}
    //中间广告
    if($('.wst-in-adst a').hasClass("advert2")){
    }else{
    	$('.wst-in-adst').hide();
    }
	goodsWH();
	//刷新
	indexList();

    $(window).scroll(function(){
        if (loading) return;
        if (5 + ($(window).scrollTop()) >= ($(document).height() - $(window).height())) {
            currPage = Number( $('#currPage').val() );
            if(currPage < 10 ){
                indexList();
            }
        }
    });
});