/*================================
 setting.js
 tokuda@n-di.co.jp
=================================*/

$(function() {
			  
	/* Fix "inline-block" models for less than Firefox2.0 */
	var UA = navigator.userAgent;
	var version = UA.match(/.+Firefox\/([\d\.]+)/) ? RegExp.$1 : UA;
	if(UA.match(/Firefox/) && version.match(/[12]\.[\d\.]+/)){
		$("body *").each(function(){
				if($(this).css("display").match(/list\-item/))
					$(this).css("display","-moz-inline-box").html("<div style='width: "+$(this).width()+"px; display: block;'>"+$(this).html()+"</div>");
		});
	}
				  	
	$("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']","#gNav").each(function(){rollOver($(this))});
	
	if($("body").hasClass("products")){
		$("a[href$='.html'],a[href$='.jpg'],a[href$='.gif']","ul.outline").click(function(){
			window.open(this.href,"","");
			return false;
		});
	}
	
	function eqHeight(parent){
		var child = $(">*",parent);
		var maxHeight = 0;
		for(var i=0;i<child.length;i++){
			if(i>0) maxHeight = (maxHeight < $(child[i]).height()) ? $(child[i]).height() : maxHeight;
			else maxHeight = $(child[i]).height();
		}
		child.each(function(){
			$(this).height(maxHeight);
		});
	}
	eqHeight($(".floatBoxParent"));
				
	function getScrollPosition(){
		var obj = new Object();
		obj.x = document.body.scrollLeft || document.documentElement.scrollLeft;
		obj.y = document.body.scrollTop || document.documentElement.scrollTop;
		return obj;
	}
	
	$("area").focus(function(){
		this.blur();
	});
	
	$("a","table.partner").click(function(){
		window.open(this.href,"","");
		return false;
	});

	$("p.pageTop a[href*='#']").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(){
	function flagment(){
		var targetId = $(location.hash);
		if(location.hash && targetId.length>0){
			var offset = targetId.offset();
			window.scroll(0,offset.top);
			return false;
		}
	}
	flagment();								
});
