/*
 * setting.js
 * jQuery1.2.6 required
 * $Date: 2008-09-19 22:00
 */

$(function() {
			  	
	/* addClass (first-child & last-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").not("br").each(function(){
		$(this).addClass("last-child");
	});
	
	/* PD Menu */
	$("ul","div#nav ul").hide().each(function(){
		var pd = $(this);
		$(this).parent().hover(function(event){
			$("ul","div#nav ul").not(pd).stop().css({
				height: "auto",
				opacity: 1
			}).hide();
			pd.slideDown("fast");
		},function(){
			pd.fadeOut(100);
		});
		$(this).mouseover(function(event){
			event.stopPropagation();
		});
	});
	
	/* Here Anchor Style */
	function hereAnchor(){
		if(location.href=="http://www.dcokk.com/") return false;
		var loc = location.href.split("/");
		$("a").each(function(){
			var href = $(this).attr("href").split("/");
			if(href[href.length-1].match(new RegExp("^"+loc[loc.length-1]))) $(this).addClass("here");	
		});
	}
	hereAnchor();
	
	/* Rollover Effect for Global Navigation */
	$(">ul>li","#nav").each(function(){
		var imgSrc = $("img",this).attr("src");
		var rollOverSrc = imgSrc.replace("_off","_on");
		var preload = new Image();
		preload.src = rollOverSrc;
		$(this).hover(function(){
			$("img",this).attr("src",rollOverSrc);
		},function(){
			$("img",this).attr("src",imgSrc);
		});
	});
	
	/* Google Mapを表示する */
	function gMap(id,lo){
		var map, address;
		var load = function() {
			var address = "Pacific Century Place, 1-11-1 Marunouchi, Chiyoda-ku";
			if(GBrowserIsCompatible()){
				var mapArea = document.createElement("div");
				$(mapArea).attr("id","map").insertAfter(lo);
				map = new GMap2(document.getElementById("map"));
				map.addControl(new GMapTypeControl());
				map.addControl(new GLargeMapControl());
				var glng = new GLatLng(35.678111,139.766918);
				map.setCenter(glng,14);
				map.addOverlay(new GMarker(glng));
			}
		}
		load();
	}
	if($("#address").length>0) gMap("address",$("#location"))
	
	/* Map Toggle Button */
	$("<a href='#map' id='toggle'> <img src='../img/profile/map_btn.jpg' alt='MAP' /></a>").insertAfter("#address");
	$("#map").hide();
	$("#toggle").click(function(){
		$("#map").slideToggle();
		return false;
	});
	
					
	/* Smooth Scroll */
	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(){
	/* Flagment Brousing Fix */
	var targetId = $(location.hash);
	if(location.hash && targetId.length>0){
		var offset = targetId.offset();
		window.scroll(0,offset.top);
		return false;
	}
});