/**
 * @fileOverview *************************
 * @version 0.0.1
 */
/* ----------------------------------------------------------------------------------- */


/**
 * @namespace 
 */
var NIKKEIKIN_LIB = {};


/* ----------------------------------------------------------------------------------- */
/**
 * スムーススクロール処理。
 * @class スムーススクロール
 * @constructor
 */
NIKKEIKIN_LIB.SmoothScroll = function () {

	/** イベントを設定する要素を指定。
	    @type jQuery Object @constant @private */
	this.selector    = $('a[href^=#], area[href^=#]');

	/** 「ページ先頭へ戻る」のリンクの場合は、URLからフラグメント識別子を削除。
	    @type String @constant @private */
	this.goToPageTop = "#header-area";// 配列化が必要？

	/** アニメーション速度
	    @type Number @constant @private */
	this.speed       = 600;

	/** easing用キーワード
	    @type RegExp @constant @private */
	this.easing      = "easeInOutCubic";//"easeOutExpo";

	/** スクロールさせたくない場合に設定するclass属性値
	    @type String @constant @private */
	this.noScrollCName    = "no-scroll";

	if (this.selector.length) {
		this.init();
	}
}

/**
 * 初期化処理。とび先のid属性を持つ要素が無ければname属性を調べる。
 * ・アンカーリンク移動時の挙動
 * ・とび先がページの最下部付近の場合
 * @function
 * @return {Boolean} フラグメント識別子をURL末尾に付けるか否か。falseの場合は付けない。※falseの時は既に入っているものを消したい。
 */
NIKKEIKIN_LIB.SmoothScroll.prototype.init = function () {
	var _this = this;
	this.selector.each(function () {
		if (!$(this).hasClass(_this.noScrollCName)) {
			var fi = $(this).attr("href");
			if (fi == "#") return false;
			var el = ($(fi).length) ? $(fi) : $("a[name="+fi.replace(/#/,"")+"]");
			if (el.length) {
				$(this).click(function(e) {
					e.preventDefault();
					var target = el[0];
					$.scrollTo(target, {
						speed   : _this.speed,
						easing  : _this.easing,
						axis    : "y",////////////////////////////////////
						onAfter : function() {
							if (!fi.match(_this.goToPageTop)) {
								location.href = fi;
							}/*
							else {
								location.href = "./";
							}*/
						}
						/*,
						onAfter: function() {
							return (fi == _this.goToPageTop) ? false : true;
						}*/
					});
					//return (fi == _this.goToPageTop) ? false : true;
					// フラグメント識別子を後付けしてあげる必要あり。
					// ブラウザ別に処理が必要。
					//return true;
					//
				});
			}
		}
	});
}




/* ----------------------------------------------------------------------------------- */
$(function() {

	/* for IE6 background image flicker */
	if (jQuery.browser.msie && jQuery.browser.version == 6) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}

	/* Setup RolloverImages */
	var roi = new RolloverImages('rollover', 'on');

	/* Setup NIKKEIKIN_LIB  */
	for (module in NIKKEIKIN_LIB) {
		var obj = NIKKEIKIN_LIB[module];
		if (obj && typeof obj == "function") {
			new NIKKEIKIN_LIB[module]();
		}
	}

});


