/**
 * @fileOverview ***
 * @version 0.0.1
 * @requires jquery.js
 */
/* ----------------------------------------------------------------------------------- */

/**
 * @namespace 
 */
var TXHDLIB = {};


TXHDLIB.COMMON_DIR_NAME = "common";




/* ----------------------------------------------------------------------------------- */
TXHDLIB.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();
	}
}

TXHDLIB.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) {
//					e.preventDefault();
					var target = el[0];
					$.scrollTo(target, {
						speed: _this.speed,
						easing: _this.easing/*,
						onAfter: function() {
							location.hash = "#"+fi.split("#")[1];;
						}*/
					});
					return false;
				});
			}
		}
	});
}


/* ----------------------------------------------------------------------------------- */
/**
 * @returns {String} 相対パスを返す。'../../common/'など。
 * 
*/
TXHDLIB.getCommonDir = function() {
	var dirName = arguments.length? arguments[0] : TXHDLIB.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 TXHDLIB) {
		var obj = TXHDLIB[module];
		if (obj && typeof obj == "function") {
			new TXHDLIB[module]();
		}
	}

});


/* ----------------------------------------------------------------------------------- */
/**
 * 
 * 
*/

(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^='link-'])").SpanInsert();

	var tid = setTimeout(function(){
		$("a:has(img[class^='link-'])").SpanInsert();
	}, 2000);

});



/* ----------------------------------------------------------------------------------- */
/**
 * 
 * 
*/

$(function() {

	var config = {
		
	};

	var QA_LIST   = "#main-content .qa-list-1";
	var QA_LIST_Q = "#main-content .qa-list-1 .question";
	var QA_LIST_A = "#main-content .qa-list-1 .answer";

	var QA_LIST_Q_IMAGE_PLUS  = "qa_01.gif";
	var QA_LIST_Q_IMAGE_MINUS = "qa_01_on.gif";


	var $qaList = $(QA_LIST);

	$qaList.each(function() {

		var $question = $(this).find(".question");
		var $answer   = $(this).find(".answer");


		var imgPlus;
		var imgMinus;
		var $qImg = $question.find("a img");

		imgMinus = $($qImg.get(0)).attr("src");
		imgPlus  = imgMinus.replace(QA_LIST_Q_IMAGE_MINUS, QA_LIST_Q_IMAGE_PLUS);// QA_LIST_Q_IMAGE_MINUSにマッチしない場合はreturnにする。

		// img preload
		(new Image()).src = imgPlus;
		(new Image()).src = imgMinus;

		// 予め開閉ボタンを＋に変更
		$qImg.each(function() {
			$(this).attr({"src": imgPlus});
		});


		if ($question.size()!=0 && $answer.size()!=0) {
			$question.click(function(e) {
				e.preventDefault();
				e.stopPropagation();
				
				var currentDisp = $answer.css("display");
				var disp;
				var imgSrc;
				if (currentDisp == "none") {
					disp   = "block";
					imgSrc = imgMinus;
				}
				else {
					disp = "none";
					imgSrc = imgPlus;
				}
				
				//$answer.css({"display":disp});
				$answer.slideToggle("easeInOutCubic"); //easeInOutCubic , easeOutExpo
				$(this).find("a img").attr({"src": imgSrc});
			});
		}

	});
});

(function(){
var QA_LIST_STYLE =''
+'<style type="text/css">'
+'.qa-list-1 .answer { display: none; }'
+'</style>';
document.write(QA_LIST_STYLE);
})()



/* ----------------------------------------------------------------------------------- */
/**
 * search-box
 */
$(function(){
	$("#search-keywords").css({
		"width": "134px",
		"border": "1px solid #cccccc",
		"padding": "3px 5px 2px"
	});
});



/* ----------------------------------------------------------------------------------- */
/**
 * search results
 */
$(window).load(function(){
	//if (jQuery.browser.webkit && location.href.match(/\/search\/[^\/]*/) && !location.hash) {
	if (jQuery.browser.webkit && location.href.match(/\/search\//) && !location.hash) {
		location.href = location.href + "#container";
	}
});




/* ----------------------------------------------------------------------------------- */
/**
 * @requires jquery.js, styleswitcher.js, 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>');
}



/* ----------------------------------------------------------------------------------- */
/**
 * 
 * 
 */
function MM_openBrWindow(theURL,winName,features) { //v2.0
	win=window.open(theURL,winName,features);
	win.focus();
}





