/**
 *@class EntryBrowse
 *@extends Div
 */


var EntryBrowse = Class.create();


EntryBrowse.prototype = Object.extend(new Div, {


	/**
	 *@constructor initialize
	 */
	initialize: function (id,parentObj,no,entryId) {
		this.id=id;
		this.parentObj=parentObj;
		this.no=no;
		this.entryId=entryId;


		this.createDiv();


		this.displayLoading();


		this.reqEntry();
	},



	/**
	 *reqEntry
	 *DBからエントリーをリクエスト
	 */
	reqEntry: function(){


		/* Ajax.Request */
		var req = new Ajax.Request("../src/php/request/entryBrowse.php",{
//		var req = new Ajax.Request("browse.php",{
			method: "get",
			parameters: "entry_id="+this.entryId,
			onComplete: this.display.bind(this)	//this.display関数呼び出し
		});


	},





	/**
	 *display
	 */
	display: function (request) {


		/* request */
		var json=eval("("+request.responseText+")");

		/* idが正しいかチェック */
		if(json.allNum==0){
			$(this.id).innerHTML="エントリーID:"+this.entryId+"に対応するエントリーは存在しません。正しいエントリーIDを入力して下さい";

			/* setStyle */
			this.setStyle();

			/* onInit */
			onInit();
			return;
		}


		/* html */
		var html='';


		/* title */
		html+='<div class="title">';
			html+='<img src="../style/img/synergy_logo_b.jpg" width="700" height="56" />';
		html+='</div>';


		/* main */
		html+='<div class="main">';


			/* center */
			html+='<div class="center">';


				/* category_title */
				html+='<div class="category-1_title">';
					html+='&nbsp;';
				html+='</div>';


				/* entry */
				html+='<div class="entry">';
				html+='<div class="category'+categoryAll.category_id[this.no]+'">';


					/* title */
					html+='<div class="category'+categoryAll.category_id[this.no]+'_entry_title">';
						/* newFlg */
						//console.log(json.newFlg);
						if(json.entry[0].newFlg==1){
							html+='<img src="../style/img/new.jpg" /><br />';
						}
						/* title */
						var func='onOpenBrowse('+this.entryId+','+categoryAll.category_id[this.no]+')';
						var anc='/entry_id='+json.entry[0].entry_id+'/category_id='+categoryAll.category_id[this.no];
						html+='<a href="#mode=browse'+anc+'" onClick='+func+'>';
							html+=json.entry[0].title;
						html+='</a>';
					html+='</div>';


					/* main_text */
					html+='<div class="category'+categoryAll.category_id[this.no]+'_entry_main_text">';
						html+='<span class="top_text">';
							html+=json.entry[0].main_text+'<br clear="all" />';
						html+='</span>';
					html+='</div>';


					/* footer */
					html+='<div class="category'+categoryAll.category_id[this.no]+'_entry_footer">';
						html+=json.entry[0].uptime+' | clicked : '+json.entry[0].log;
					html+='</div>';

					/* alert */
					html+='<div class="category-1_entry_top_text">';
						if(categoryAll.category_id[this.no]==4){	//コンペ情報
							html+='<div class="category'+categoryAll.category_id[this.no]+'_notice">';
							html+='<font color="'+categoryAll.category_color[this.no]+'">＊コンペ情報は、当サイト掲載後に変更となる可能性があります。詳細については、それぞれの主催者にご確認下さい。<br />';
							html+='＊当コーナーでは、各種情報をお待ちしています。<a href="mailto:bunka@shokokusha.co.jp">こちら</a>まで情報をお寄せ下さい。<br />';
							html+='＊なお、いただいた情報の掲載の可否判断につきましては、編集部にご一任ください。掲載に際しては、掲載をもってご報告とさせていただきますので、あらかじめご了承ください。</font>';
							html+='</div>';
						}else if(categoryAll.category_id[this.no]==12){	//展覧会・イベント情報
							html+='<div class="category'+categoryAll.category_id[this.no]+'_notice">';
							html+='<font color="'+categoryAll.category_color[this.no]+'">＊展覧会、イベント情報は、当サイト掲載後に変更となる可能性があります。詳細については、それぞれの主催者にご確認下さい。<br />';
							html+='＊当コーナーでは、各種情報をお待ちしています。<a href="mailto:bunka@shokokusha.co.jp">こちら</a>まで情報をお寄せ下さい。<br />';
							html+='＊なお、いただいた情報の掲載の可否判断につきましては、編集部にご一任ください。掲載に際しては、掲載をもってご報告とさせていただきますので、あらかじめご了承ください。</font>';
							html+='</div>';
						}
					html+='</div>';


				html+='</div>';	//category
				html+='</div>';	//entry








				/* keywords */
				for(var i=0; i<json.keywords.length; i++) {


					/* category_title */
					html+='<div class="category-1_title">';
					if(json.keywords[i].keyword==''){
							html+='関連するエントリーはありません。 ';
					}else{
							html+='キーワード： 「 '+json.keywords[i].keyword+'」に関連するエントリー '+json.keywords[i].entryKeywords.length+'件<br />';
					}
					html+='</div>';


					/* entry */
					html+='<div class="entry">';
					for(var j=0; j<json.keywords[i].entryKeywords.length; j++) {


						for(var k=0; k<json.keywords[i].entryKeywords[j].category_id.length; k++) {


							/* category */
							html+='<div class="category'+json.keywords[i].entryKeywords[j].category_id[k]+'">';

								/* title */
								html+='<div class="category'+json.keywords[i].entryKeywords[j].category_id[k]+'_entry_title_top">';
									/* newFlg */
									//console.log(json.newFlg);
									if(json.keywords[i].entryKeywords[j].newFlg==1){
										html+='<img src="../style/img/new.jpg" /><br />';
									}
									/* title */
									var func='onOpenBrowse('+json.keywords[i].entryKeywords[j].entry_id+','+json.keywords[i].entryKeywords[j].category_id[k]+')';
									var anc='/entry_id='+json.keywords[i].entryKeywords[j].entry_id+'/category_id='+json.keywords[i].entryKeywords[j].category_id[k];
									html+='<a href="#mode=browse'+anc+'" onClick='+func+'>';
										html+=json.keywords[i].entryKeywords[j].title;
									html+='</a>';
								html+='</div>';


								/* footer */
								html+='<div class="category'+json.keywords[i].entryKeywords[j].category_id[k]+'_entry_footer">';
									html+=json.keywords[i].entryKeywords[j].uptime;
									html+=' | clicked : '+json.keywords[i].entryKeywords[j].log;
									html+=' | category : '+categoryAll.getCategoryDisplayName(json.keywords[i].entryKeywords[j].category_id[k]);
								html+='</div>';


							html+='</div>';	//category


						}


					}
					html+='</div>';	//entry

				}


			html+='</div>';	//center






			/* right */
			html+='<div class="right">';


				/* category_title */
				html+='<div class="category-1_title">';
					html+='このエントリーに関連する推薦図書';
				html+='</div>';


				/* entryBookSynergy */
				var category_id=2
				for(var i=0; i<json.entryBookSynergy.length; i++) {


					/* entry */
					html+='<div class="entry_top">';
					html+='<div class="category'+category_id+'">';


						/* title */
						html+='<div class="category'+category_id+'_entry_title_top">';
							/* newFlg */
							//console.log(json.newFlg);
							if(json.entryBookSynergy[i].newFlg==1){
								html+='<img src="../style/img/new.jpg" /><br />';
							}
							/* title */
							var func='onOpenBrowse('+json.entryBookSynergy[i].entry_id+','+category_id+')';
							var anc='/entry_id='+json.entryBookSynergy[i].entry_id+'/category_id='+category_id;
							html+='<a href="#mode=browse'+anc+'" onClick='+func+'>';
								html+=json.entryBookSynergy[i].title;
							html+='</a>';
						html+='</div>';


						/* top_text */
						html+='<div class="category'+category_id+'_entry_top_text">';
							html+='<span class="top_text">';
								html+=json.entryBookSynergy[i].top_text+'<br clear="all" />';
							html+='</span>';
						html+='</div>';


						/* footer */
						html+='<div class="category'+category_id+'_entry_footer">';
							html+=json.entryBookSynergy[i].uptime;
							html+=' | clicked : '+json.entryBookSynergy[i].log+'<br />';
							html+='category : '+categoryAll.getCategoryDisplayName(category_id);
						html+='</div>';


					html+='</div>';//category
					html+='</div>';//entry


				}





				/* entryBookNew */
				var category_id=3
				for(var i=0; i<json.entryBookNew.length; i++) {


					/* entry */
					html+='<div class="entry_top">';
					html+='<div class="category'+category_id+'">';


						/* title */
						html+='<div class="category'+category_id+'_entry_title_top">';
							/* newFlg */
							//console.log(json.newFlg);
							if(json.entryBookNew[i].newFlg==1){
								html+='<img src="../style/img/new.jpg" /><br />';
							}
							/* title */
							var func='onOpenBrowse('+json.entryBookNew[i].entry_id+','+category_id+')';
							var anc='/entry_id='+json.entryBookNew[i].entry_id+'/category_id='+category_id;
							html+='<a href="#mode=browse'+anc+'" onClick='+func+'>';
								html+=json.entryBookNew[i].title;
							html+='</a>';
						html+='</div>';


						/* top_text */
						html+='<div class="category'+category_id+'_entry_top_text">';
							html+='<span class="top_text">';
								html+=json.entryBookNew[i].top_text+'<br clear="all" />';
							html+='</span>';
						html+='</div>';


						/* footer */
						html+='<div class="category'+category_id+'_entry_footer">';
							html+=json.entryBookNew[i].uptime;
							html+=' | clicked : '+json.entryBookNew[i].log+'<br />';
							html+='category : '+categoryAll.getCategoryDisplayName(category_id);
						html+='</div>';


					html+='</div>';//category
					html+='</div>';//entry


				}



			html+='</div>';	//right



		html+='</div>';	//main


		/* footer */
		html+='<div class="footer">';
			html+='本ホームページに掲載のテキスト・写真などの著作権は、その著者・撮影者および株式会社 彰国社に帰属します。<br />';
			html+='無断での転用・転載等は禁止させていただきます。<br />';
			html+='&copy; 2005- <a href="http://www.shokokusha.co.jp/" target="_blank">彰国社</a> All rights reserved.';
		html+='</div>';








		$(this.id).innerHTML=html;


		/* setStyle */
		this.setStyle();


		/* onInit */
		onInit();


	},


	/**
	 *displayLoading
	 */
	displayLoading: function () {


		/* html */
		var html='';

		html+='<div class="category-1_entry_top_text">';
		html+='loading id:'+this.entryId+'...';
		html+='</div>';


		$(this.id).innerHTML=html;


		/* setStyle */
		this.setStyle();


		/* onInit */
		onInit();


	},





	/**
	 *setStyle
	 */
	setStyle: function () {


		Element.setStyle($(this.id),{
			backgroundColor	:'#ffffff',


			fontFamily		:'Times, serif',
			fontSize		:'11px',
			lineHeight		:'18px',


			marginLeft		:'0px',
			marginRight		:'0px',
			marginTop		:'0px',
			marginBottom	:'0px',


			position		:'static',	//配置方式:static(default),relative,absolute,fixed,inherit
			overflow		:'hidden'	//スクロールバー制御:visible,hidden,scroll,auto,inherit
		});


	}





});
