
$(function(){
	/**
	 *	將產品加入購物車
	 */
	$("a[name=add_to_shopping_cart]").click(function(){
		if($("#LoginData").val() != ''){
			var product_id = $(this).attr("product_id");
			var _fun_id = $(this).attr("fun_id");
			var product_spec = $("input[name=product_spec]").val();
			var product_buy_number = $("input[name=product_buy_number]").val();
			//alert(product_id+'...'+_fun_id+'...'+product_spec+'...'+product_buy_number);
					
			$.post("module/shop/cart_modify.php",{
				fun_id:_fun_id,
				act:'add',
				product_id:product_id,
				product_spec:product_spec,
				product_buy_number:product_buy_number
			},function(xml){
				eval("_data="+xml);
				alert(_data['msg']);
			});
			return false;
		}else{
			alert("請先登入會員");	
		}
	});
	/**
	 *	我要結帳
	 */
	var CartLink;
	var CartLinkVarNameId;
	var ships_id;
	$("a[name=Checkout_shopping_cart]").click(function(){
		if($("#LoginData").val() != ''){
			var _product_id = $(this).attr("product_id");
			var _fun_id = $(this).attr("fun_id");
			var _product_spec = $("input[name=product_spec]").val();
			var _product_buy_number = $("input[name=product_buy_number]").val();
			CartLink = $(this).attr("CartLink");
			CartLinkVarNameId = $(this).attr("CartLinkVarNameId");
			ships_id = $(this).attr("ships_id");
			//alert(_product_id+'...'+_fun_id+'...'+_product_spec+'...'+_product_buy_number+'...'+CartLink+'...'+CartLinkVarNameId+'...'+ships_id);
			
			$.post("module/shop/cart_modify.php", {
				fun_id:_fun_id,
				act:'add',
				product_id:_product_id,
				product_spec:_product_spec,
				product_buy_number:_product_buy_number
			} ,function(xml) {
				eval("_data="+xml);
				if (_data['cls']==1) {
					//location.href=CartLink+'?'+CartLinkVarNameId+'='+ships_id;
					window.location.href=CartLink+'?'+CartLinkVarNameId+'='+ships_id;
				} else {
					alert(_data['msg']);
				}
			});
			return false;
		}else{
			alert("請先登入會員");	
		}
	});
	/**
	 *	加入追蹤清單網址變更
	 */
	$("a[name=TrackList]").click(function(){
		var product_id=$(this).attr("product_id");
		var href=$("a[name=TrackList]").attr("href");
		var val=$("input[name=product_spec]").val();
		$("a[name=TrackList]").attr("href",href+'&spec_id='+val);
	});
	
	/*
	* 點小圖換大圖
	*/
	change_pic = function(v, w, h) {
		var _width=w;
		var _height=h;
		
		var autosize;
		eval("autosize={"+$("#big_pic").attr("autosize")+'}');
		var x =_width/autosize.width;
		var y = _height/autosize.height;
		
		if(_width > _height){
			ww = _width/x;
			hh = _height/x;
		}else{
			ww = _width/y;
			hh = _height/y;	
		}
		
		$("#big_pic").css("width", Math.floor(ww));
		$("#big_pic").css("height", Math.floor(hh));
		
		$("#big_pic").attr("src", "../upload_file/img_product/large/"+v);
		$("#big_pic").attr("jqimg", "../upload_file/img_product/large/"+v);
	}
	/**
	 *	自動縮小圖片到一定尺寸內 用法: class="AutoImgSize" autosize="width:80,height:50"
	 */
	$(".AutoImgSize_pic").each(function(){
		var _width=$(this).attr("w");
		var _height=$(this).attr("h");
		//alert(_width+'...'+_height);
		
		var autosize;
		eval("autosize={"+$(this).attr("autosize")+'}');
		var x =_width/autosize.width;
		var y = _height/autosize.height;
		
		if(_width > _height){
			ww = _width/x;
			hh = _height/x;
		}else{
			ww = _width/y;
			hh = _height/y;	
		}

		$(this).css("width",Math.floor(ww));
		$(this).css("height", Math.floor(hh));
		
		$(this).css("_width",Math.floor(ww));
		$(this).css("_height", Math.floor(hh));
	});
});
	

