// Generated by CoffeeScript 1.8.0
var tab;
var endPage;
(function() {
  var bestLoadData, moreLoadData;

  moreLoadData = function(_tab,_endPage) {
    var item,swp;
    /*
    if(_tab===undefined&&_endPage===undefined){
    	_tab = 0;
    	_endPage = 0;
    }
    */
    item = $("#moreListTpl")[0].innerHTML;
    swp = new $.compent.swiper("#moreList", {
      tpl: item,
      refreshEnabled: false,
      noDataTpl: ""
    });
    swp.dataSource = function(pageIndex, s, opt) {
      return Ajax({
        url: baseUrl + '/api/news/list.do',
        data: {
          pageIndex: pageIndex,
          newsType:1126
        },
        type: 'get',
        callback: function(obj) {
        	$.each(obj.datas,function(idx,item){
        		item.pubTime = item.pubTime.substr(5,6);
				if(item.mthumbnail===null||item.mthumbnail===""||item.mthumbnail===undefined){
					item.mthumbnail="../../static/images/news_b.jpg";
				}else{
					item.mthumbnail = item.mthumbnail
				}
				if(item.newsTypeName==null||item.newsTypeName==""||item.newsTypeName===undefined){
					item.newsTypeName=="宽客财富";
				}
      	    });
        	endPage = pageIndex;
          return swp.dataList(obj.datas);
        },
        error: function(res) {
          opt.timeStatu = res.status;
          return swp.timeOut();
        }
      });
    };
    return swp.initData();
  };

  bestLoadData = function(_tab,_endPage) {
    var item, swp;
    /*
    if(_tab===undefined&&_endPage===undefined){
    	_tab = 0;
    	_endPage = 0;
    }
    */
    item = $("#bestListTpl")[0].innerHTML;
    swp = new $.compent.swiper("#bestList", {
      tpl: item,
      refreshEnabled: false,
      noDataTpl: ""
    });
    swp.dataSource = function(pageIndex, s, opt) {
      return Ajax({
        url: baseUrl + '/api/news/list.do',
        data: {
          pageIndex: pageIndex,
          newsType:1126,
          rmd:1
        },
        type: 'get',
        callback: function(obj) {
        	$.each(obj.datas,function(idx,item){
        		item.pubTime = item.pubTime.substr(5,6);
				if(item.mthumbnail===null||item.mthumbnail===""||item.mthumbnail===undefined){
					
				}else{
					item.mthumbnail = item.mthumbnail
				}
				if(item.newsTypeName===null||item.newsTypeName===""||item.newsTypeName===undefined){
					item.newsTypeName="宽客财富";
				}
      	    });
        	endPage = pageIndex;
          return swp.dataList(obj.datas);
        },
        error: function(res) {
          opt.timeStatu = res.status;
          return swp.timeOut();
        }
      });
    };
    return swp.initData();
  };
  /*
  changeTab = function(){
	$("#best").removeClass("active");
  	$("#more").addClass("active");
  	console.log(swp.initialSlide);
  	$(".swiper-wrapper").attr("width","auto");
  	$(".swiper-wrapper").attr("height","auto");
  	swp.initialSlide=6;
  	$(".content>div").eq(1).show();
  	$(".content>div").eq(0).hide();
  	$("#tab_best_content").css("width","");
  };
  */

  $(function() {
    $(".toast").hide();
    // tab = GetQueryString("tab");
    // endPage = GetQueryString("endPage");
    // active = GetQueryString("active");
    // if(tab==null&&endPage==null){
    	//moreLoadData();
        //bestLoadData();
        //	tab=1;
    	//	endPage=1;
    	// }else{
    	// 	moreLoadData(tab,endPage);
    	//   bestLoadData(tab,endPage);
        // }
    // if(tab==2){
    	//  	changeTab();
   // }
    $(document).on("click", ".item", function() {
    	console.log($(".item").index());
    	  return location.href = "./newsInfo.html?newsId=" + $(this).data("id");
    	  //+"&tab=" + tab + "&endPage=" + endPage + "&active=" + $(this).index()
    	});

    return $(".hd-btn-group a").click(function() {
      $(this).addClass("active").siblings().removeClass("active");
      $(".content>div").eq($(this).index()).show().siblings().hide();
      if(typeof($(".tab_best").attr("style"))=="object"){
    	  tab = 1;
      }
      if(typeof($(".tab_more").attr("style"))=="object"){
    	  tab = 2;
      }
    });
  });

}).call(this);
