/**
 *@class CategoryNavi
 *@extends Div
 *カテゴリナビ
 */


var CategoryNavi = Class.create();


CategoryNavi.prototype = Object.extend(new Div, {


	/**
	 *@constructor initialize
	 */
	initialize: function (id,parentObj,no) {
		this.id=id;
		this.parentObj=parentObj;
		this.no=no;
		this.createDiv();


		this.entryNum=0;
		this.limitStart=0;
		this.limitLength=searchAll.displayNum;
		this.reqEntryNum();


		this.display();
		this.setStyle();


		this.entryID;
		this.entryAll;
		this.entry;
	},



	/**
	 *reqEntryNum
	 *カテゴリー毎で、検索にヒットしたエントリー総数
	 */
	reqEntryNum: function(){


		/* Ajax.Request */
		var req = new Ajax.Request("../src/php/request/entryNum.php",{
			method: "get",
			parameters: "category_id="+categoryAll.category_id[this.no]+"&keyword="+searchAll.keyword+"&orderKey="+searchAll.orderKey,
			asynchronous: false
		});


		/* entryNum */
		this.entryNum=req.transport.responseText;
		//console.log("["+categoryAll.category_id[this.no]+"]"+this.entryNum);


	},






	/**
	 *display
	 */
	display: function () {


		var html='';


		/* entryNum */
		if(this.limitStart+this.limitLength<this.entryNum){
			html+=this.limitStart+' - '+(this.limitStart+this.limitLength)+' / '+this.entryNum+' ENTRIES<br/>';
		}else{
			html+=this.limitStart+' - '+this.entryNum+' / '+this.entryNum+' ENTRIES<br/>';
		}


		/* prev */
		var prevStart=this.limitStart-this.limitLength;
		if(prevStart>=0){
			//var func="move.main.categories["+this.no+"].reqEntryID("+prevStart+")";
			var func='onNavi('+this.no+','+prevStart+')';
			html+='<a href="#mode=search" onClick='+func+'>PREV</a>';
		}else{
			html+='PREV';
		}


		html+=' | ';


		/* next */
		var nextStart=this.limitStart+this.limitLength;
		if(nextStart<this.entryNum){
			//var func="move.main.categories["+this.no+"].reqEntryID("+nextStart+")";
			var func='onNavi('+this.no+','+nextStart+')';
			html+='<a href="#mode=search" onClick='+func+'>NEXT</a>';
		}else{
			html+='NEXT';
		}


		/* innerHTML */
		$(this.id).innerHTML=html;


	},





	/**
	 *reqEntryID
	 *カテゴリー毎で、検索にヒットしたエントリーのIDリストをリクエスト
	 */
	reqEntryID: function(){


		/* Ajax.Request */
		var req = new Ajax.Request("../src/php/request/entryID.php",{
			method: "get",
			parameters: "category_id="+categoryAll.category_id[this.no]+"&limitStart="+this.limitStart+"&limitLength="+this.limitLength+"&keyword="+searchAll.keyword+"&orderKey="+searchAll.orderKey,
			asynchronous: false
		});


		/* entryID */
		this.entryID=req.transport.responseText.split(",");
		if(this.entryID[0]==''){
			this.entryID=new Array();
		}


	},





	/**
	 *makeEntryAll
	 *entryAll生成
	 */
	makeEntryAll: function(){
		this.entryAll=new EntryAll(searchWindow.world.id+'Category'+categoryAll.category_id[this.no]+'_entryAll',
							   	   this.parentObj,
							   	   this.no);


	},



	/**
	 *makeEntry
	 *エントリー生成
	 */
	makeEntry: function(){
		this.entry=new Array();
		for(var i=0;i<this.entryID.length;i++){
			this.entry[i]=new Entry(searchWindow.world.id+'Category'+categoryAll.category_id[this.no]+'_entry'+i,
							   		this.entryAll,
							   		this.no,
							   		this.entryID[i]);
		}


	},





	/**
	 *setStyle
	 */
	setStyle: function () {
		Element.setStyle($(this.id),{
			backgroundColor	:"rgb(255,255,255)",
			color			:categoryAll.category_color[this.no],
			fontFamily		:"Helvetica, sans-serif",
			fontSize		:"11px",
			lineHeight		:"16px",
			marginLeft		:"0px",
			marginRight		:"0px",
			marginTop		:"5px",
			marginBottom	:"0px",
			paddingLeft		:"10px",
			paddingRight	:"10px",
			paddingTop		:"5px",
			paddingBottom	:"5px",
			borderColor		:categoryAll.category_color[this.no],
			borderLeftWidth		:"0px",
			borderRightWidth	:"0px",
			borderTopWidth		:"1px",
			borderBottomWidth	:"1px",
			borderStyle		:"dotted"
		});
	}



});
