// 轮播图
$(document).ready(function() {
	$("#owl-demo").owlCarousel({
		autoPlay: 3000,
		navigation : true,
		slideSpeed : 300,
		paginationSpeed : 400,
		singleItem : true
	});
	
	$('#marquee5').kxbdSuperMarquee({
		isEqual:false,
		distance:40,
		time:3,
		direction:'up'
	});

	/*
	*商品列表页筛选
	*/
	  $('#m360BtnClass').click(function(){
		  $('body').css('overflow','hidden');
		  $('#m360_leftNav').show();
		  $('#m360_leftNav_t').show().animate({'right':0},200,function(){
			  setNavHeight();
		  });			
		  return false;
	  });		   
	  $('#m360_leftNavBg').click(function(){
		  $('body').css('overflow','auto');
		  $('#m360_leftNav_t').animate({'right':-280},200,function(){
			  $('#m360_leftNav').hide();														 
		  });
		  return false;									
	  });
	  $('#m360_leftNav_list > li').click(function(event){
		  var _this = $(this);										
		  var ul = $(this).find('ul');
		  if( _this.hasClass('hover'))
		  {
			  ul.slideUp( 200,function(){
				  _this.removeClass('hover');						
			  });	
		  }else{
			  _this.addClass('hover');
			  ul.slideDown( 200);	
		  }	
		  //需要判断高度
		  setNavHeight();
		  event.stopPropagation();
	  });
	  //m360_pages_select
	  $('select.m360_pages_select').change(function(){
		  var x = $(this).val();
		  window.location.href = x;
	  });
	  /*筛选的收缩伸展*/
		$(".click").click(function(){
			var t_class=$(this).attr('class');
			if(t_class == "click icon-down_arrow"){
				$(this).addClass("cur");
				$(this).parent().next().addClass("hAuto");
			}else{
				$(this).removeClass("cur");
				$(this).parent().next().removeClass("hAuto");
				}	
		})
		

	
	$('#list-sub-products dl dd a').click(function(){
        changethis($(this));
    });
    function changethis(obj){
        $(obj).siblings().removeClass('on');
        if($(obj).hasClass('on')){
            $(obj).removeClass('on');
        }else{
            $(obj).addClass('on');
        }
    }
	/**/
  });
/*关闭属性框*/
function claseattr(){
	$('.buy-popup').next().fadeOut();
	$('.buy-popup').animate({"bottom": "-100%"});
	$('body').css("overflow","");
}
// 选择属性
function attr(id,img,name,price){
	$('#popup-mian').html('');
	var query = new Object();
	query.goodsid = id;
	query.img = img;
	query.name = name;
	query.price = price;
	$.ajax({
		type: "POST",
		url: APP + "Mobile/PurIndex/attr.html",
		data: query,
		success: function(data) {
			if(data.status==1){
				$('#popup-mian').html(data.html);
				combination = data.combination;//属性组合方式
				combinationnum = data.combinationnum;//属性组合数量
				combinationprice = data.combinationprice;//拼接属性价格库存
				combinationpricenum = data.combinationpricenum;//拼接属性价格库存数量
				$('#popup-mian').next().fadeIn();
				$('#popup-mian').animate({"bottom": 0});	
				$('.buy-popup').show();
				$('body').css("overflow","hidden");
			}else if(data.status==2){
				num(id,'+',name);
			}else{
				$.showErr(data.msg,1,'hc');
			}
		}
	})
}
/**
**改变购物车数量
**/
function num(goodsid,k,name){
	var moq = parseInt($('#moq'+goodsid).val());
	var num = parseFloat($('#number'+goodsid).html());
	var packid = parseInt($('#pack_id'+goodsid).val());
	
	switch(k){
		case "+":
			if(num > 0){
				num = num+1;
			}else{
				num = moq;
			}
			break;
		case "-":
			if(num !==1 && num > moq){
				num = num - 1;
			}else if(num==1){
				num = 0;
				// $('#item_num'+goodsid).addClass('hide');
				// $('#remove_item'+goodsid).addClass('hide');
			}else{
				$.showErr('起订量不得低于'+moq,0,'hc');return false;
			}
			break;
	}
	var query = new Object();
	query.goodsid = goodsid;
	query.number = num;
	query.name = name;
	query.pack_id = packid;
	$.ajax({
        type:"POST",
        url:APP + "Mobile/PurIndex/add_cartlist",
        data:query,
        success:function(data){
            if(data.status==1) {
				$.showErr(data.msg,0,'hc');
            }else if(data.status==2){
            	if(k=='+' && num >0){
            		// $.showSuccess(data.msg,0,'hc');
            		$('#item_num'+goodsid).removeClass('hide');
					$('#remove_item'+goodsid).removeClass('hide');
            	}
				$('#number'+goodsid).html(num);
            }else{
                $.showErr(data.msg, 0, 'hc', function () {
                    window.location.href = data.url;
                });
            }
        }
    })
}

/**
 * 商品数量加减
 * @param k “+”或者“-”
 */
function changenum(goodsid,k) {
    var num = parseFloat($('#product_amount').val());
    if($('#product_amount').val()=='' || num<0){ num=0;}
    if(isNaN($('#product_amount').val())){num=0;}
    switch (k) {
        case "+":
            num = num + 1;
            break;
        case "-":
            if (num !== 1) {
                num = num - 1;
            } else {
                $.showErr('数量不能小于1件', 0,'hc');
            }
            break;
    }
    $('#product_amount').val(num);
}
/**
*有属性加入购物车
**/
function addcart(goodsid){
	var arr=checkarrkey_str;
    var num=parseInt($('#product_amount').val());
	var packid = parseInt($('#pack_id'+goodsid).val());
	var attrs=new Array();
    attrs=arr.split("_");
    var names='';
    for(i=0;i<attrs.length;i++){
        var namea=$("#attr"+attrs[i]+"").html();
        var parent_name= $("#attr"+attrs[i]+"").parent().siblings("dt").html();
        var allname=parent_name+":"+namea;
        names+=allname+' ';
    }
	var query = new Object();
	query.goodsid = goodsid;
	query.number = num;
	query.name = names;
	query.pack_id = packid;
	if(arr){
		query.goods_attr = arr;
	}else{
		query.goods_attr = 0;
	}
	$.ajax({
        type:"POST",
        url:APP + "Mobile/PurIndex/add_cartlist",
        data:query,
        success:function(data){
            if(data.status==1) {
				$.showErr(data.msg,0,'hc');
            }else if(data.status==2){
            	if(num >0 ){
            		$.showSuccess(data.msg,2,'hc');
            		claseattr();
            	}
				$('#number'+goodsid).html(num);
            }else{
                $.showErr(data.msg, 0, 'hc', function () {
                    window.location.href = data.url;
                });
            }
        }
    })
}

function setNavHeight()
{
  var h_top=document.documentElement.clientHeight - $('header').height();
  $('#m360_leftNav').css("height",h_top)
  
}




