
$(function() {

	setFontSizeChanger('#contents');
	rollover();
	columnset();

	$("ul.list_fix").each(function(){
		$("> li", this).flatWidth();
	});

	$("#contents a.blank, .leftmenu a.blank").attr("target","_blank").append("<span class=\"blankicon\"></span>");


	$("#tabs").each(function(){

		if ($(this).is(".infosearch")) {
			var infoitems = $(this).next().find("dl.info_list");
			var infosearch = 1;
		}

		$("> li > a[href*=#]", this).click(function(){

			$("#tabs > li > a.tab_on").each(function(){
				cid = $("#tabs > li > a.tab_on").attr("href").split("#")[1];
				$("#tabs > li > a.tab_on").removeClass("tab_on");

				if (infosearch) {
					if (cid == "all") {
						$("> *" ,infoitems).hide();
					} else {
						$("."+cid, infoitems).hide().next().hide();
					}
				} else {
					$("#"+cid).hide();
				}

			});
			cid = $(this).attr("href").split("#")[1];

			if (infosearch) {
				if (cid == "all") {
					$("> *:hidden" ,infoitems).show();
				} else {
					$("."+cid, infoitems).show().next().show();
				}
			} else {
				$("#"+cid).show();
			}

			$(this).addClass("tab_on");

			$("#tabs.service").toggleClass("border_red", $("#tabs.service > li:eq(0) > a").hasClass("tab_on"));
			selffontsizechange();

			return false;
		});

		$("> li > a[href*=#]", this).each(function(){
			cid = $(this).attr("href").split("#")[1];

			if (infosearch) {
				$("> *" ,infoitems).hide();
			} else {
				$("#"+cid).hide();
			}

		});
		if ($("> li > a", this).is("[href=#" + document.URL.split("#")[1] +"]")) {
			$("> li > a:[href=#" + document.URL.split("#")[1] +"]", this).click();
		} else {
			$("> li:eq(0) > a[href*=#]", this).click();
		}
	});

	$(".floatimagebox").each(function(){
		$(this).css("padding-left",$("img.floatimage", this).width()+10);
		$("img.floatimage", this).css("margin-left", 0 - ($("img.floatimage", this).width()+10));
	});

	$("#leftmenu_rightbanner #main > div").flatHeights();

	$("#sitemap #contents ul").each(function(){
		$("> li", this).flatHeights();
	});
});

function columnset(){
	var sets = [], temp = [];

	/* div要素を2つずつの組に分ける */
	$('div.column2').each(function() {
		$('div.column', this).each(function(i) {
			temp.push(this);
			if (i % 2 == 1) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);
		temp = [];
	});

	temp = [];

	$('dl.link').each(function() {
		$('> *', this).each(function(i) {
			temp.push(this);
			if (i % 2 == 1) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);
		temp = [];
	});

	/* 各組ごとに高さ揃え */
	$.each(sets, function() {
		$(this).flatHeights();
	});
}

function rollover() {
	var image_cache = new Object();
	$('[src*=_roll.]').not("[src*='_on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}

$(function(){
	if (document.URL.match(/\?print$/)) {
		$('link[media="print"]').attr({media: "all"});
	}
});

function setFontSizeChanger(target){
	$('#fontsize').show();

	$("#fontsize a").click(function(){
		var fontsize = $(this).parent("dd").attr("id").split("_")[1];
		$(target).attr("class","fontsize_"+fontsize);
		$.cookie('fontsize', fontsize, { expires:30, path:'/' });
		$('#fontsize').attr("class","fontselect_"+fontsize);
		selffontsizechange();
		return false;
	});

	var fontsize = $.cookie('fontsize');
	if (fontsize == null) {fontsize = "medium";}
	$(target).addClass("fontsize_" + fontsize);
	$('#fontsize').attr("class","fontselect_"+ fontsize);

}

function selffontsizechange(){
	$.each($.changeLetterSize.handlers, function(i, handler) {
		handler();
	});
}


