// JavaScript Document

// ロールオーバー
function initRollOverImages() {
	var image_cache = new Object();
	$("img.rover,input.rover").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_ro;
		$(this).hover(function(){
			if(!$(this).hasClass("active")){
				this.src = imgsrc_ro;
			}
		},function(){
			if(!$(this).hasClass("active")){
				this.src = imgsrc;
			}
		});
	});
}

$(document).ready(initRollOverImages);

//メニューアクティブ化
//画面ロード時にimgタグを_onの付いた画像に張り替える
function Menu_active(id){
	var target_img = "img#"+id;
	$(target_img).each(function(i) {
		dot = this.src.lastIndexOf('.');
    	var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		this.src = imgsrc_ro;
		//既に割り当てられているロールオーバー関数を上書き
		$(this).hover(function(){
			this.src = imgsrc_ro;
		},function(){
			this.src = imgsrc_ro;
		});
	});
}

//メニューアクティブ化(テキスﾄ)
//画面ロード時にclass="on"をつける
function localMenu_active(id){
	var target_img = "li#"+id;
	$(target_img).each(function(i){
		$(this).addClass("on");
	});
	var target_img = "dd#"+id;
	$(target_img).each(function(i){
		$(this).addClass("on");
	});
}

//form フォーカス
function InputFocus(){
	$('input[type=text]').addClass('input-text');
	$('input[type=text],textarea').focus(function(){
		$(this).addClass('focus');
	});
	$('input[type=text],textarea').blur(function(){
		if($(this).find('.focus')){
			$(this).removeClass('focus');
		}
	});
}
$(document).ready(InputFocus);



// タブ切り替え

//Index:Tab

$.auto={
	init:function(){
		for (module in $.auto) {
			if($.auto[module].init)
			$.auto[module].init();
		}
	}
};

$(document).ready($.auto.init);


// Switches tabs on click
$.auto.tabs = {
	init: function() {
		$('.Tabchange').each(function(){
			var f = $.auto.tabs.click;
			var group = this;
			$('.tab li,', group).each(function(){
				$(this).css("cursor","pointer");
				this.group = group;
				$(this).click(f);
				$('#'+this.id+'Tabchange').hide();
			}).filter(':first').trigger('click');
		});
	},

	click: function(){
	var tab = $('#'+this.id+'Tabchange').get(0);
		$('.tab li,', this.group).each(function(){
			$(this).removeClass('on');
			$('#'+this.id+'Tabchange').hide();
		});
		$(".tab img").each(function(){
			this.src=this.src.replace("_on","");
			if($(this).hasClass("active")){
				$(this).removeClass("active");
			}
		});

		$(this).find("img").addClass("active");
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace(".jpg","_on.jpg"));
		$(this).addClass('on');
		$(tab).show();
		this.blur();

		return false;

	}

};

