
// global
var gProduct = {
	data:new Array(),
	page:1,
	size:1000,
	cat_id:0
};

/*
<div id="1" class="case"  sort="item">
	<div class="imgArea2"><img src="images/pic.png" width="181" height="106"/></div>
	<h4>fsdfsdfsd</h4>
</div>
*/
function initProductListByCatid(){
	if(gProduct.cat_id != 0){
		$("#navigation").show();
		var pro = product(global.market,global.language,gProduct.cat_id,gProduct.page,gProduct.size);
	
		//page
		$("#pageSum").html(pro["page"]["total"]);
		$("#pageNo").val(pro["page"]["page"]);	
		
		var html = new Array();	
		for(var i=0;i<pro.length;i++){
			//var url = (pro[i]["photoUrl"]=="")?"uploads/gril.B.jpg":pro[i]["photoUrl"];		
			var url = (pro[i]["photoUrl"]=="")?"category/B.jpg":pro[i]["photoUrl"];
			html[html.length] = '<div id="'+pro[i]["id"]+'" class="case" sort="item">';
			html[html.length] = '	<div class="imgArea2"><a href="detail.php?pid='+pro[i]["id"]+'"><img src="'+url+'" width="181" height="106"/></a></div>';       
			html[html.length] = '	<h4>'+pro[i]["number"]+'&nbsp;&nbsp;'+pro[i]["name"]+'</h4>';
			html[html.length] = '</div>';
		}
		var htm = html.join("\r\n");	
		$("#productList").html(htm);
		initItemB();
	}else{
		$("#navigation").hide();
	}
}

function pageKeyDown(e){
	e = e || window.event;
	if(e.keyCode == 13){
		var pageNo = $("#pageNo").val();
		var pageSum = Math.ceil($("#pageSum").html());
		var re = new RegExp("^[1-9]*$");
		var judeg = re.test($.trim($("#txt").val()));
		if(pageNo <= 0 || pageNo > pageSum || !judeg){
			$("#pageNo").val(gProduct.page);
			return false;
		}
		location.href = "?c="+gProduct.cat_id+"&p="+pageNo;	
	}	
}

function initPageEvent(){
	$("#pagePrev").click(function(){
		var pageNo = $("#pageNo").val()-1;
		if(pageNo <= 0) return;
		location.href = "?c="+gProduct.cat_id+"&p="+pageNo;
	});	
	$("#pageNext").click(function(){
		var pageNo = Math.ceil($("#pageNo").val())+1;
		var pageSum = Math.ceil($("#pageSum").html());
		if(pageNo > pageSum) return;
		location.href = "?c="+gProduct.cat_id+"&p="+pageNo;		
	});
	$("#pageGo").click(function(){
		var pageNo = $("#pageNo").val();
		var pageSum = Math.ceil($("#pageSum").html());
		if(pageNo <= 0 || pageNo > pageSum) return;
		location.href = "?c="+gProduct.cat_id+"&p="+pageNo;	
	});
}
