/**
 * @fileOverview *************************
 * @version 0.0.1
 */
/* ----------------------------------------------------------------------------------- */

/**
 * @namespace 
 */
var JGKA = {};


JGKA.COMMON_DIR_NAME = "common";




/* ----------------------------------------------------------------------------------- */
JGKA.SmoothScroll = function () {

	this.selector    = $('a[href^=#], area[href^=#]');

	this.goToPageTop = "#container";

	this.speed       = 600;

	this.easing      = "easeOutExpo";

	this.noScrollCName    = "no-scroll";

	if (this.selector.length) {
		this.init();
	}
}

JGKA.SmoothScroll.prototype.init = function () {
	var _this = this;
	this.selector.each(function () {
		if (!$(this).hasClass(_this.noScrollCName)) {
			var fi = $(this).attr("href");
			if (fi == "#") return;//return false;
			var el = ($(fi).length) ? $(fi) : $("a[name="+fi.replace(/#/,"")+"]");
			if (el.length) {
				$(this).click(function() {
					//e.preventDefault();
					var target = el[0];
					$.scrollTo(target, {
						speed: _this.speed,
						easing: _this.easing/*,
						onAfter: function() {
							return (fi == _this.goToPageTop) ? false : true;
						}*/
					});
					return (fi == _this.goToPageTop) ? false : true;
				});
			}
		}
	});
}


/* ----------------------------------------------------------------------------------- */
// ret : '../../common/'
// デフォルトは /common/ に設定

JGKA.getCommonDir = function() {
	var dirName = arguments.length? arguments[0] : JGKA.COMMON_DIR_NAME;
	var links   = document.getElementsByTagName('LINK');
	var reg = new RegExp( "(.*\/?" + dirName + "\/).+$" );
	if( links ){
		for( var i=0; i<links.length; i++ ){
			if( links[i].getAttribute("rel") && links[i].getAttribute("rel").indexOf("stylesheet") != -1 ) {
				if( links[i].href && links[i].href.match( reg ) )
					return RegExp.$1;
			}
		}
	}
	return '/'+ dirName +'/';
}



/* ----------------------------------------------------------------------------------- */


$(function() {

	if (jQuery.browser.msie && jQuery.browser.version == 6) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}

	var roi = new RolloverImages('rollover', 'on');

	for (module in JGKA) {
		var obj = JGKA[module];
		if (obj && typeof obj == "function") {
			new JGKA[module]();
		}
	}

});


/* ----------------------------------------------------------------------------------- */
/**
 * @version  0.0.1_2010-08-18
 * @requires jquery.js
*/

(function($) {

	var config = {
		target_ua    : (jQuery.browser.mozilla || jQuery.browser.webkit),
		anchor_cname : 'span-insert-anchor',
		span_cname   : 'span-insert-span'
	};

	jQuery.fn.SpanInsert = function() {
		return this.each(function() {
			_SpanInsert(this);
		});
	};

	_SpanInsert = function(el) {
		var $el = $(el);
		if (config.target_ua) {// もっと前のタイミングで実施
			if ($el.get(0) && $el.get(0).nodeType == 1) {
				if (!$el.hasClass(config.span_cname)) {
					
					$el.contents().each(function() {
						if (this.nodeType == 1) {//ELEMENT
							_SpanInsert(this);
						}
						else if (this.nodeType == 3) {//TEXT
							var $tx = $(this);
							var $anchor = $tx.closest("a");
							if ($anchor.get(0) && $anchor.get(0).nodeType==1) {
								$anchor.addClass(config.anchor_cname);
								$tx.wrap("<span></span>").parent().addClass(config.span_cname);
							}
						}
					});
					
				}
			}
		}
	};

})(jQuery);


$(function(){
	$("a:has(img[class^='ic-'])").SpanInsert();
});



/* ----------------------------------------------------------------------------------- */
/**
 * @version  0.0.1_2009-06-29
 * @requires jquery.js
 * @requires styleswitcher.js
 * @requires rollover.js
 */

FONTSIZE_SELECTOR_ENABLED = true;
FONTSIZE_SELECTOR         = null;


if (FONTSIZE_SELECTOR_ENABLED) {

	$(function() {
		var config = {
			className      : "fontsize",
			blockId        : "fontsize-selector",
			buttonsSetting : {
					"small" : {
								styleId       : "fontsize-small",
								buttonId      : "fontsize-btn-small",
								title         : "文字サイズを「小」に変更します",
								titleSelected : "現在選択中の文字サイズは「小」です"
					},
					"medium" : {
								styleId       : "fontsize-medium",
								buttonId      : "fontsize-btn-medium",
								title         : "文字サイズを「中」に変更します",
								titleSelected : "現在選択中の文字サイズは「中」です"
					},
					"large" : {
								styleId       : "fontsize-large",
								buttonId      : "fontsize-btn-large",
								title         : "文字サイズを「大」に変更します",
								titleSelected : "現在選択中の文字サイズは「大」です"
					}
			}
			,rollover : new RolloverImages("rollover-fs", "on", "on")
		};

		FONTSIZE_SELECTOR = new FontSizeSelector(config);
	});

	// 
	document.write(''
	+ '<style  type="text/css" media="screen,print">'
	+ '#fontsize-selector {display: block !important;}'
	+ '</style>');
}



/* ----------------------------------------------------------------------------------- */
/**
 * @requires jquery.js
 */

function MM_openBrWindow(theURL,winName,features) { //v2.0
	win=window.open(theURL,winName,features);
	win.focus();
}


