jQuery(function($){

	//ロールオーバー処理
	var postfix = '_on';
	$('.btn_over').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
							 + postfix
							 + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {
			img.attr('src', src_on);
		}, function() {
			img.attr('src', src);
		});
	});
	
	$('.btn_trans').each(function() {
		var img = $(this);
		img.hover(function() {
			img.css({"filter":"alpha(opacity=60)","-moz-opacity":"0.6","opacity":"0.6"});
		}, function() {
			img.css({"filter":"alpha(opacity=100)","-moz-opacity":"1","opacity":"1"});
		});
	});

	//高さ揃え
	
	/* div要素を2つずつの組に分ける */
	var fh_sets2 = [], fh_temp2 = [];
	$('#block_category > .box').each(function(i) {
		fh_temp2.push(this);
		if (i % 2 == 1) {
			fh_sets2.push(fh_temp2);
			fh_temp2 = [];
		}
	});
	if (fh_temp2.length) fh_sets2.push(fh_temp2);
	/* 各組ごとに高さ揃え */
	$.each(fh_sets2, function() {
		$(this).flatHeights();
	});
	
	/* div要素を3つずつの組に分ける */
	var fh_sets3 = [], fh_temp3 = [];
	$('.flatheightbox > dl > dd, ul.block_products > li').each(function(i) {
		fh_temp3.push(this);
		if (i % 3 == 2) {
			fh_sets3.push(fh_temp3);
			fh_temp3 = [];
		}
	});
	if (fh_temp3.length) fh_sets3.push(fh_temp3);
	/* 各組ごとに高さ揃え */
	$.each(fh_sets3, function() {
		$(this).flatHeights();
	});
	

	//インプット補助プラグイン
	$.fn.inputAssist=function(assist_txt){
		var $t=$(this),txtColor=$("body").css("color"),bool=false;
		$t.val(assist_txt).css("color","#999");
		$t.focus(function(){if(! bool)$t.val("").css("color",txtColor);});
		$t.blur(function(){if(! $t.val()){$t.val(assist_txt).css("color","#999");bool=false;}});
		$t.keydown(function(){bool=true})
	};
	$("input#sitesearch_inputbox").inputAssist("検索語句を入力");
	$("input#tenposearch_inputbox").inputAssist("高知");
	$("input#tenponumsearch_inputbox").inputAssist("103");

	//ラジオボタン表示非表示
	$.fn.selectedCheck=function(){
		var $t=$(this),$p=$("div#select_tenpoatm").find("p");
		var first_class=$p.eq(0).find("input").val();
		display_elm(first_class);
		function display_elm(class_name){
			$t.find("p").not($t.find("p."+class_name)).hide();
			$t.find("p."+class_name).show();
		}

		$p.find("input").click(function(){
			var selected_class=$(this).val();
			display_elm(selected_class);
		});

	};
	$("div#selected_check").selectedCheck();
	

	//セレクタに正規表現を利用するプラグイン
	$.expr[':'].regex = function(elem, index, match) {
		var matchParams = match[3].split(','),
		validLabels = /^(data|css):/,
		attr = {
			method: matchParams[0].match(validLabels) ? 
			matchParams[0].split(':')[0] : 'attr',
			property: matchParams.shift().replace(validLabels,'')
		},
		regexFlags = 'ig',
		regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
		return regex.test(jQuery(elem)[attr.method](attr.property));
	}

	//ページ内スクロール
	$.fn.pageScroll=function(){
		var $t=$(this);
		$t.click(function(){
			var Hash=$(this.hash),HashOffset=$(Hash).offset().top;
			$("html,body").animate({
				scrollTop: HashOffset
			},800,"easeOutQuart");
			return false;
		});
	}
	$("a:regex(href,^#[a-z,A-Z])").pageScroll();
	
	//「四国銀行について」ページ ローカルナビ
	$("#profilemenu h3").click(function(){
		$(this).next().slideToggle();
	})
	
	//外部リンク時にアラートを出す
	$(".externallinkalert").click(function(){
		var message = $(this).attr("title");
		if(window.confirm(message)){
			return true;
		}else{
			return false;
		}
	});


});


