var Obj = {};


/**
 * @function    
 * @return {String}    ex) '../common/'
 */
Obj.getCommonDirPath = function() {
	var s = document.getElementsByTagName('SCRIPT');
	if( s.length && s[0].src && s[0].src.match(/(.*\/?common\/)js\/.+$/))
		return RegExp.$1;
	else
		return '/common/';
}


/* -------------------------------------------------------------------
	* 共通関数実行
	* init
 ------------------------------------------------------------------- */
$(function() {

	/* for IE6 background image flicker */
	if (jQuery.browser.msie && jQuery.browser.version == 6) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}

	/* set RolloverImages */
	var roi = new RolloverImages('rollover', 'on');

	/* init printCurrentYear */
	$('#site-copyright span').PrintCurrentYear();
	
	/* set PdfLinkBlank */
	$('#contents a').LinkTargetSet();
	
	/* init SearchPlaceholder */
	$('.site-search').SearchPlaceholder();


	/* set SmoothScroll */
	$().SmoothScroll({noflagment:'#page-container'});

	/*  */
	$('.shop-list-select').selectLink();
	
	/* iconBox */
	$('.explain-icon-btn-01,.explain-icon-btn-02').iconBox();
	/*  
	$(".carousel").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		visible: 4,
		circular: false
	});
	*/

});




/* -------------------------------------------------------------------
	* 共通関数定義
	* @function
 ------------------------------------------------------------------- */
