// JavaScript Document
jQuery(document).ready(function(){
	//画像ロールオーバー
	jQuery(".rollover").each(function(){
		this.orgsrc=jQuery(this).attr("src");
		if ((n = this.orgsrc.lastIndexOf(".")) != -1) {
			ext = this.orgsrc.substring(n);
		}
		this.newsrc=this.orgsrc.replace(ext, "_on"+ext);
		var newimg=new Image();
		newimg.src=this.newsrc;
		
		$(this).hover(
			function(){
				jQuery(this).attr("src",this.newsrc);
			},
			function(){
				jQuery(this).attr("src",this.orgsrc);
			}
		)
	});
	
	//文字サイズ変更
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
	
	jQuery('a').click(function() {
		var jumpTo = jQuery(this).attr('href');
		if(jumpTo == '#top') {
			$('html,body').animate({ scrollTop: 0 }, 'slow')
			return false;
		}
		else if(jumpTo == '#') {
			return false;
		}
		else if(jumpTo.charAt(0) == '#') {
			$('html,body').animate({ scrollTop: jQuery(jumpTo).offset().top }, 'normal')
			return false;
		}
	});
	
	
	$(".side-history dt:gt(0),.side-history dd:gt(0),.side-recent dt:gt(0),.side-recent dd:gt(0)").hide();
	
	$(".side-history .expand-btn").click(function(){
		$(".side-history dt:gt(0),.side-history dd:gt(0)").slideToggle("slow");
	});
	$(".side-recent .expand-btn").click(function(){
		$(".side-recent dt:gt(0),.side-recent dd:gt(0)").slideToggle("slow");
	});


	$(".keyword-menu-head a").each(function(){
		this.orgsrc=$(this).find("img").attr("src");
		if ((n = this.orgsrc.lastIndexOf(".")) != -1) {
			ext = this.orgsrc.substring(n);
		}
		this.newsrc=this.orgsrc.replace(ext, "_on"+ext);
		var newimg=new Image();
		newimg.src=this.newsrc;
		this.isVisible=false;
		this.targetObj=$(this).attr("rel")+" .keyword-menu-body";
		
		
		
		$(this).click(function(){
			$(this.targetObj).slideToggle("slow");
			if(this.isVisible)
				$(this).find("img").attr("src",this.orgsrc);
			else
				$(this).find("img").attr("src",this.newsrc);
			this.isVisible=!this.isVisible;

			return false;
		});
	});
	$("#monthCheckSpring").change(function(){
		$("#monthCheck3").attr("checked",$(this).attr("checked"));
		$("#monthCheck4").attr("checked",$(this).attr("checked"));
		$("#monthCheck5").attr("checked",$(this).attr("checked"));
	});
	$("#monthCheckSummer").change(function(){
		$("#monthCheck6").attr("checked",$(this).attr("checked"));
		$("#monthCheck7").attr("checked",$(this).attr("checked"));
		$("#monthCheck8").attr("checked",$(this).attr("checked"));
	});
	$("#monthCheckAutumn").change(function(){
		$("#monthCheck9").attr("checked",$(this).attr("checked"));
		$("#monthCheck10").attr("checked",$(this).attr("checked"));
		$("#monthCheck11").attr("checked",$(this).attr("checked"));
	});
	$("#monthCheckWinter").change(function(){
		$("#monthCheck12").attr("checked",$(this).attr("checked"));
		$("#monthCheck1").attr("checked",$(this).attr("checked"));
		$("#monthCheck2").attr("checked",$(this).attr("checked"));
	});
	
	$("#areaCheck1").change(function(){
		$("#prefCheck1").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck2").change(function(){
		$("#prefCheck2").attr("checked",$(this).attr("checked"));
		$("#prefCheck3").attr("checked",$(this).attr("checked"));
		$("#prefCheck4").attr("checked",$(this).attr("checked"));
		$("#prefCheck5").attr("checked",$(this).attr("checked"));
		$("#prefCheck6").attr("checked",$(this).attr("checked"));
		$("#prefCheck7").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck3").change(function(){
		$("#prefCheck8").attr("checked",$(this).attr("checked"));
		$("#prefCheck9").attr("checked",$(this).attr("checked"));
		$("#prefCheck10").attr("checked",$(this).attr("checked"));
		$("#prefCheck11").attr("checked",$(this).attr("checked"));
		$("#prefCheck12").attr("checked",$(this).attr("checked"));
		$("#prefCheck13").attr("checked",$(this).attr("checked"));
		$("#prefCheck14").attr("checked",$(this).attr("checked"));
		$("#prefCheck15").attr("checked",$(this).attr("checked"));
		$("#prefCheck16").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck4").change(function(){
		$("#prefCheck17").attr("checked",$(this).attr("checked"));
		$("#prefCheck18").attr("checked",$(this).attr("checked"));
		$("#prefCheck19").attr("checked",$(this).attr("checked"));
		$("#prefCheck20").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck5").change(function(){
		$("#prefCheck21").attr("checked",$(this).attr("checked"));
		$("#prefCheck22").attr("checked",$(this).attr("checked"));
		$("#prefCheck23").attr("checked",$(this).attr("checked"));
		$("#prefCheck24").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck6").change(function(){
		$("#prefCheck25").attr("checked",$(this).attr("checked"));
		$("#prefCheck26").attr("checked",$(this).attr("checked"));
		$("#prefCheck27").attr("checked",$(this).attr("checked"));
		$("#prefCheck28").attr("checked",$(this).attr("checked"));
		$("#prefCheck29").attr("checked",$(this).attr("checked"));
		$("#prefCheck30").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck7").change(function(){
		$("#prefCheck31").attr("checked",$(this).attr("checked"));
		$("#prefCheck32").attr("checked",$(this).attr("checked"));
		$("#prefCheck33").attr("checked",$(this).attr("checked"));
		$("#prefCheck34").attr("checked",$(this).attr("checked"));
		$("#prefCheck35").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck8").change(function(){
		$("#prefCheck36").attr("checked",$(this).attr("checked"));
		$("#prefCheck37").attr("checked",$(this).attr("checked"));
		$("#prefCheck38").attr("checked",$(this).attr("checked"));
		$("#prefCheck39").attr("checked",$(this).attr("checked"));
	});
	$("#areaCheck9").change(function(){
		$("#prefCheck40").attr("checked",$(this).attr("checked"));
		$("#prefCheck41").attr("checked",$(this).attr("checked"));
		$("#prefCheck42").attr("checked",$(this).attr("checked"));
		$("#prefCheck43").attr("checked",$(this).attr("checked"));
		$("#prefCheck44").attr("checked",$(this).attr("checked"));
		$("#prefCheck45").attr("checked",$(this).attr("checked"));
		$("#prefCheck46").attr("checked",$(this).attr("checked"));
		$("#prefCheck47").attr("checked",$(this).attr("checked"));
	});
});



$(window).unload(function(){
  var title = getActiveStyleSheet();
  createCookie("style", title, 0);
});


function setActiveStyleSheet(title) {
	jQuery("link[rel*='stylesheet'][title]").each(function(){
		this.disabled = true;
		this.disabled = jQuery(this).attr("title")!=title;
	});
}


function getActiveStyleSheet() {
	var titlename = null;
	jQuery("link[rel*='stylesheet'][title]").each(function(){
	if(!this.disabled)
		titlename = jQuery(this).attr("title");
	});
	return titlename;
}


function getPreferredStyleSheet() {
	var titlename = null;
	jQuery("link[rel^='stylesheet'][title]").each(function(){
		titlename = jQuery(this).attr("title");
	});
	return titlename;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function popup(href){
	window.open(href, 'popup', 'width=600, height=620, menubar=yes, toolbar=yes, scrollbars=yes');
}
