// Generated by CoffeeScript 1.8.0
(function() {
	stopBubble=function(e){
		 if ( e && e.stopPropagation ) 
			    e.stopPropagation(); 
			     else 
			    window.event.cancelBubble = true; 
	};
	
  var loadData;

  loadData = function() {
    var convert, item, swp, top;
    top = '';
    item = $("#itemTpl")[0].innerHTML;
    swp = new $.compent.swiper("#meetList", {
      tpl: item,
      refreshEnabled: false
    });
    convert = {
      status: function(val) {
        return val === 4 || val === 3 && 'cancle';
      }
    };
    swp.convert(convert);
    swp.dataSource = function(pageIndex, s, opt) {
      return Ajax({
        url: baseUrl + '/api/meeting/list.do',
        data: {
          pageIndex: pageIndex
        },
        type: 'get',
        callback: function(res) {
        	$.each(res.datas,function(idx,item){
				if(item.mthumbnail===null||item.mthumbnail===""||item.mthumbnail===undefined){
					item.mthumbnail="../../static/images/nopic.png";
				}else{
					item.mthumbnail = item.mthumbnail
				}
      	    });
        	
        	if(pageIndex>1&&res.datas.length===0){
	  			  var a = $(".swiper-wrapper").children('div:last-child');
	  				a.after("<div class=\"swiper-slide\" style=\"height:23px\"></div>");
	  		  }
            swp.dataList(res.datas);
            
          //查看收藏
            $.ajax({
        		url:baseUrl+'/api/user/get_collect.do',
        		type:'post',
        		data:{favoriteType:3,flag:false},
        		success:function(data){
        			if(data.status==200){
        				var collect=data.datas;
        				if(collect!=undefined&&collect!=null){
        					for(i=0;i<collect.length;i++){
        						$("#collect"+collect[i].relationId).addClass("cancle");
        					}
        				}
        			}
        		}
        	});
        },
        error: function(res) {
          opt['timeStatu'] = res.status;
          return swp.timeOut();
        }
      });
    };
    return swp.initData();
  };

  $(function() {
    $('.toast').hide();
    loadData();
   /* $("#usercenter").on("tap",function(){
    	var _id=$.cookie('_id');
    	if(_id!=null){
    		return $.ajax({
    				url:baseUrl+'/api/user/get_user_info.do',
    				type:"post",
    				success:function(data){
    				    if(data.status===311){	
    				    	return location.href="../user/login.html";
    				    }else if(data.data.userinfo.role===1&&data.data.userinfo.isVerify===1){
    				    	return location.href="../user/userCenter.html";
    				    }else {
    				    	return location.href="../user/index.html";
    				    	}
    					}
    		});
    	}else{
    		location.href="../user/login.html";
    	}
    });*/
    $(document).on("click", ".item", function() {
    	var exurl = $(this).data("exurl");
    	if (exurl == undefined || exurl == '' || exurl == null) {
    		exurl = "./detail.html?meetingId=" + $(this).data("id");
    	}
    	return location.href = exurl;
    });
    $(document).on("click", ".collect", function(e) {
    	stopBubble(e);
   	 var meetingId = $(this).data("id");
   	 if(!$('#collect'+meetingId).hasClass("cancle")){
   		 $.ajax({
			    	url:baseUrl+'/api/user/collect.do',
			    	data:{
			    		favoriteType:3,
			    		relationId:meetingId,
			    		orginUri:location.href,
			    		thumbnail:"../../static/images/meet_collect.jpg"
			    	},
				    success:function(data){
				    	if(data.status===311){	
				    	   localStorage.clear();	
				    	   localStorage.setItem("meetingId", meetingId);
				    	   return location.href="../user/login.html";
				    	}else if(data.status===200){
				    		$('#collect'+meetingId).addClass("cancle");
				        }else{
				        	wrongMsg(data.message);
				        }
				  }
		    	});
   	 }else{
   		 $.ajax({
			    	url:baseUrl+'/api/user/cancel_collect.do',
			    	data:{
			    		favoriteType:3,
			    		relationId:meetingId
			    	},	 	    				    
				    success:function(data){
				    	if(data.status===311){	
				    	   localStorage.clear();	
				    	   localStorage.setItem("meetingId", meetingId);
				    	   return location.href="../user/login.html";
				    	}else if(data.status===200){
				    		$('#collect'+meetingId).removeClass("cancle");
				        }else{
				        	wrongMsg(data.message);
				        }
				  }
		    	});
		    	
		}
   	
   });
  });

}).call(this);