(function($){
	/*
	 * コピーライトの年号書き出し
	 * @function
	 */
	$.fn.PrintCurrentYear = function(config){
		c = jQuery.extend({},config);
		var t = this;
		var $t = $(t);
		var currentYear = (new Date()).getFullYear();
		$t.html('1995-'+currentYear+' ');
		
	}

	/*
	 * リンクのtarget指定の設定・上書き	(初期値：pdfリンクを別窓にする)
	 * @function
	 */
	$.fn.LinkTargetSet = function(config){
		c = jQuery.extend({
					reg	:	new RegExp("(\.pdf$|\.pdf#.*)", "i"),
				 	target	:	'_blank'
			 },config);
		$(this).each(function(){
			var t = this;
			var $t = $(t);
			var href = $t.attr('href');
			if (href.match(c.reg)) {
				$t.attr('target',c.target);
			}
		});
	}

	/*
	 * サイト内検索ボックスのプレースホルダ
	 * @function
	 */
	$.fn.SearchPlaceholder = function(config){
		c = jQuery.extend({
					str				:	'',
					addClass	:	'pre-text'
				},config);
		
		$(this).each(function(){
			var t = this;
			var $t = $(t);
			var $ele = {
					form	:	$t.find('form'),
					input	:	$t.find('input:text'),
					btn		:	$t.find('input:image')
			}
			// 入力支援 
			$ele.input.attr('value',c.str).addClass(c.addClass)
								.focus(function(){
									var value = $ele.input.attr('value');

									if(value == c.str){
										$ele.input.removeClass(c.addClass).attr('value','');
									}
								})
								.blur(function(){						 
									var value = $ele.input.attr('value');
									if(value == c.str || value == ''){
										$ele.input.addClass(c.addClass).attr('value',c.str);
									}
								});

			 //	submit時のエラー処理

/*			$ele.form.submit(function(){
					var value = $ele.input.attr('value');
					
					if(value == c.str || value == ''){
							return false;
					}
			});
*/
			
		});
	}


	/*
	 * ポップアップ
	 * @function
	 */
	$.fn.jqueryPopup = function(options){
		
		var c = $.extend({
				name       :'popup',  // windowname
				width      :'750',    // 幅
				height     :'600',    // 高さ
				scrollBar  :1,        // スクロールバーの有無
				locationBar:1,        // ロケーションバーの有無
				menuBar    :1,        // メニューバーーの有無
				resize     :1,        // リサイズハンドルの有無
				statusBar  :1,        // ステータスバーの有無
				toolBar    :1,        // ツールバーの有無
				directorBar:1         // ディレクトリバーの有無
			}, options);
		
		var target = $(this);
		var url = target.attr('href');
		var SUB_WIN;
		
		var winops = 'width=' +c.width+ ',height=' +c.height+ ',scrollbars=' +c.scrollBar+ ',location=' +c.locationBar+ ',menubar=' +c.menuBar+ ',resizable=' +c.resize+ ',status=' +c.statusBar+ ',toolbar=' +c.toolbar+ ',directories=' +c.directorBar;
		
		if(!url) return false;

		SUB_WIN = window.open(url,c.name,winops);
		SUB_WIN.focus();
		
		return false;
	}

	/*
	 * スムーススクロール
	 * @function
	 */
	$.fn.SmoothScroll	= function(options){
		
		var scroller = (function() {
			var c = $.extend({
							easing:100,
							step:30,
							fps:60,
							fragment:'',
							noflagment:''
						}, options);
				
			c.ms = Math.floor(1000/c.fps);
			var timerId;
			var param = {
					stepCount:0,
					startY:0,
					endY:0,
					lastY:0
			};
				
				// fnc
				function move() {
					if (param.stepCount == c.step) {
						// scroll end
						setFragment(param.fragment);
						
						window.scrollTo(getCurrentX(), param.endY);
					} else if (param.lastY == getCurrentY()) {
						// scroll
						param.stepCount++;
						window.scrollTo(getCurrentX(), getEasingY());
						param.lastY = getEasingY();
						timerId = setTimeout(move, c.ms); 
					} else {
						// error	
						if (getCurrentY()+getViewportHeight() == getDocumentHeight()) {
							setFragment(param.fragment);
						}
					}
				}
				function setFragment(fragment){
					if(fragment != c.noflagment ) {
						//location.href = location.href.split('#')[0] + fragment;
					}
					/*
					setTimeout(function(){
						location.href = location.href.split('#')[0] + fragment;
					},1000);
					*/
				}

				function getEasingY() {
					return Math.floor(getEasing(param.startY, param.endY, param.stepCount, c.step, c.easing));
				}
				function getEasing(start, end, stepCount, step, easing) {
					var s = stepCount / step;
					return (end - start) * (s + easing / (100 * Math.PI) * Math.sin(Math.PI * s)) + start;
				}
				function targetOffsetTop(target){
					return target.offset().top;
				}
				return {
					set: function(options) {
						this.stop();
						if (options.startY == undefined) options.startY = getCurrentY();
						param = $.extend(param, options);						
						param.lastY = param.startY;
						param.fragment = options.fragment;
						timerId = setTimeout(move, c.ms); 
					},
					stop: function(){
						clearTimeout(timerId);
						param.stepCount = 0;
					}
				};
			})();
			
			function getCurrentY() {
					return document.body.scrollTop  || document.documentElement.scrollTop;
			}
			function getCurrentX() {
					return document.body.scrollLeft  || document.documentElement.scrollLeft;
			}
			function getDocumentHeight(){
					return (document.compatMode && document.compatMode != "BackCompat")?document.documentElement.scrollHeight:document.body.scrollHeight;
			}
			function getViewportHeight(){
					return (!$.browser.safari && !$.browser.opera) ? document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight : window.innerHeight;
			}
			// init
//			$('a[href^=#], area[href^=#]').not('a[href=#],area[href=#],a.no-scroll').live('click',function(){
		$('a, area').live('click',function(){
				
				if($(this).hasClass('no-scroll') || $(this).attr('href')=='#') {
					return false;
				}
				var fragment = $(this).attr('href');
				var url = location.href.split('#')[0];
				
//				alert(fragment.split('#')[0]+'\r\n'+url);
				
				if(fragment.split('#')[0] == url) {
					fragment = '#'+fragment.split('#')[1];
//					alert(fragment);
				}
				
				
				var target = $(fragment);
				//alert(target);
				
				if (target.length == 0) target = $('a[name='+fragment+']');
				
				if (target.length) {
					scroller.set({
						endY: ((getDocumentHeight() - target.offset().top )) < getViewportHeight() ? getDocumentHeight() - getViewportHeight() : target.offset().top,
						fragment: fragment,
						_target :	target
					});

					return false;
				}
			});
	}




	/**
	 * プルダウンのリンク
	 * @function
	 */
	$.fn.selectLink = function(config){
		var c = $.extend({
			
		},config);
		
		$(this).each(function(){
			var target = $(this);
			target.submit(function(e){
				e.preventDefault();
				var url = target.find('option:selected').attr('value');
				if(url != ''){
					location.href = url;
				}
				return false
			});
		});
	}
	
	/**
	 * アイコンの説明
	 * @function
	 */
	$.fn.iconBox = function(config){
		var c = $.extend({
			targetBoxId : '#explain-icon-box-01',
			closeBtnId	:	'#explain-icon-close-btn'
		},config);
		
		var box = $(c.targetBoxId);
		var closeBtn = $(c.closeBtnId);
		box.css({
			'display'	: 'none',
			'position':	'absolute'
		})

		$(this).each(function(){
			var target = $(this);
			var pos = target.children('a').offset();

			target.toggle(function(){
				box.css({
					'display'	:	'block',
					'top'			:	pos.top + 5 + 'px',
					'left'		:	pos.left - 103 + 'px'
				});
				return false;
			},function(){
				box.css({
					'display'	:	'none'
				});
				return false;
			});
			
			closeBtn.click(function(){
				box.css({
					'display'	:	'none'
				});
				return false;
			});

		});
	}
	
})(jQuery)





/*---------------------------------------------------------------------------*/
/**
 * @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-switch",
			buttonsSetting : {
					"default" : {
								styleId       : "fontsize-default",
								buttonId      : "fontsize-btn-default",
								title         : "文字サイズを「標準」に変更します",
								titleSelected : "現在選択中の文字サイズは「標準」です"
					},
					"large" : {
								styleId       : "fontsize-large",
								buttonId      : "fontsize-btn-large",
								title         : "文字サイズを「大」に変更します",
								titleSelected : "現在選択中の文字サイズは「大」です"
					}
			}
			,rollover : new RolloverImages("rollover-fsbutton", "on", "on")
		};

		FONTSIZE_SELECTOR = new FontSizeSelector(config);
	});

	// 
	document.write(''
	+ '<style  type="text/css" media="screen,print">'
	+ '#fontsize-selector {display: block !important;}'
	+ '</style>');
}

