// JavaScript Document

// Initialization
$.auto = {
	init: function() {
		for (module in $.auto) {
			if ($.auto[module].init)
				$.auto[module].init();
		}
	}
};
$(document).ready($.auto.init);


//基本のロールオーバー
$.auto.hover = {
	init: function() {
		$('IMG.Hover')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},
	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},
	enter: function() {
		this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},
	exit: function() {
		this.src = this.src.replace(/^(.+)_over(\.[a-z]+)$/, "$1$2");
	}
};


//※以下の2種類のボタンについては画像のプリロードが未設定です（調整中）

//画像をプリロード
//function preload(Dir, imgs){
//	var d = document;
//	for(var i = 0; i< imgs.length; i++){
//		var imgObj = new Image();
//		imgObj.src = Dir+imgs[i];
////			alert(imgObj.src);
//	}
//}
//window.onload = function(){ preload("images/contents/", ["btnreset_down.gif","btnreset_over.gif","btnform_down.gif","btnform_over.gif","btnconfirm_down.gif","btnconfirm_over.gif"]) }


//各ページからフォームに飛ばすボタン classはjumpfで
$(function (){
			//フォーカス時の点線を消す
$('.jumpf').focus(
       function(){ $(this).blur() }
    );	
	//マウスが乗ったら…
	$('.jumpf').mouseover(function() {
		//up画像
		var upimgSrc1 = $(this).attr("src");
		//over画像
		var overimgSrc1 = upimgSrc1.replace("up", "over");
		//down画像
		var downimgSrc1 = upimgSrc1.replace("up", "down");
		//over画像に入れ替え
		$(this).attr("src", overimgSrc1);
		//念のためアップ画像をバックグラウンドに設定
		$(this).css("background-image", "url("+upimgSrc1+")");
		//マウスが押されたら…
		$(this).mousedown(function() {
			//down画像に入れ替え
			$(this).attr("src", downimgSrc1);
			//マウスアップしたら…
			$(this).mouseup(function() {
				//up画像に入れ替え
				$(this).attr("src", upimgSrc1);
			});
		});
		//マウスが外れたら…
		$(this).mouseout(function() {
			$(this).attr("src", upimgSrc1);
		});
	});
});		

//メールフォーム内各種ボタン
$(function (){
	//フォーカス時の点線を消す
    $('form :image').focus(
       function(){ $(this).blur() }
    );
	//マウスが乗ったら…
	$('form :image').mouseover(function() {
		//up画像
		var upimgSrc2 = $(this).attr("src");
		//over画像
		var overimgSrc2 = upimgSrc2.replace("up", "over");
		//down画像
		var downimgSrc2 = upimgSrc2.replace("up", "down");
		//over画像に入れ替え
		$(this).attr("src", overimgSrc2);
		//念のためアップ画像をバックグラウンドに設定
		$(this).css("background-image", "url("+upimgSrc2+")");
		//マウスが押されたら…
		$(this).mousedown(function() {
			//down画像に入れ替え
			$(this).attr("src", downimgSrc2);
			//マウスアップしたら…
			$(this).mouseup(function() {
				//up画像に入れ替え
				$(this).attr("src", upimgSrc2);
			});
		});
		//マウスが外れたら…
		$(this).mouseout(function() {
			$(this).attr("src", upimgSrc2);
		});
	});
});
