//微信分享的简介与用户名称
var wx_share_title = "金客-指尖财富管理专家";
var wx_share_description = "高净值客户与金融人士的专业平台";
// Generated by CoffeeScript 1.8.0
(function() {
  var drawCircle, drawProcess, loadData;

  drawCircle = function(e, radil, process, color) {
    if (radil == null) {
      radil = 30;
    }
    if (process == null) {
      process = "0";
    }
    if (color == null) {
      color = "red";
    }
    e.beginPath();
    e.moveTo(30, 30);
    //e.arc(30, 30, radil, 0, Math.PI * 2 * process / 100, false);
    if (process != 100) {
    	var _p = process / 100;
	    var _percent = _p >= 0.25 ? Math.PI * 2 * _p - Math.PI * 0.5 : 1.5*Math.PI + Math.PI * 2 * _p; 
	    e.arc(30, 30, radil, 1.5*Math.PI, _percent, false);
    } else {
    	e.arc(30, 30, radil, 0, Math.PI * 2, false);
    }
    e.closePath();
    e.fillStyle = color;
    return e.fill();
  };

  drawProcess = function(process1, process2) {
    if (process1 == null) {
      process1 = "90";
    }
    if (process2 == null) {
      process2 = "70";
    }
    return $("#productList canvas").each(function() {
      var context, proce;
      proce = $(this).data("proce");
      context = this.getContext("2d");
      //context.shadowColor = "#fff";
      //context.shadowBlur = 5;
      //context.mozImageSmoothingEnabled = false;
      context.clearRect(0, 0, 30, 30);
      drawCircle(context, 30, 100, "#d2d4d8");
      drawCircle(context, 30, proce, "#D6AD3D");
      drawCircle(context, 26, 100, "#FFF");
      context.font = "bold 10pt Arial";
      context.fillStyle = '#D6AD3D';
      context.textAlign = 'center';
      context.textBaseline = 'middle';
      return context.fillText(proce + "%", 30, 30);
    });
  };

  loadData = function() {
	var _id = $.cookie("_id");
	if (_id != null) {
		$("#usercenter").attr("src", "../../static/images/userlogined.png");
	}
    var item, swp, top,rnd;
    rnd = Math.random(100);
    item = $("#itemTpl")[0].innerHTML;
    top = "<div class=\"swiper-container\" id=\"banner\">\n	<div class=\"swiper-wrapper\">\n		<div class=\"swiper-slide\">\n			<a href=\"../user/applypartner.html\"><div class=\"img\" style=\"background-image: url('../../static/images/ad_1.jpg');\"></div></a>\n		</div>\n		<div class=\"swiper-slide\">\n			<a href=\"../user/applypartner.html\"><div class=\"img\" style=\"background-image: url('../../static/images/ad_2.jpg');\"></div></a>\n		</div>\n		<div class=\"swiper-slide\">\n			<a href=\"../user/applypartner.html\"><div class=\"img\" style=\"background-image: url('../../static/images/ad_3.jpg');\"></div></a>\n		</div>\n	</div>\n	<div class=\"pagination\"></div> \n</div>\n " ;
    var temp="<div style=\"height:3px\"><span style=\"float: left;\"></span></div>";
    top+=temp;
    swp = new $.compent.swiper("#productList", {
      tpl: item,
      refreshEnabled: false,
      topHtml: top
    });
    
    swp.convert();
    swp.dataSource = function(pageIndex, s, opt) {
      return Ajax({
        url: baseUrl + '/api/product/list.do',
        data: {
          page: pageIndex,
          rnd:rnd
        },
        callback: function(res) {
			$.each(res.datas,function(idx,item){
      		  if(item.appointmentPercent<=0||item.appointmentPercent==""||item.appointmentPercent==null){
      			item.appointmentPercent="0";
      		  }
      		  if (parseInt(item.appointmentPercent) > 100) {
      			item.appointmentPercent = "100";
      		  }

      		  if(item.status===1){
      			item.statusName="热销";
      		  } else {
      			  item.statusName="售罄"; 
      			  item.appointmentPercent = "100";
      			  item.status = "0";
      		  }
      		  item.brightPoint = item.brightPoint.replace("  "," ").replace(" ", "<br/>");
      	    });
//          var banner;
          
          swp.dataList(res.datas);
          drawProcess("69", "87");
//          return banner = new Swiper("#banner", {
//            	loop: true,
//                autoplay: 5e3,
//                speed: 1e3,
//                pagination: '.pagination',
//                paginationClickable: true
//              });
          if(document.getElementById("jsfoot02")){
        		var scrollup = new ScrollText("jsfoot02");
        		scrollup.LineHeight = 22;        //单排文字滚动的高度
        		scrollup.Amount = 1;            //注意:子模块(LineHeight)一定要能整除Amount.
        		scrollup.Delay = 20;           //延时
        		scrollup.Start();             //文字自动滚动
        		scrollup.Direction = "up";   //默认设置为文字向上滚动
        	}
        },
        error: function(res) {
          opt['timeStatu'] = res.status;
          return swp.timeOut();
        }
      });
    };
    return swp.initData();
  };
  getBanner = function(){
	  var banner;
	  return banner = new Swiper("#banner", {
      	loop: true,
          autoplay: 5e3,
          speed: 1e3,
          pagination: '.pagination',
          paginationClickable: true
        });
  };

  $(function() {
	  $(document).on("click", ".item", function() {
	  return location.href = "./product.html?id=" + $(this).data("id");
	});
    loadData();
    setTimeout(function(){
    	getBanner();
    },500);
    
    
    /*$("#usercenter").on("click",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";
    	}
    });*/
    return $("#bottom>div").click(function() {
      return $(this).addClass("active").siblings().removeClass("active");
    });
  });
  
  $(function() {
	    var cur_index;
	    var appId='wxa0eadefda1950ee0';
	    var timestamp;
	    var nonceStr;
	    var signature;
	    var uri=location.href;
	    var id=GetQueryString("id");
	    var uid=$.cookie("_id");
	    $.ajax({
	    	url: baseUrl+"/api/product/wx.do",
	    	data: {
	    		url: uri
	    	},
	    	success:function(data){
	    		var wxs=data.data.url;
	    		timestamp=wxs.timeStamp;
	    		nonceStr=wxs.nonceStr;
	    		signature=wxs.signature;
	    		wx.config({
	    	        debug: false,

	    	        appId: appId,
	    	        timestamp: timestamp,
	    	        nonceStr: nonceStr,
	    	        signature: signature,

	    	        jsApiList: [
	    	          'checkJsApi',
	    	          'onMenuShareTimeline',
	    	          'onMenuShareQQ',
	    	          'onMenuShareAppMessage',
	    	        ]
	    	    });
	    		wx.ready(function(){

	    		    wx.checkJsApi({
	    		      jsApiList: [
	    		          'onMenuShareTimeline',
	    				  'onMenuShareQQ',
	    				  'onMenuShareAppMessage'
	    		      ],
	    		      success: function (res) {
	    		      }
	    		    });
	    		    wx.onMenuShareTimeline({
	    			      title: wx_share_title,
	    			      desc: wx_share_description, 
	    			      link: "http://m.tao798.com/api/product/index.html" ,

	    			      imgUrl: 'http://m.tao798.com/static/images/jinke_logo.jpg',
	    			      trigger: function (res) {
	    			      },
	    			    
	    			      success: function (res) {
	    			      },
	    			      cancel: function (res) {
	    			      }
	    			    });
	    		    /*
	    		    wx.onMenuShareQQ({
	    			      title: wx_share_title,
	    			      desc: wx_share_description, 
	    			      link: "http://m.tao798.com/api/product/index.html" ,
	    			      imgUrl: 'http://m.tao798.com/static/images/jinke_logo.png',			      
	    			      complete: function (res) {
	    			        alert(JSON.stringify(res));
	    			      },
	    			      success: function (res) {
	    			      },
	    			      cancel: function (res) {
	    			      }
	    			    });
	    			    */
	    		    wx.onMenuShareAppMessage({
	    		        title: wx_share_title, // 分享标题
	    		        desc: wx_share_description, 
	    		        link: "http://m.tao798.com/api/product/index.html", // 分享链接
	    		        imgUrl: 'http://m.tao798.com/static/images/jinke_logo.jpg', // 分享图标
	    		        success: function () { 
	    		        },
	    		        cancel: function () { 
	    		        }
	    		    });
	    	});
	    	}
	    });
    });
}).call(this);
