/* 
 *
 *	settings.js
 *	jQuery 1.2.6 required
 *	
 *	tokuda@n-di.co.jp
 *
 */
 
$(function(){

	/* ImgReplace */
	function imgReplace(targetImg){
		var img = {}, preload = new Image();
		img.src = $(targetImg).attr("src");
		img.on = img.src.replace("_off","_on");
		preload.src = img.off;
		$(targetImg).hover(
			function(){$(this).attr("src",img.on)},
			function(){$(this).attr("src",img.src);}
		);
	}
	$("img[src*='_off']").each(function(){
		imgReplace(this);
	});
	
	/* Add Classes */
	$("body *:first-child").addClass("first-child");
	$("body *:last-child").addClass("last-child");
	$("table>tr,table>tbody>tr,ul>li,ol>li").filter(":even").addClass("odd");
	$("table>tr,table>tbody>tr,ul>li,ol>li").filter(":odd").addClass("even");

	$("li","ol,ul").each(function(){
		var index = $("li",$(this).parent()).index(this);
		$(this).addClass("index-"+(index+1));
	});
	
	/* Open new window */
	$("a[class*='external']").click(function(){
		window.open(this.href,"","");
		return false;
	});
	
	/* Extend telBox anchors */
	$(".telBox").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	}).click(function(){
		location.href = $("p.btn a",this).attr("href");
	}).css("cursor","pointer");
	
	/* Apply :hover and :focus */
	$("input,textarea").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	}).focus(function(){
		$(this).addClass("focus");
	}).blur(function(){
		$(this).removeClass("focus");
	});
	
	/* gNav Pulldown Menu */
	var footerMenus = $("dl","div#footer");
	for(var i=0;i<footerMenus.length;i++){
		if(i==2){
			var ul = document.createElement("ul");
			var menus = $("dd",footerMenus[i]);
			for(var j=0;j<menus.length;j++){
				var li = document.createElement("li");
				$(li).append($("a",menus[j]).clone());
				$(ul).hide().append(li);
			}
		}else{
			var ul = $("ul",footerMenus[i]).clone();
		}
		$(">li:nth-child("+(i+1)+")","div#header ul.gNav").append(ul).addClass("slideImg"+i);
		$(ul).addClass("slideMenu"+i).hide();
		$("li:last-child",ul).addClass("last-child");
	}
	$("li","div#header ul.gNav").each(function(){
		if($(this).attr("class").match(/slideImg/)){
			$(this).hover(function(){
				$("a",this).addClass("hover");
				$("ul",this).fadeIn(100);
			},function(){
				$("a",this).removeClass("hover");
				$("ul",this).fadeOut(150);
			});
		}
	});
	
	if($.fn.tabSwitch) $(".tabArea").tabSwitch();
	
});
