// JavaScript Document

/* ===============================================
  ロールオーバー
  
  <img />,<input type="image" />タグに「class="rover"」とつけると
  「～～.gif」,「～～,jpg」を「～～_on.gif」,「～～_on,jpg」に切り替える。
=============================================== */

function init() {
	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; }});
	});

}



function parseHash(str){
	if(str.indexOf("#")==0 && str.length > 1){
		return str;
	}else{
		return null;
	}
}

/* ===============================================
  メニューアクティブ
  
  画面ロード時にimgタグを_onの付いた画像に張り替える
=============================================== */

function Menu_active(id){
	var target_img = "#"+id;
	$(target_img).each(function(i) {
	
		var 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;
		});
	});
	
}

/* ===============================================
  メニューアクティブ化(テキスﾄ)
  
  画面ロード時にliタグ or ddタグにクラス[on]を追加する
=============================================== */
	function localMenu_active(id){
		if(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");
			});
		}
	}
	
/* ===============================================
  スムーススクロール
  
  アンカーリンクをエフェクトしながら動く
=============================================== */
	function SmoothnessScroll(){
		$('a[href^="#"]').click(function(){
			$(this).scrollTo(500);
			return false;
		});
	}
	
	jQuery.fn.extend({
		scrollTo : function(speed, easing){
			if(!$(this)[0].hash || $(this)[0].hash == "#"){
				return false;
			}
			return this.each(function() {
				var targetOffset = $($(this)[0].hash).offset().top;
				$('html,body').animate({scrollTop: targetOffset}, speed, easing);
			});
		}
	});

/* ===============================================
  input,textareaタグをフィーカスする
  
  input,textareaタグにカーソルが乗ると、[input-focus]クラス名が追加される。
  デフォルト時は[input-usually]が自動的に追加される。
=============================================== */
	function InputFocus(){
		$('input[type=text],input[type=password]').addClass('input-usually');
		$('.input-usually').focus(function(){
			$(this).addClass('input-focus');
		});
		$('.input-usually').blur(function(){
			if($(this).find('.input-focus')){
				$(this).removeClass('input-focus');
			}
		});
	}

/* ===============================================
  各関数を実行する。
=============================================== */
$(document).ready(function(){
	init();
	//スムーススクロール
	SmoothnessScroll();
	//inputフォーカス
	InputFocus();
});

$.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() {
		$('.tabArea').each(function(){
			var f = $.auto.tabs.click;
			var group = this;
			$('.tabList li', group).each(function(){
				$(this).css("cursor","pointer");
				this.group = group;
				$(this).click(f);
				$('#'+this.id+'Box').hide();
			}).filter(':first').trigger('click');
		});
	},
	click: function(){
		var tab = $('#'+this.id+'Box').get(0);
		$('.tabList li', this.group).each(function(){
			$(this).removeClass('on');
			$('#'+this.id+'Box').hide();
		});
		$(".tabList 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(".gif","_on.gif"));
		$(this).addClass('on');
		$(tab).fadeIn("slow");
		this.blur();
		return false;
	}
};


