// JavaScript Document  分页插件
;(function($){
		   $.fn.jPagination=function(options){
			   var settings={
				   list:"", //需要分页的列表
				   pageSize:10, //每页记录数
				   rowCount:5
				   }
			   var op=$.extend(settings,options);
			   var $this=$(this);
			   var pageNo=1;
			   //计算出页码
			   var pageCount=Math.round(op.list.length / op.pageSize + 0.455)
			   
			   //生成页面列表
			   var createrPagination=function(){
				   $this.show();
				   $this.find("li.pagelinks").remove()
				   for (i=0;i<pageCount; i++){
					   var $pagelink=$("<li class=\"pagelinks\"><a href=\"#\" title=\""+(i+1)+"\">"+(i+1)+"</a></li>");
					   if (i+1==pageNo) $pagelink.find("a").addClass("current")
					   $this.find("li.pagenext").before($pagelink)
					   }
				   $this.find("li.pagepreviou").unbind();
				   $this.find("li.pagenext").unbind();
				   $this.find("li.pagepreviou").click(function(){
															   pageNo = pageNo-1 <= 0 ? pageNo:pageNo-1;
															   resetPaginationView();
															   return false;
															   })
				   $this.find("li.pagenext").click(function(){
															pageNo = pageNo+1 > pageCount ? pageNo:pageNo+1;
															resetPaginationView();
															return false;
															})
				   clickPageLink();
				   }
			   
			   //点击链接事件的绑定
			   var clickPageLink=function(){
				   $this.find("li.pagelinks").unbind();
				   $this.find("li.pagelinks").click(function(){
															 //alert($(this).find("a").html())
															 pageNo=$(this).find("a").html()/1;
															 resetPaginationView()
															 return false;
															 })				   
				   }
			   
			   //重置页码		   
			   var resetPaginationView=function(){
				   $this.find("li.pagelinks").find("a").removeClass("current");
				   $this.find("li.pagelinks").each(function(){
															if ($(this).find("a").html()/1 == pageNo){
																$(this).find("a").addClass("current")
																}
															})
				   
				   //过滤列表
				   filterList();
				   }
			   
			   
			   var showHiddenLogoAndTechnologys=function(obj){
				   var $showProductList=obj.filter(":visible")//.find("li:first:visible")
				   var haveLogo=false;
				   var maxLogoHeight=0;
				   var haveTechnologys=false;
				   $showProductList.each(function(index){
												  haveTechnologys=false;
												  haveLogo=false;
												  maxLogoHeight=0;
//												  $(this).find("div.logo").show();//初始化所有的LOGO位置为显示
//												  if ($(this).find("div.logo > img").length==0){
//													  if (index % op.rowCount == 0){ //第一个不含LOGO的话 就标志下，后面的都不显示LOGO的占位。
//														  isLogo=false;
//														  //$(this).find("div.logo").hide()
//														  }
//													  }
												  //if (isLogo==false) $(this).find("div.logo").hide();
												  
												  //当前行中都没有技术图标或LOGO，那当前行放技术图标或LOGO的层就隐藏掉
												  //求当前行
												  var currentRow=Math.round(((index+1) / op.rowCount) + 0.455)
												  //计算出当前行起始的数字和结束的数字
												  var startPosition=(currentRow-1) * op.rowCount ==0 ? 0 : (currentRow-1) * op.rowCount
												  var endPosition=startPosition+op.rowCount
												  var $currentRow=$showProductList.slice(startPosition,endPosition)
												  //吧当前行的放技术图标或LOGO的层隐藏掉
												  $currentRow.find("div.technologys").hide();
												  $currentRow.find("div.logo").hide();
												  $currentRow.find("div.new").show();
												  $currentRow.each(function(){//当前行搜索有没有技术图标或LOGO
																			if ($(this).find("div.technologys > ul").length > 0) haveTechnologys=true
																			if ($(this).find("div.logo > img").length > 0) haveLogo=true;
																			$(this).find("div.logo").height() > maxLogoHeight ? maxLogoHeight=$(this).find("div.logo").height() : maxLogoHeight = maxLogoHeight;
																			})
												  //如果结果为有的，就把当前行中所有的放技术图标或LOGO的层显示
												  if (haveTechnologys)  $currentRow.find("div.technologys").show();
												  if (haveLogo)  $currentRow.find("div.logo").show().height(maxLogoHeight);
												  })
				   
				   }
			   
			   //过滤列表
			   var filterList=function(){
				   
				   
				   //全部隐藏
				   op.list.hide();
				   
				   //如果列表为空，把页码隐藏
				   if (op.list.length == 0 ) $this.hide()
				   
				   //计算出起始的数字和结束的数字
				   var startPosition=(pageNo-1) * op.pageSize ==0 ? 0 : (pageNo-1) * op.pageSize
				   var endPosition=(pageNo-1) * op.pageSize+op.pageSize > op.list.length ? op.list.length : (pageNo-1) * op.pageSize+op.pageSize
				   showHiddenLogoAndTechnologys(op.list.slice(startPosition,endPosition).show());
				   }
			   
			   createrPagination();
			   filterList();
			   
			   return $this;
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   }
		   
		   
		   
		   })( jQuery );
