function gSetting() {
// location
	$("#btnarea li a").each(function() {
		var url = document.URL.split("/");
		crtdir = url[3];
		if(crtdir == "index"){
		} else if((crtdir == "archives")||(crtdir == "archives.html")) {
			$("#btnarea li a[href*='archives']").parent().addClass("current");
		} else if(crtdir) {
			crtdirPath = url[4];
			var pathfile = crtdirPath.split(".");
			var crtfile = pathfile[0];
			$("#btnarea li a[href*='"+ crtdir +"/"+ crtfile +"']").parent().addClass("current");
		}
	});

// rollover
	var aPreLoad = new Object();
	$("#btnarea a img , .bnr a img, .archives a img").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; });
	});
	$("#btnarea li.current img").each(function() { this.src = this.src.replace(/(\.gif|\.jpg|\.png)/, '_crt'+"$1"); });

	$('a[href^=#]').click(function() {
		var $target=$(this.hash);
		var targetY=$target.offset().top;
		$($.browser.opera ? document.compatMode == 'BackCompat' ? 'body' : 'html' : 'html, body').animate({ scrollTop: targetY }, 'slow','swing');
		return false;
	});
}

$(function(){
// load
	$("#btnarea").load("/common3/inc/globalnav.txt", function(){ gSetting();});

// rollover
	var aPreLoad = new Object();
	$("#footer ul a img, img.imgover, .btn input, .btn 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; });
	});

// links
	$('a[rel="external"]').click(function(){ this.target = '_blank';});
	$('a[rel$="popup"]').click(function(){
		var newWin =window.open(this.href,'popwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=713,height=780').focus();
		return false;
	});

// etc
	$('li:first-child').addClass("first-child");
	$(".box:even").addClass("first");


	$('.pChoice .block02 .box').flatHeights();
	$(".pChoice .box").hover(function(){ $(this).addClass('over'); }, function(){ $(this).removeClass('over');
	}).click(function(){
		window.location=$(this).find("a").attr("href");
		return false;
	});

});

/* ============================================================
 * Float Navigation
 ============================================================ */
jQuery(function($){
var isMobile = navigator.userAgent.match(/iPad|iPhone|iPod|Android|BlackBerry/);
var target = $('#btnarea');
if (isMobile) {
	target.css('-webkit-transition', 'margin-top 0.4s ease-in-out');
}
function setNavPosition(e){
	var top = (document.documentElement.scrollTop || document.body.scrollTop);
	if (($.browser.webkit && isMobile) || target.css('position') != 'fixed') {
		top += Math.min(0, $('#footer').offset().top - top - target.outerHeight() - parseFloat(target.css('top').replace('px',''), 10));
		target.css('margin-top', top + 'px');
	} else {
		var base = ((document.documentElement.scrollWidth || document.body.scrollWidth) - 970) / 2;
		var offset = -1 * (document.documentElement.scrollLeft || document.body.scrollLeft);
		top = Math.min(0, $('#footer').offset().top - top - target.outerHeight() - parseFloat(target.css('top').replace('px',''), 10));
		target.css('margin-top', top + 'px');
		target.css('margin-left', (base + offset) + 'px');
	}
}
$(window).load(setNavPosition).scroll(setNavPosition).resize(setNavPosition);
setNavPosition();
});

/* ============================================================
 * jquery.flatheights.js
 * Version: 2010-09-15

 * Copyright (c) 2007, KITAMURA Akatsuki
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ============================================================ */
/* $.changeLetterSize.addHandler(func) */
jQuery.changeLetterSize = { handlers : [], interval : 1000, currentSize: 0};
(function($) {
 var self = $.changeLetterSize;
 var ins = $('<ins>M</ins>').css({ display: 'block', visibility: 'hidden', position: 'absolute', padding: '0', top: '0' });
 var isChanged = function() { ins.appendTo('body'); var size = ins[0].offsetHeight; ins.remove(); if (self.currentSize == size) return false; self.currentSize = size; return true; };
 $(isChanged);
 var observer = function() { if (!isChanged()) return; $.each(self.handlers, function(i, handler) { handler(); }); };
 self.addHandler = function(func) { self.handlers.push(func); if (self.handlers.length == 1) { setInterval(observer, self.interval); } };
})(jQuery);

/* $(expr).flatHeights() */
(function($) {
 var sets = [];
 var flatHeights = function(set) { var maxHeight = 0; set.each(function(){ var height = this.offsetHeight; if (height > maxHeight) maxHeight = height; }); set.css('height', maxHeight + 'px'); };
jQuery.fn.flatHeights = function() { if (this.length > 1) { flatHeights(this); sets.push(this); } return this; };
var reflatting = function() { $.each(sets, function() { this.height('auto'); flatHeights(this); }); };
$.changeLetterSize.addHandler(reflatting);
$(window).resize(reflatting);
})(jQuery);


