/*================================
 setting.js
 tokuda@n-di.co.jp
=================================*/

$(function() {
			  	
	/* body以下の要素のfirstChild(そのクラスにaccessGuideがあれば次の要素)にクラス(first-child)を付加 */
	$("body *:first-child").not("br").each(function(){
		if(this.className.match(/Guide/)){
			$(this).next().addClass("first-child");
		}else{
			$(this).addClass("first-child");
		}
	});
	$("body *:last-child").addClass("last-child");
	
	/* ロールオーバー */
	function rollOver(img){
		var src = img.attr("src");
		var overSrc = src.replace("_off","_on");
		var over = new Image();
		over.src = overSrc;
		img.hover(function(){
			img.attr("src",overSrc);
		},function(){
			img.attr("src",src);		
		});
	}
	$("img[src*='_off']").each(function(){rollOver($(this))});
	
	/* メイン下部のお問い合わせリンクの拡張 */
	function inqExt(){
		$("#inq").click(function(){
			location.href = $("p:last-child a",this).attr("href");
		}).hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		}).css("cursor","pointer");
	}
	//inqExt();
	
	/* スムーズスクロール */
	function getScrollPosition(){
		var obj = new Object();
		obj.x = document.body.scrollLeft || document.documentElement.scrollLeft;
		obj.y = document.body.scrollTop || document.documentElement.scrollTop;
		return obj;
	}

	$("p.pagetop a").click(function(){
		var y = getScrollPosition().y;
		var x = getScrollPosition().x;
		var timer = setInterval(
			function(){
				y = y - Math.ceil(y/5);
				x = x - Math.ceil(x/5);
				window.scroll(x,y);
				if(y<1) clearInterval(timer);
			}
		,10);
		return false;
	});
});

$(window).load(function(){
	/* フラグメント参照fix */
	function flagment(){
		var targetId = $(location.hash);
		if(location.hash && targetId.length>0){
			var offset = targetId.offset();
			window.scroll(0,offset.top);
			return false;
		}
	}
	flagment();	
	
	/* jQuery.validation.js activate */
	if($("body").hasClass("inquiry")){
		$("form").validation();
	}
	
//	if(location.hostname.match(/nishigami/)){
//		$("a[href*='inquiry']").click(function(){
//			pageTracker._link("https://www.secure-n-di.com/nishigami/ad/inquiry/");
//			return false;
//		});
//	}
				
});