/**
 * 越後上越 天地人博 Site Interface Controller
 * Date: 12/17/2008
 * @author xe-que design works
 * @version 1.0
 *
 */


jQuery(function( $ ){

	// コンテンツメニューのフェード
	// remove link background images since we're re-doing the hover interaction below 
	// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
	// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
	$(".nav").children("li").each(function() {
		var current = "nav current-" + ($(this).attr("class"));
		var parentClass = $(".nav").attr("class");
		if (parentClass != current) {
			$(this).children("a").css({backgroundImage:"none"});
		}
	});	

	// create events for each nav item
	attachNavEvents(".nav", "about");
	attachNavEvents(".nav", "story");
	attachNavEvents(".nav", "recommend");
	attachNavEvents(".nav", "information");
	attachNavEvents(".nav", "introduces");
	attachNavEvents(".nav", "tour");
	attachNavEvents(".nav", "agent");
	attachNavEvents(".nav", "contact");
	attachNavEvents(".nav", "sponsor");
	attachNavEvents(".nav", "blog");
	attachNavEvents(".nav", "gototop");

	function attachNavEvents(parent, myClass) {
		$(parent + " ." + myClass).mouseover(function() {
			$(this).append('<div class="nav-' + myClass + '"></div>');
			$("div.nav-" + myClass).css({display:"none"}).fadeIn(400);
		}).mouseout(function() {
			// fade out & destroy pseudo-link
			$("div.nav-" + myClass).fadeOut(400, function() {
				$(this).remove();
			});
		});
	}


	// アンカーのフェード
	$(".fade").hover(
		function(){$(this).fadeTo(300, 0.6);},
		function(){$(this).fadeTo(300, 0.999);}
	);

	$(".fade-intensive").children("a").hover(
		function(){$(this).children("img").fadeTo(300, 0.6);},
		function(){$(this).children("img").fadeTo(300, 0.999);}
	);	


	//smoothscroll
	$('#footer a[href*=#],#content-agent a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 20;
				var scldurat = 600;
				var targetOffset = target.offset().top - sclpos;
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});
});

