/* ----------------------------------------------------------------------------
 * サイドバーシステム
 * ------------------------------------------------------------------------- */

var sidebarSystems = {
	
	//設定項目
	config : {
		// サイドバーコンテンツ Ajax JSON ファイル名
		jsonFile : "resources/c_media/themes/monotalk_v100/js/sidebar_contents.json",
		//サイドバーコンテンツ　Ajax PHPファイル名
		phpFile : "category/select/cid/313"
	},
	
	//内部保持変数
	c : {
		// 現在表示中の項目
		now : "",
		//cache生成済みの項目
		cached : new Array(),
		//現在選択中の項目のヒット数
		hits : "",
		//選択済みの項目
		selectedPsscId　: {}
	},
	
	//キャッシュ
	cache : {
		/*
		[項目名] : {
			popup 		: ポップアップ要素(jQuery)
			title 		: タイトル要素(jQuery)
			cateBlocks	: <div class="cateBlocks_area">....(jQuery)
			psscLists	: 選択対象
						{
							[pssc_id] : <dd class="include|exclude ">,
							...
						}...
			x_buttons 	: ポップアップ内各項目Xボタン
						{
							[pssc_id] : <img class="list_x">,
							...
						}
			submitArea 	: <div class="submitArea">...
			close 		: <p class="close">...
			selected_box :
						{
							[pssc_id] : <div class="selected_box">
							...
						}
			x_button_d :　ディスプレイ部Xボタン
						{
							[pssc_id] : <img>
							...
						}
			show		: クリックされた<li>要素
						<li class="on">text</li>
			
			pssc_id 	: product_search_category_id,product_country_id,brand_id
						{
							i : new Array,
							e : new Array
						}
		}, ...
		*/
	},	

	//テンプレート
	template : {
		// ポップアップ全体
		popup			: '<div class="sidebar_popup" tabindex="-1"></div>',
		// タイトル
		title  			: function(title){
							return $('<div />').addClass("popup_title")
								.append($('<h3 />')
								.append(title + 'から選択')
								.append($('<span />').addClass('title_small_cap')
								.append('(キーワードを２回クリックすると除外)')));
						},
		//各項目ラッパー
		cateBlocks 		: '<div class="cate_block"></div>',			
		//項目Xボタン
		x_button		: $('<a />').addClass("x_button").text(" "),
									//.attr('src', "resources/c_media/themes/monotalk_v400/images/sidebar_img/parts/icon_navi_check.png")
									//.attr('onMouseOver','this.src="resources/c_media/themes/monotalk_v400/images/sidebar_img/parts/icon_navi_check_on.png"')
									//.attr('onMouseOut','this.src="resources/c_media/themes/monotalk_v400/images/sidebar_img/parts/icon_navi_check.png"'),
		//検索するボタン		
		submitArea 		: '<div class="submitArea"><input type="image" src="resources/c_media/themes/monotalk_v400/images/sidebar_img/parts/icon_navi_search.png" onClick="sidebarSystems.psscFunc.submit()"  onmouseover="this.src=\'resources/c_media/themes/monotalk_v400/images/sidebar_img/parts/icon_navi_search_on.png\'" onmouseout="this.src=\'resources/c_media/themes/monotalk_v400/images/sidebar_img/parts/icon_navi_search.png\'" /></div>',
							//<!--<input type="checkbox" name="danger" value="off" />危険な添加物を含まない>-->
		// 「閉じる」ボタン
		close 			: '<p class="close"> </p>',
		//'<p class="close"><input type="image" class="close_image"/></p>',
		//表示領域項目
		selected_box 	: function(text, img){ 
							return $('<div />').addClass("selected_box")
								.append($('<span />').addClass("selected_name")
								.append(text))
								.append(img);
						},
		x_button_d		: function(pssc_id, cached) {
							return  '<span class="x_button_d" onClick=sidebarSystems.display_area.x_button_func("' + pssc_id + '","' + cached + '")> </span>';
							//$('<span />').addClass('x_button_d').text(" ")
							//.attr('onclick','sidebarSystems.display_area.x_button_func(' + pssc_id + ',"' + cached + '");');							
						}
	},
	
	//イベントボタン用メソッド
	psscFunc : {
		//popup内項目選択時イベント
		include : function(i){
			sidebarSystems.cache[sidebarSystems.c.now].pssc_id.i.push(i);							
			sidebarSystems.cache[sidebarSystems.c.now].psscLists[i].addClass("included");
			sidebarSystems.cache[sidebarSystems.c.now].x_buttons[i].appendTo(sidebarSystems.cache[sidebarSystems.c.now].psscLists[i]);
			sidebarSystems.display_area.include_selected.append(sidebarSystems.cache[sidebarSystems.c.now].selected_box[i]);
			sidebarSystems.psscFunc.getProductCount();
		},
		exclude : function(i){
		 	sidebarSystems.cache[sidebarSystems.c.now].pssc_id.e.push(i);
			sidebarSystems.cache[sidebarSystems.c.now].pssc_id.i = $.map(sidebarSystems.cache[sidebarSystems.c.now].pssc_id.i, function(item, index){
				return (item !== i) ? item : null;
			});
			sidebarSystems.cache[sidebarSystems.c.now].psscLists[i].removeClass("included");
			sidebarSystems.cache[sidebarSystems.c.now].psscLists[i].addClass("excluded");
			sidebarSystems.cache[sidebarSystems.c.now].selected_box[i].detach();
			sidebarSystems.display_area.exclude_selected.append(sidebarSystems.cache[sidebarSystems.c.now].selected_box[i]);
			sidebarSystems.psscFunc.getProductCount();
		},
		unselect : function(i){
			sidebarSystems.cache[sidebarSystems.c.now].pssc_id.e = $.map(sidebarSystems.cache[sidebarSystems.c.now].pssc_id.e, function(item, index){
				return (item !== i) ? item : null;
			});
			sidebarSystems.cache[sidebarSystems.c.now].psscLists[i].removeClass("excluded");
			sidebarSystems.cache[sidebarSystems.c.now].x_buttons[i].remove();
			sidebarSystems.cache[sidebarSystems.c.now].selected_box[i].remove();
			sidebarSystems.psscFunc.getProductCount();
		},
		//Xbutton イベント
		include_d : function(i, cached){
			sidebarSystems.cache[cached].pssc_id.i = $.map(sidebarSystems.cache[cached].pssc_id.i, function(item, index){
				return (item !== i) ? item : null;
			});
			sidebarSystems.cache[cached].psscLists[i].removeClass("included");
			sidebarSystems.cache[cached].x_buttons[i].detach();
			sidebarSystems.cache[cached].selected_box[i].detach();
			sidebarSystems.psscFunc.getProductCount();
		},
		exclude_d : function(i, cached){
			sidebarSystems.cache[cached].pssc_id.e = $.map(sidebarSystems.cache[cached].pssc_id.e, function(item, index){
				return (item !== i) ? item : null;
			});
			sidebarSystems.cache[cached].psscLists[i].removeClass("excluded");
			sidebarSystems.cache[cached].x_buttons[i].detach();
			sidebarSystems.cache[cached].selected_box[i].detach();
			sidebarSystems.psscFunc.getProductCount()
		},
		//選択項目リセット
		reset : function(){
			var form = $('#reset');
			//ページ再読込
			//location.reload();
			form.submit();
		},
		//現在のヒット数表示
		getProductCount : function(){
			var jsonData = {
				requestId : {}
			};
			//jsonData = this.createJsonData();
			$.each(sidebarSystems.cache, function(key, val){
				jsonData.requestId[key] = val.pssc_id;
			});
			jsonData.sidebar = "getProductCount";
			$.ajax({
				url		: sidebarSystems.config.phpFile,
				type	: 'post',
				data	: jsonData
			}).success(function(data){
				if(data){
					sidebarSystems.display_area.current_num.text(data);
				}else{
					//データが何らかの事情で帰ってこない場合、とりあえずの数を表示
					sidebarSystems.display_area.current_num.text("5562 ");
				}
			}).error(function(){
				
			});
			
		},
		//submit
		submit	: function(){
			//データをまとめて送信
			form = $('#get_product_id');
			$.each(sidebarSystems.cache, function(key, val){
				if(val.pssc_id.i){
					$.each(val.pssc_id.i, function(){
						form.append($('<input />').attr('type','hidden').attr('name', 'requestId[' + key + '][i][]').val(this));
					});
				}
				if(val.pssc_id.e){
					$.each(val.pssc_id.e, function(){
						form.append($('<input />').attr('type','hidden').attr('name', 'requestId[' + key + '][e][]').val(this));
					});
				}
			})
			form.submit();
		}
		/**
		*	予備関数群
		*
		
		//Jsonデータ生成
		createJsonData : function(){
		 	var jsonData = {
				"pssc_id" 	: {
								i : new Array,
								e : new Array
							},
				"country_id"	: {
								i : new Array,
								e : new Array
							},
				"brand_id"	: {
								i : new Array,
								e : new Array
							},
			};
			$.each(sidebarSystems.cache, function(i,val){
				switch (i) {
					case "原産国" :
						Array.prototype.push.apply(jsonData.country_id.i, this.pssc_id.i);
						Array.prototype.push.apply(jsonData.country_id.e, this.pssc_id.e);
						break;
					default	 :
						Array.prototype.push.apply(jsonData.pssc_id.i, this.pssc_id.i);
						Array.prototype.push.apply(jsonData.pssc_id.e, this.pssc_id.e);
				};
			});
			$.each(jsonData, function(i,val){
				$.each(jsonData[i], function(i2,val2){
					if(jsonData[i][i2] == ""){
						delete jsonData[i][i2];
					}
				});
			});
			return jsonData
		},
		*/
		//選択済みのidをセット
		/*
		getJsonData : function(){
			var obj = {};
			function getUrlVars() {
				
				var vars = [], hash; 
				var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 
				for(var i = 0; i < hashes.length; i++) { 
					hash = hashes[i].split('='); 
					vars.push(hash[0]); 
					vars[hash[0]] = hash[1]; 
				} 
				return vars; 
			}
			function check(target){
				if(getUrlVars()[target]){
					return eval('[' + utf.URLdecode(getUrlVars()[target]) + ']')[0]
				}
			}
			obj["pssc_id"] = check("pssc_id");
			obj["country_id"] = check("country_id");
			sidebarSystems.c.selectedPsscId = obj;
		},
		*/		
	},
	
	//サイドバー
	popup : {
		//セット
		set : function(){
			var sidebarLists = $("#sidebar_list li");
			if (sidebarLists.length < 1) { return; } //サイドバー無い場合、以降の処理をキャンセル（バグ防止）
			// ポップアップ要素を追加する親要素
			var root = $(document.body);
			
			/*
			
						この部分をＡｊａｘに変更予定
			
			
			*/
			// JSON ファイル取得し、実行
			//$.getJSON(sidebarSystems.config.jsonFile, function(data) {
			//monotalk plugin にアクセスし、psscテーブルからサイドバーコンテンツデータ取得
			$.ajax({
				url		: sidebarSystems.config.phpFile,
				type	: 'post',
				data	: {"sidebar":"getSidebarListContents"}
			}).success(function(data){
				if(data){
					data = $.parseJSON(data);
				}else{
					return;
				}
				// 現在表示中のポップアップを位置を指定
				function setPosition() {
					if ( sidebarSystems.c.now) {
						var btn = sidebarSystems.cache[sidebarSystems.c.now].show;
						var pos = btn.offset();
						// 表示ボタン上端 + 表示ボタン高さで固定
						sidebarSystems.cache[sidebarSystems.c.now].popup.css({
							top  : ($(window).scrollTop() + 153) + "px", //(pos.top-100)+"px",
							left : (pos.left + btn.outerWidth())+"px"
						});
					}
				}
				// リサイズ時にポップアップ位置がズレるので都度修正
				$(window).resize(setPosition);
			
				// ポップアップ外のクリック → 閉じる
				$(document).click(function() {
					sidebarSystems.c.now && sidebarSystems.cache[sidebarSystems.c.now].close.trigger("click");
				});
				
				sidebarLists.each(function() {
					// サイドバー項目
					var obj = $(this);
					var text = obj.attr('id');					
					if (!text || !data[text]) { return; }　//Jsonデータが見つからなかった場合、処理中止

					// サイドバーボタンイベント設定
					obj.click(function() { 
						//現在表示中の項目がクリックされた場合
						if (sidebarSystems.c.now == text) {
							//閉じる
							sidebarSystems.cache[sidebarSystems.c.now].close.trigger("click");
						//ポップアップ表示中に他の項目がクリックされた場合　→　現在表示中のポップアップを閉じて新規にポップアップ展開						
						} else if (sidebarSystems.c.now && sidebarSystems.c.now != text){ 
								sidebarSystems.cache[sidebarSystems.c.now].close.trigger("click");
								$(this).trigger("click");
						//ポップアップが表示されていない場合	
						} else {
									
							// 選択された項目名
							sidebarSystems.c.now = text;
							//キャッシュされた項目を記憶
							if($.inArray(text, sidebarSystems.c.cached) == -1){
								sidebarSystems.c.cached.push(text);
							}
							// キャッシュが無い場合、生成
							if (!sidebarSystems.cache[sidebarSystems.c.now]) {
								sidebarSystems.cache[sidebarSystems.c.now] = {
									// ポップアップ要素
									popup : $(sidebarSystems.template.popup),
									// タイトル
									title : sidebarSystems.template.title(sidebarSystems.c.now),
									//項目
									cateBlocks : $('<div />').addClass("cateBlocks_area"),
									//検索するボタン
									psscLists : {},	
									//Xボタン
									x_buttons : {},
									//検索エリア
									submitArea : $(sidebarSystems.template.submitArea),
									// 「閉じる」ボタン
									close : $(sidebarSystems.template.close),
									selected_box : {},
									x_button_d : {},
									pssc_id : {
												i : new Array(),
												e : new Array()
											 },
									//ブランド項目
									ui_tab: {}
								};
								/*------------------------------------------------
								*   ポップアップコンテンツ作成
								*-----------------------------------------------*/
								//cate_block
								/*
								*<div class="cate_block">
								*	<dt>*******</dt>
								*	<img src="resources/c_media/themes/monotalk_v400/images/sidebar_img/thumbs/img_navi_*******.jpg">
								*	<!--	temp_dl	-->
								*</div>																				 
								*/
								var tempCateBlock = {};
								
								//<dl>要素
								/*-*
								*	<dl>
								*		<dd>ドライ</dd>
								*		<dd>セミモイスト</dd>
								*		<dd>ウェット</dd>
								*	</dl>
								*/
								var temp_dl ={};

								if(sidebarSystems.c.now == "ブランド"){
									
									
								/*
										<div id="ui-tab">	ui_tab
											<ul class="ui-tabs-nav">	ui_tabs_vav
												<li><a href="#fragment-1"><span>あ</span></a></li>	ui_tabs_nav_fragment_func
												<li><a href="#fragment-2"><span>か</span></a></li>
												<li><a href="#fragment-3"><span>さ</span></a></li>
												<li><a href="#fragment-4"><span>た</span></a></li>
												<li><a href="#fragment-5"><span>な</span></a></li>
												<li><a href="#fragment-6"><span>は</span></a></li>
												<li><a href="#fragment-7"><span>ま</span></a></li>
												<li><a href="#fragment-8"><span>や</span></a></li>
												<li><a href="#fragment-9"><span>ら</span></a></li>
												<li><a href="#fragment-10"><span>わ</span></a></li>
											</ul>
											<div id="fragment-1">	fragment 
												<div class="brand_header"><h4><span>あ</span>行から始まるブランド名</div></h4>	brand_header
											
												<div class="cateBlocks_area"> cate_blocks
													<div class="cate_block">
														<dt>あ</dt>
														<dl><dd>アイムス</dd>
															<dd>アイリスオーヤマ</dd>
															<dd>アスク</dd>
															<dd>アニウェル(aniwell)</dd>
															<dd>アニマルズアバスキャリー</dd>
															<dd>アニマル・ワン</dd>
															<dd>アボダーム(AvoDerm)</dd>
															<dd>アミノエース</dd>
															<dd>アークナチュラルズ</dd>
															<dd>アース・バイオケミカル</dd>
															<dd>アーテミス</dd>
															<dd>ADD.MATE(アドメイト)</dd>
															<dd>愛犬元気</dd>
														</dl>
													</div>
								*/

									
									var ui_tab = $('<div />').attr('id','ui-tab');
									var ui_tabs_nav = $('<ul />').addClass('ui-tabs-nav');
									var ui_tabs_nav_fragment_func = function(num, val) {
										return $('<li><a href="#fragment-' + num + '"><span>' + val + '</span></a></li>');
									}
									var fragment = {};
									var fragment_num = 1;
									var fragment_func = function(num){
										return $('<div />').attr('id', 'fragment-' + num);
									}
									var brand_header;
									var brand_header_func = function(val){
										return $('<div class="brand_header"><h4><span>' + val + '</span>行から始まるブランド名</div></h4>');
									}
									
									
									$.each(data[sidebarSystems.c.now], function(si) { //si = 子音
										var cateBlocksArea = $('<div />').addClass("cateBlocks_area");
										
										$.each(data[sidebarSystems.c.now][si], function(i) {
											temp_dl[i] = $('<dl />');
											
											//各母音が空の場合は表示無し
											if(data[sidebarSystems.c.now][si][i] != 0){
												
												$.each(data[sidebarSystems.c.now][si][i]["dd"], function(i2, val) {
													var temp_pssc_id = data[sidebarSystems.c.now][si][i]["pssc_id"][i2];
													
													//ポップアップ内項目（クリック対象）をidをkeyにキャッシュに保存
													sidebarSystems.cache[sidebarSystems.c.now].psscLists[temp_pssc_id] = $('<dd />').append(val);
													sidebarSystems.cache[sidebarSystems.c.now].x_buttons[temp_pssc_id] = $(sidebarSystems.template.x_button).clone(false);
													//ディスプレイエリア項目（クリック対象）をidをkeyにキャッシュに保存
													sidebarSystems.cache[sidebarSystems.c.now].x_button_d[temp_pssc_id]
													 = $(sidebarSystems.template.x_button_d(temp_pssc_id, sidebarSystems.c.now)).clone(false);
													sidebarSystems.cache[sidebarSystems.c.now].selected_box[temp_pssc_id]
													 = $(sidebarSystems.template.selected_box(val,sidebarSystems.cache[sidebarSystems.c.now].x_button_d[temp_pssc_id]));
													//<dl>要素構築
													temp_dl[i].append(sidebarSystems.cache[sidebarSystems.c.now].psscLists[temp_pssc_id]);
													
												});
												//cateBlocks構築
												tempCateBlock[i] =  $(sidebarSystems.template.cateBlocks)
																	.append($('<dt />').append(i))
																	.append($('<img />').attr('src', data[sidebarSystems.c.now][si][i]["src"]))
																	.append(temp_dl[i]);
												 cateBlocksArea.append(tempCateBlock[i][0]);
												
											}
										});
										
										ui_tabs_nav.append(ui_tabs_nav_fragment_func(fragment_num, si));
										fragment[fragment_num] = fragment_func(fragment_num);
										fragment[fragment_num].append(brand_header_func(si))
																.append(cateBlocksArea);
																
										fragment_num++;
									});
									ui_tab.append(ui_tabs_nav);
									$.each(fragment, function(fragment_num){
										ui_tab.append(fragment[fragment_num]);
									});
									sidebarSystems.cache[sidebarSystems.c.now].ui_tab = ui_tab;
									
									// ポップアップキャッシュ構築
									sidebarSystems.cache[sidebarSystems.c.now].popup
										.append(sidebarSystems.cache[sidebarSystems.c.now].ui_tab)
										.append(sidebarSystems.cache[sidebarSystems.c.now].submitArea)
										.append(sidebarSystems.cache[sidebarSystems.c.now].close);
									
								}else{
									//jsonデータ処理（デフォルト）				
									$.each(data[sidebarSystems.c.now], function(i) {
										temp_dl[i] = $('<dl />');
										$.each(data[sidebarSystems.c.now][i]["dd"], function(i2, val) {
											var temp_pssc_id = data[sidebarSystems.c.now][i]["pssc_id"][i2];
											//ポップアップ内項目（クリック対象）をidをkeyにキャッシュに保存
											sidebarSystems.cache[sidebarSystems.c.now].psscLists[temp_pssc_id] = $('<dd />').append(val);
											sidebarSystems.cache[sidebarSystems.c.now].x_buttons[temp_pssc_id] = $(sidebarSystems.template.x_button).clone(false);
											//ディスプレイエリア項目（クリック対象）をidをkeyにキャッシュに保存
											sidebarSystems.cache[sidebarSystems.c.now].x_button_d[temp_pssc_id]
											 = $(sidebarSystems.template.x_button_d(temp_pssc_id, sidebarSystems.c.now)).clone(false);
											sidebarSystems.cache[sidebarSystems.c.now].selected_box[temp_pssc_id]
											 = $(sidebarSystems.template.selected_box(val,sidebarSystems.cache[sidebarSystems.c.now].x_button_d[temp_pssc_id]));
											//<dl>要素構築
											temp_dl[i].append(sidebarSystems.cache[sidebarSystems.c.now].psscLists[temp_pssc_id]);
										});
										//cateBlocks構築
										tempCateBlock[i] =  $(sidebarSystems.template.cateBlocks)
															.append($('<dt />').append(i))
															.append($('<img />').attr('src', data[sidebarSystems.c.now][i]["src"]))
															.append(temp_dl[i]);
										sidebarSystems.cache[sidebarSystems.c.now].cateBlocks.append(tempCateBlock[i][0]);			
									});
									// ポップアップキャッシュ構築
									sidebarSystems.cache[sidebarSystems.c.now].popup
										.append(sidebarSystems.cache[sidebarSystems.c.now].title)
										.append(sidebarSystems.cache[sidebarSystems.c.now].cateBlocks)
										.append(sidebarSystems.cache[sidebarSystems.c.now].submitArea)
										.append(sidebarSystems.cache[sidebarSystems.c.now].close);
									
									
								};

							}
			
						
							$.each(sidebarSystems.cache[sidebarSystems.c.now].psscLists, function(i, val) {
								//popup内項目イベント設定
								sidebarSystems.cache[sidebarSystems.c.now].psscLists[i].click(function(){
									switch (sidebarSystems.cache[sidebarSystems.c.now].psscLists[i].attr('class')) {
										case "included":
											sidebarSystems.psscFunc.exclude(i);
											break;
										case "excluded":
											sidebarSystems.psscFunc.unselect(i);
											break;
										default:
											sidebarSystems.psscFunc.include(i);
											break;
									};
								});
								
								//ポップアップ内Xボタンイベント設定
								sidebarSystems.cache[sidebarSystems.c.now].x_buttons[i].click(function(event){
									sidebarSystems.display_area.x_button_func(i, sidebarSystems.c.now);
									event.stopPropagation();
								});
								
							});

							// 選択中の<li>タグ
							sidebarSystems.cache[sidebarSystems.c.now].show = $(this);
							//サイドバー項目背景切り替え
							sidebarSystems.cache[sidebarSystems.c.now].show.toggleClass("on");
							// 「閉じる」ボタン イベント設定
							sidebarSystems.cache[sidebarSystems.c.now].close.click(function() {
								sidebarSystems.cache[sidebarSystems.c.now].popup.remove();
								sidebarSystems.cache[sidebarSystems.c.now].show.toggleClass("on");
								sidebarSystems.c.now = "";
							});
							// ポップアップ stopPropagation設定
							sidebarSystems.cache[sidebarSystems.c.now].popup.click(function(event) {
								event.stopPropagation();
							});
							//ポジションリセット
							setPosition();
							// 表示処理
							root.append(sidebarSystems.cache[sidebarSystems.c.now].popup)
							//ブランド項目のタブにイベント設定
							$('#ui-tab > ul').tabs();
						 }
						// ポップアップイベントここまで
						return false;
					});

					/*
					//GETから選択済みの項目選択
					if(sidebarSystems.c.selectedPsscId["pssc_id"]){
						//sidebarSystems.var_dump(sidebarSystems.c.selectedPsscId);
						var IdList = {};
						
						IdList[text] = new Array;
						$.each(data[text], function(i,val){
							Array.prototype.push.apply(IdList[text], this["pssc_id"]);
						});
						
						if(sidebarSystems.c.selectedPsscId["pssc_id"]["i"]){
							
							$.each(sidebarSystems.c.selectedPsscId["pssc_id"]["i"], function(i,val){
								if($.inArray(val, IdList[text]) != "-1"){
									obj.trigger("click");
									sidebarSystems.psscFunc.include(this);
									obj.trigger("click");
								}
							});
						};
						/*
						if(sidebarSystems.c.selectedPsscId["pssc_id"]["e"]){
							$.each(sidebarSystems.c.selectedPsscId["pssc_id"]["e"], function(){
								if($.inArray(val, IdList[text]) != "-1"){
									obj.trigger("click");
									sidebarSystems.psscFunc.include(this);
									sidebarSystems.psscFunc.exclude(this)
									obj.trigger("click");
								}
							});
						}
						
					};
					*/
				});
			}).error(function(){
				//AJAXエラー時の処理
				//alert("err");
			});

;			
		}
	},
	
	//ディスプレイエリア
	display_area : {
		
		//ディスプレイエリアXボタン機能
		x_button_func: function (i, cached) {
			switch (sidebarSystems.cache[cached].psscLists[i].attr('class')) {
				case "included":
					sidebarSystems.psscFunc.include_d(i, cached);
					break;
				case "excluded":
					sidebarSystems.psscFunc.exclude_d(i, cached);
					break;
			};
			return false;
		},
		
		//ディスプレイエリアset
		set : function(){
			sidebarSystems.display_area.current_num 		= $("#current_num");
			sidebarSystems.display_area.display_area 		= $("#display_area");
			sidebarSystems.display_area.include_selected 	= $("#include_selected");
			sidebarSystems.display_area.exclude_selected 	= $("#exclude_selected");
			//ディスプレイエリアクリック時にpopup閉じる動作をキャンセル
			sidebarSystems.display_area.display_area.click(function(event) {
				return false;
			});
		}
	},
	
	
	//オンロード時に実行
	onload : function() {
		//ディスプレイエリアセット
		sidebarSystems.display_area.set(sidebarSystems.c.now);
		//検索項目セット済みか調査してデータ取得
		//sidebarSystems.psscFunc.getJsonData();
		// サイドバーポップアップセット
		sidebarSystems.popup.set();
	}
};

$(
	function() {
		//システム起動
		sidebarSystems.onload();
	}
);
