//読み込み時の処理(初期設定)
$(function(){
	
	//---------------------------
	// 初期設定
	//---------------------------
	
	test_mode=false;
	test_level=0;
	shadow=true;//影をいれるか
	
	test_dir="search";
	footer_add_str="-footer";//フッター用のコンテナに付加する文字列
	hf_add_str_array=new Array();
	hf_add_str_array["header"]="";
	hf_add_str_array["footer"]=footer_add_str;
	
	show_speed=500;
	hide_speed=250;
	header_phase="";//ヘッダーミニメニュー用の現在のフェーズ格納用
	footer_phase="";//フッターミニメニュー用の現在のフェーズ格納用
	
	loaded_flag=new Array();//コンテンツをロードしたかのフラグ
	loaded_flag["area"]=0;
	loaded_flag["type"]=0;
	loaded_flag["particular"]=0;
	loaded_flag["freeword"]=0;

	//キャプション用テキスト
	caption_text=new Array();
	caption_text["area"]=new Array();
	caption_text["area"]["title"]="地域検索";
	caption_text["area"]["content"]="遊びたい地域が決まってるならこちら";
	caption_text["type"]=new Array();
	caption_text["type"]["title"]="業種検索";
	caption_text["type"]["content"]="遊びたい業種が決まってるならこちら";
	caption_text["particular"]=new Array();
	caption_text["particular"]["title"]="こだわり検索";
	caption_text["particular"]["content"]="こだわりがあるならこちら";
	caption_text["freeword"]=new Array();
	caption_text["freeword"]["title"]="フリーワード検索";
	caption_text["freeword"]["content"]="キーワードで検索";

	//コンテナの高さ用配列
	height_array=new Array();
	height_array["area"]=680;
	height_array["type"]=700;
	height_array["particular"]=650;
	height_array["freeword"]=150;

	//ボタンのスタイル
	default_search_btn_style={border:"3px solid black"}
	selected_search_btn_style={border:"3px solid white"}
		
		
	if(ini_phase!=null){
		//alert("ini_phaseあり");
		captionChange(ini_phase);
		//$(".return-search").hide();
	}else{
		//alert("ini_phaseなし");
		$(".search-caption").hide();
		hideAll();
		//alert("hideAll");
		$(".return-search").show();
		$(".return-search").click(function(){
			//alert(loaded_phase);
			parent_id=$(this).attr("id");
			var hf=parent_id.replace("return-search-","");
			//alert(hf);
			loadAction(loaded_phase,hf);
	 	});
	}

/*
	//---------------------------
	// SWF作成準備
	//---------------------------
	var att = { data:'/'+test_dir+"/area/swf/area.swf", width:"780", height:"550" };
	var par = { menu:"false" };
	
	//swfを作成したかのフラグ
	create_area_swf_flag=new Array();
	create_area_swf_flag["header"]=false;
	create_area_swf_flag["footer"]=false;
	*/

	//---------------------------
	// リスト色変更
	//---------------------------
	//alert("fade");
	//default_list_opacity=0.85;
	//$("ul.result li").fadeTo(0,default_list_opacity);
	//$("ul.result li").hover(
		//function(){
			//$(this).addClass("hover");
			//$(this).fadeTo(150,1);
			//$(this).animate({width:"92%"},100);
			//$(this).css("clear","both");
		//},
		//function(){
			//$(this).removeClass("hover");
			//$(this).fadeTo(150,default_list_opacity);
			//$(this).animate({"width":"46%"},100);
			//$(this).css("float","left");
		//}
	//);
	
	//---------------------------
	// ミニメニュー作成
	//---------------------------
	$(".mini-menu ul").lavaLamp({  
		fx: "easeOutQuint",  
		speed: 500,
		click: function(event, menuItem) {            
		return false;  
		}
	});
	
	mini_icon_default_alpha=0.8;
	$(".mini-menu a img").fadeTo(0,mini_icon_default_alpha);
	$(".mini-menu a img").hover(
	function(){
		$(this).fadeTo(0,1);
	},
	function(){
		$(this).fadeTo(200,mini_icon_default_alpha);
	});
	
	//---------------------------
	// キャプションに影作成
	//---------------------------
	if(shadow){
		$(".search-type-name .name").dropShadow({left:-4,top:-1,blur:0,color:'white',opacity:0.5});
	}
    
	//---------------------------
	// スライドコンテナ作成
	// DOM整理
	//---------------------------
	//指定したIDに空のコンテナを作成
	function slideDomCreate(id,add){
		selector=$(id);
		selector.html('<div id="area-container'+add+'"><div id="area-flash'+add+'"></div></div><div id="type-container'+add+'"></div><div id="particular-container'+add+'"></div><div id="freeword-container'+add+'"></div>');
	}
	slideDomCreate("#slide-container","");
	slideDomCreate("#slide-container-footer",footer_add_str);
	hideAll();
	
	// 隠すメソッド
	function customHide(object){
		object.slideUp(hide_speed);
	}
		
	// 表示メソッド
	function customShow(object){
		object.slideDown(show_speed);
	}
	
	// ヘッダーフッターをそれぞれ隠す
	function hideContainer(hf){
		add=hf_add_str_array[hf];
		selector=$("#area-container"+add+",#type-container"+add+",#particular-container"+add+",#freeword-container"+add);
		customHide(selector);
	}
	
	// 全て隠す
	function hideAll(){
		hideContainer("header");
		hideContainer("footer");
	}
	
	//上部ミニ検索ボタンを押した時
	minimenu_header_selector=$("#minimenu-header .btn_area,#minimenu-header .btn_type,#minimenu-header .btn_particular,#minimenu-header .btn_freeword");
	$(minimenu_header_selector).click(function(){
		commonBtnAction($(this),"header");
	});

	//下部ミニ検索ボタンを押した時
	minimenu_footer_selector=$("#minimenu-footer .btn_area,#minimenu-footer .btn_type,#minimenu-footer .btn_particular");
	$(minimenu_footer_selector).click(function(){
		commonBtnAction($(this),"footer");
	});
	
	//ミニ検索ボタンクリック共通処理
	function commonBtnAction(selector,hf){
		type_name=selector.attr("name");
		loadAction(type_name,hf);
	}
	
	//ミニ検索ボタンホバー
	minimenu_header_selector.hover(function(){
		commonBtnHoverAction($(this));
	});
	minimenu_footer_selector.hover(function(){
		commonBtnHoverAction($(this));
	});

	//ミニ検索ボタンホバー共通処理
	function commonBtnHoverAction(selector){
		type_name=selector.attr("name");
		captionChange(type_name);
	}

	//------------------------------------------
	//  ミニ検索ボタンを押した時の読み込み処理
	//------------------------------------------
	function loadAction(phase,hf){
		
		add=add=hf_add_str_array[hf];
		$("#"+phase+"-container"+add).css("height",height_array[phase]+"px");
		$("#include-area").hide();
		//alert('$("#include-area").fadeOut()');
		$(".return-search").fadeOut("slow");
		
		if(hf=="header"){
			phase_var=header_phase;//現在のフェーズ格納
			header_phase=phase;//ヘッダーフッダーそれぞれのフェーズを格納
		}else{
			phase_var=footer_phase;
			footer_phase=phase;
		}
		
		//今のフェーズでなければ読み込み処理
		if(phase_var!=phase){
			if(phase_var!=""){hideContainer(hf);}
			$(".btn_"+phase).css(selected_search_btn_style);
			container_str="#"+phase+"-container"+add;
			container_selector=$("#"+phase+"-container"+add);//コンテナ指定
			
			loadContent(phase);

			captionChange(phase);//キャプション変更
			customShow(container_selector);//読み込みエフェクト
			//returnTop();
			//alert("header_phase,footer_phase="+header_phase+","+footer_phase);
		}else{
			if(test_level>5) alert("今のフェーズなのでよみこみませんでした。phase_var="+phase_var+","+phase+"¥nheader_phase="+header_phase);
		}
	}
	
	//-------------------------------
	// ロードするメソッド（業種・こだわり）
	//-------------------------------
	function loadContent(phase){
		
		//読み込みをしていないか、コンテナが空のときに読み込み処理をおこなう
		if(loaded_flag[phase]==0 || container_selector.html()==""){
			if(ini_phase==phase){
				//最初から読み込んであるコンテンツであれば内容をコピーする
				container_selector.html($("#include-area").html());
				if(test_mode) alert('読み込まず内容をコピーしました。');
			}else{
				//var container_selector=$("#"+phase+"-container");
				var load_file_name='/'+test_dir+'/'+phase+'/'+phase+'.php';
				container_selector.load(load_file_name,{jqload:true});//UTFでロードするため引数を渡す。
				if(test_mode) alert("ロード処理行いました。");
			}
			loaded_flag[phase]=1;//フラグを立てる
		}
	}
	
	//-------------------------------
	//キャプションの内容を変更する
	//-------------------------------
	function captionChange(type_name){
		if(ini_phase!=null){
			$(".search-caption:hidden").fadeIn("fast");
			caption_title=caption_text[type_name]["title"];
			$(".search-type-name .name").text(caption_title);
			caption_content=caption_text[type_name]["content"];
			$(".search-caption .content").text(caption_content);
		}
	}
	
	//読み込み時のアクション
	/*
	if(ini_phase!=null){
		loadAction(ini_phase,"header");
	}else{
		//指定無しの場合はキャプションを隠す。
		$(".caption").hide();
	}
	if(ini_phase=="area"){
		swfobject.createSWF(att, par, "area-flash-header");
		loadAction(ini_phase,"header");
	}
	*/
	
	//上にスクロールで戻る
	function returnTop(){
		$('html,body').animate({ scrollTop: 0 }, 1000,'easeOutQuart');
	}
	
	
    
	//---------------------------
	//アイコン説明のtooltip表示処理
	//---------------------------
	$("#icon_explanation_tooltip").hover(function(){
		$("#tooltip").fadeIn("normal");
		},
		function(){
		$("#tooltip").fadeOut("normal");
		});
});
//ready終了



