jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing, {
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});

function gSetting() {
	// location
	$('#gnav li a').each(function() {
		var url = document.URL.split('/');
		var crtdir = url[3];
		var crtdirPath = url[4];
		if (crtdir === 'otoshidama') {
			$('#gnav li a[href*='+ crtdir +']').parents('dl').children('dt').addClass('current');
			if (crtdirPath === 'number.html') {
				$('#gnav li a[href*="/otoshidama/number.html"]').parent().addClass('current');
			} else {
				$('#gnav li a[href*="/otoshidama/index.html"]').parent().addClass('current');
			}
		} else if (!crtdir.match(/\.html/i)) {
			$('#gnav li a[href*='+ crtdir +']').parent().addClass('current');
			$('#gnav li a[href*='+ crtdir +']').parents('dl').children('dt').addClass('current');
		}
		if (crtdir !== 'facebook') { // banner only show facebook directory
			$('.gNavBnr li:nth-child(3)').hide();
		}
	});
	
	// box effect
	$('#gnav li dd').hide().append('<div class="shd1"></div><div class="shd2"></div>');
	
	$('#gnav li').hover(function() {
		$(this).addClass('active');
		$(this).children('dl').children('dd').show();
		$(this).children('dl').children('dt').children('img').not('.current img, .active img[src*="_ov"]').each(function() {
			this.src = this.src.replace('.gif', '_ov.gif');
		});
	}, function() {
		$(this).removeClass('active');
		$(this).children('dl').children('dd').hide();
		$(this).children('dl').children('dt').children('img').not('.current img, .active img[src*="_ov"]').each(function() {
			this.src = this.src.replace('_ov.gif', '.gif');
		});
	});
	$('#gnav .current img').not('.gBnr img, .gNavBnr img, .gNavExtraBnr img').each(function() {
		this.src = this.src.replace(/(\.gif|\.jpg|\.png)/, '_crt'+'$1');
	});
	
	// rollover
	var aPreLoad = new Object();
	$('#gnav a img , .bnr a img, img.imgover').not('[src*="_ov"], .current img').each(function(i) {
		var tsrc = this.src;
		var ftype = this.src.lastIndexOf('.');
		var hsrc = this.src.substr(0, ftype) + '_ov' + this.src.substr(ftype, 4);
		aPreLoad[this.src] = new Image(); aPreLoad[this.src].src = hsrc;
		$(this).hover(function() {
			this.src = hsrc;
		}, function() {
			this.src = tsrc;
		});
	});
	
	// change rel to target
	$('a[rel="external"]').click(function() {
		this.target = '_blank';
	});
	
	// scroll
	$('a[href^="#pagetop"]').click(function() {
		$('html, body').animate({
			scrollTop : 0
		}, {
			duration: 1500,
			easing: 'easeInOutExpo'}
		);
		return false;
	}); 
};

$(function() {
	// load
	$('#gnav').load('/common/inc/globalnav.html', function() {
		gSetting();
	});

	// rollover
	var aPreLoad = new Object();
	$('#footer ul a img, .subnavi ul a img, .totop a img').not('[src*="_crt"], [src*="_ov"], .current img').each(function(i) {
		var tsrc = this.src;
		var ftype = this.src.lastIndexOf('.');
		var hsrc = this.src.substr(0, ftype) + '_ov' + this.src.substr(ftype, 4);
		aPreLoad[this.src] = new Image(); aPreLoad[this.src].src = hsrc;
		$(this).hover(function() {
			this.src = hsrc;
		}, function() {
			this.src = tsrc;
		});
	});
	
	// etc
	$('#content .section.colBlock01').not('.colBlock01.active, .colBlock01.kitdl').addClass('active').wrapInner('<div class="wrap"></div>');
	$('#content .section.colBlock01 .sep').not('.colBlock01 .sep.active').addClass('active').wrapInner('<div class="sepwrap"></div>');
	$('#content .btnlink a').not('.btnlink a.active').addClass('active').wrapInner('<span class="link"></span>').hover(function() {
		$(this).parent('div').addClass('over');
	}, function() {
		$(this).parent('div').removeClass('over');
	});
	$('#content .btnlinkext a').not('.btnlinkext a.active').addClass('active').wrapInner('<span class="ext"></span>').hover(function() {
		$(this).parent('div').addClass('over');
	}, function() {
		$(this).parent('div').removeClass('over');
	});
	$('#content .linkbox02 a, #content .linkbox03 a, #content .linkbox04 a').not('#content #kitdl a').bigTarget({ hoverClass: 'over', clickZone : '.box:eq(0)'});
	$('#content .linkbox02 .wrap').flatHeights();
	$('#content .linkbox02 .btn').flatHeights();
	$('#content .linkbox03 .wrap').flatHeights();
	$('#content .linkbox03 .btn').flatHeights();
	$('#content .linkbox04 .wrap').flatHeights();
	$('#content .linkbox04 .btn').flatHeights();
	$('.pageFL #content .btn').not('.btn.active').addClass('active').wrapInner('<em></em>').prepend('<img src="/common/img/icon_plus.gif" alt="詳細を表示します">');
});

