$(function(){
	
	// 初期値を定義
	var selected = $("div#wrapper div#content div#mid div.main ul li:first-child a").attr("href");
	
	// URL中のハッシュ文字列をtargetとしてselecterに渡す
/*
	function loaded(){
		d = document.URL;
		// #を探して、それ以降を切り取る
		d = d.substr(d.indexOf("#"),d.length);
		// #で始まる文字列がない場合は初期値を渡す
		if(d.lastIndexOf("#") == -1){
			selecter(selected);
		}else{
			selecter(d);
		}
	}
*/
	
	// URL中のディレクトリを識別してサイドメニューを移動
	function sideselect(){
		var d = document.URL;
		d = d.substring(d.indexOf(".jp/")+4,d.lastIndexOf("/"));
		slide = $("div#wrapper div#side div#cat div.mid div#slider ul.slide");
		switch(d){
			case "industry":
				$("#slider").easySlider(0);
				slide.css("margin-left","0");
				break;
			case "school":
				$("#slider").easySlider(1);
				slide.css("margin-left","-233px");
				break;
			case "locate":
				$("#slider").easySlider(2);
				slide.css("margin-left","-466px");
				break;
			case "zodiac":
				$("#slider").easySlider(3);
				slide.css("margin-left","-699px");
				break;
			case "sports":
				$("#slider").easySlider(4);
				slide.css("margin-left","-932px");
				break;
			default:
				$("#slider").easySlider(0);
				break;
		}
	}
	
	// クリックされたa要素のhref属性をそのままselecterに渡す
/*
	$("div#wrapper div#content div#mid div.main ul.left li a").click(function(){
		selecter($(this).attr("href"));
		return false;
	});

	
	// 渡された引数に該当するタブを表示

	function selecter(e){
		if(e){
			filename = e.slice(1, e.length);
			$("div#wrapper div#content div#mid div.main ul.right li").remove();
			$("div#wrapper div#content div#mid div.main ul.left li a[href=" + selected + "]").parent().removeClass("selected");
			
			$("div#wrapper div#content div#mid div.main ul.right").load("subfile/" + filename + ".html");
			$("div#wrapper div#content div#mid div.main ul.left li a[href=" + e + "]").parent().addClass("selected");
			selected = e;
		}
	}
*/

	// パラメータ名がクリックされても反応しない
	$("div#wrapper div#content.company div#mid div#tab > div.param dl dt a").click(function(){
		return false;
	});
	
	// パラメータ名にオンマウスで説明文を表示・非表示
	$("div#wrapper div#content.company div#mid div#tab > div.param dl dt a").hover(function(){
		$("div#wrapper div#content.company div#mid div#tab > div.param div.graph img").hide();
		$("div#wrapper div#content.company div#mid div#tab > div.param div.graph div" + $(this).attr("href")).show();
	},
	function(){
		$("div#wrapper div#content.company div#mid div#tab > div.param div.graph img").show();
		$("div#wrapper div#content.company div#mid div#tab > div.param div.graph div" + $(this).attr("href")).hide();
	});
	
	
	$("div#wrapper div#content.company div#top-more div#r.clip div p.marici").hover(
		function(){
			$(this).hide();
			$("div#wrapper div#content.company div#top-more div#r.clip div p.summary").show();
			$("div#wrapper div#content.company div#top-more div#r.clip div p.marici-pb").hide();
			$("div#wrapper div#content.company div#top-more div#r.clip h3").css(
				"background-image","url(../../img/bg_clip_top_business.png)"
			);
		}
	);
	
	$("div#wrapper div#content.company div#top-more div#r.clip div p.summary").hover(
		function(){
		},
		function(){
			$(this).hide();
			$("div#wrapper div#content.company div#top-more div#r.clip div p.marici").show();
			$("div#wrapper div#content.company div#top-more div#r.clip div p.marici-pb").show();
			$("div#wrapper div#content.company div#top-more div#r.clip h3").css(
				"background-image","url(../../img/bg_clip_top_kkp.png)"
			);
		}
	);

	
	
	// QRコードを発行
	function putQR(){
		var d = document.URL;
		d = d.replace("t.kmonos.jp","m.kmonos.jp");
		d = d.replace("_tab2","");
		d = d.replace("_tab3","");
		gc = '<div><img src="http://chart.apis.google.com/chart?chld=Q|0&chs=70x70&cht=qr&chl=' + d + '" /></div>';
		$("div#wrapper div#side div#bnr_mobile").html(gc);
	}
	
	$("div#wrapper div#side div#bnr_mobile").click(function(){
		var d = document.URL;
		d = d.replace("t.kmonos.jp","m.kmonos.jp");
		d = d.replace("_tab2","");
		d = d.replace("_tab3","");
		window.open('../../mobileform.php?url='+d, 'mobileform', 'width=400, height=440, menubar=no, toolbar=no, scrollbars=yes');
	});
	
	
	// URL判定関数をページ読み込み後に実行
	//loaded();
	sideselect();
	
	//
	putQR();
	
	
	/* Van - Button
	++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	
	var van_selected = "map";
	var ctime = 100;
	
	$("div#wrapper.van div#content div#inside div.btns a").click(function(){
		var van_clicked = $(this).attr("id");
		
		$("div#wrapper.van div#content div#inside div.btns a#" + van_selected).removeClass("active");
		$("div#wrapper.van div#content div#inside div.btns a#" + van_clicked).addClass("active");
		
		$("div#wrapper.van div#content div#inside div#" + van_selected).fadeOut(ctime);
		$("div#wrapper.van div#content div#inside div#" + van_clicked).fadeIn(ctime);
		van_selected = van_clicked;
		return false;
	});
	
	/* Van - Map
	++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	var map_selected = "u01";
	var map_fa = true;
	
	$("div#wrapper.van div#content div#inside div#map > a").click(function(){
			
		var map_clicked = $(this).attr("class");
		var tgt = $(this).parent().children("div.pop");
		var tgt_lic = tgt.find("ul li." + map_clicked);
		var tgt_lis = tgt.find("ul li." + map_selected);
		
		if(map_fa){
			tgt.fadeIn(ctime);
			tgt_lic.fadeIn(ctime);
			map_selected = map_clicked;
			map_fa = false;
		}else{
			if(map_selected != map_clicked){
				tgt_lis.fadeOut(ctime);
				tgt_lic.fadeIn(ctime);
				map_selected = map_clicked;
			}else{
				tgt_lis.fadeOut(ctime);
				tgt.fadeOut(ctime);
				map_fa = true;
			}
		}
		
		return false;
	});

	/* Van - Town
	++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	var town_selected = "u01";
	var town_fa = true;
	
	$("div#wrapper.van div#content div#inside div#town > a").click(function(){
		
		var town_clicked = $(this).attr("class");
		var tgt = $(this).parent().children("div.pop");
		var tgt_lic = tgt.find("ul li." + town_clicked);
		var tgt_lis = tgt.find("ul li." + town_selected);
		
		if(town_fa){
			tgt.fadeIn(ctime);
			tgt_lic.fadeIn(ctime);
			town_selected = town_clicked;
			town_fa = false;
		}else{
			if(town_selected != town_clicked){
				tgt_lis.fadeOut(ctime);
				tgt_lic.fadeIn(ctime);
				town_selected = town_clicked;
			}else{
				tgt_lis.fadeOut(ctime);
				tgt.fadeOut(ctime);
				town_fa = true;
			}
		}
		
		return false;
	});

	
});


/* Maps API v3
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

function load(lat, lng, com) {
	var latlng = new google.maps.LatLng(lat, lng);
	var myOptions = {
		zoom: 15,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		scrollwheel: false,
		navigationControl: true,
		disableDefaultUI: true
	};
	
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var infowindow = new google.maps.InfoWindow({
		content: com
	});
	
	var marker = new google.maps.Marker({
		position: latlng,
		map: map,
		title: com
	});
	
	infowindow.open(map,marker);
	
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
}
