(function($) {

	$(function() {
		$.yuga.selflink({
			hoverClass:'btn'  //除去するロールオーバーのクラス名
		});
		$.yuga.rollover({
			hoverClass: '.btn',		//イメージにつけるロールオーバーのクラスセレクタ
			groupClass: '.btngroup',//グループ化したロールオーバーのクラスセレクタ
			postfix: '_on'			//ファイル名の末尾につける文字列
		});
		$.yuga.externalLink({
			windowOpen: false,				//外部リンクは別ウインドウで開く
			externalClass: 'externalLink'	//外部リンクにつけるクラス名
		});
		$.yuga.thickbox();
		$.yuga.stripe({
			oddClass:'odd',		//奇数行につくクラス
			evenClass:'even'	//偶数行につくクラス
		});
		$.yuga.css3class();
		$('a[href^=#], area[href^=#]').setYugaScroll();
	});

	//---------------------------------------------------------------------

	$.yuga = {
		// URIを解析したオブジェクトを返すfunction
		Uri: function(s){
			this.originalPath = s;
			//絶対パスを取得
			this.getAbsolutePath = function(path){
				if (!path.match(/^(mailto:)|(javascript:)/)) {
					var img = new Image();
					img.src = path;
					path = img.src;
					img.src = '#';
				}
				return path;
			};
			this.absolutePath = this.getAbsolutePath(s);
			//同じ文書にリンクしているかどうか
			this.isSelfLink = (this.absolutePath == location.href);
			//絶対パスを分解
			var fields = {'schema' : 2, 'username' : 5, 'password' : 6, 'host' : 7, 'path' : 9, 'query' : 10, 'fragment' : 11};
			var r = /^((\w+):)?(\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(this.absolutePath);
			for (var field in fields) {
				this[field] = r[fields[field]]; 
			}
		},
		//現在のページへのリンク
		selflink: function (options) {
			var c = $.extend({
				hoverClass:'btn'
			}, options);
			$('a[href]').each(function(){
				var href = new $.yuga.Uri(this.getAttribute('href'));
				if (href.isSelfLink && !href.fragment) {
					$(this).addClass('current');
					//img要素が含まれていたら現在用画像（_cr）に設定
					$(this).find('img').each(function(){
						//ロールオーバークラスが設定されていたら削除
						$(this).removeClass(c.hoverClass);
						this.originalSrc = $(this).attr('src');
						this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cr$1");
						$(this).attr('src',this.currentSrc);
					});
				}
			});
		},
		//ロールオーバー
		rollover: function(options) {
			var c = $.extend({
				hoverClass: '.roll',
				groupClass: '.rollgroup',
				postfix: '_on'
			}, options);
			//ロールオーバーするノードの初期化
			$(c.hoverClass).each(function(){
				this.originalSrc = $(this).attr('src');
				this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)$/, c.postfix+"$1");
				this.rolloverImg = new Image;
				this.rolloverImg.src = this.rolloverSrc;
			});
			//通常ロールオーバー
			$(c.hoverClass).not($(c.groupClass+' '+c.hoverClass)).hover(function(){
				$(this).attr('src',this.rolloverSrc);
			},function(){
				$(this).attr('src',this.originalSrc);
			});
			//グループ化されたロールオーバー
			$(c.groupClass).hover(function(){
				$(this).find(c.hoverClass).each(function(){
					$(this).attr('src',this.rolloverSrc);
				});
			},function(){
				$(this).find(c.hoverClass).each(function(){
					$(this).attr('src',this.originalSrc);
				});
			});
		},
		//外部リンクは別ウインドウを設定
		externalLink: function(options) {
			var c = $.extend({
				windowOpen:true,
				externalClass: 'externalLink'
			}, options);
			var e = $('a[href^="http://"]');
			if (c.windowOpen) {
				e.click(function(){
					window.open(this.href, '_blank');
					return false;
				});
			}
			e.addClass(c.externalClass);
		},
		//ドキュメントのスクロールを制御するオブジェクト
		scroll: (function() {
			var c;
			var TimerId;
			var stepCount = 0;
			var lastY = -1;
			//スクロール中に実行されるfunction
			function move() {
				var currentX = getCurrentX();
				var currentY = getCurrentY();
				if (stepCount >= c.step) {
					//スクロール終了時
					window.scrollTo(currentX, c.endY);
					stepCount = 0;
				} else if (lastY != currentY) {
					//スクロール操作時
					stepCount = 0;
				} else {
					//通常スクロール時
					stepCount++;
					window.scrollTo(currentX, getEasingY());
					lastY = getEasingY();
					TimerId = setTimeout(move, Math.floor(1000/c.fps)); 
				}

			};
			function getCurrentY() {
				return document.body.scrollTop  || document.documentElement.scrollTop;
			}
			function getCurrentX() {
				return document.body.scrollLeft  || document.documentElement.scrollLeft;
			}
			function getEasingY() {
				return Math.floor(getEasing(c.startY, c.endY, 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;
			}
			return {
				set: function(options) {
					c = $.extend({
						startY:getCurrentY(),
						endY:0,
						easing:100,
						step:30,
						fps:60
					}, options);
					lastY = c.startY;
					TimerId = setTimeout(move, Math.floor(1000/c.fps)); 
				}
			};
		})(),
		//画像へ直リンクするとthickboxで表示(thickbox.js利用)
		thickbox: function() {
			try {
				tb_init('a[@href$=".jpg"], a[@href$=".gif"], a[@href$=".png"],a[@href$=".JPG"], a[@href$=".GIF"], a[@href$=".PNG"]');
			} catch(e) {
			}	
		},
		//奇数、偶数を自動追加
		stripe: function(options) {
			var c = $.extend({
				oddClass:'odd',
				evenClass:'even'
			}, options);
			$('ul, ol').each(function(){
				$(this).children('li:odd').addClass(c.evenClass);
				$(this).children('li:even').addClass(c.oddClass);
			});
			$('table').each(function(){
				$(this).children('tr:odd').addClass(c.evenClass);
				$(this).children('tr:even').addClass(c.oddClass);
			});
		},
		//css3のクラスを追加
		css3class: function() {
			//:first-child, :last-childをクラスとして追加
			$('body :first-child').addClass('firstChild');
			$('body :last-child').addClass('lastChild');
			//css3の:emptyをクラスとして追加
			$('body :empty').addClass('empty');
		}
	};
	$.fn.setYugaScroll = function() {
		return this.each(function(){
			$(this).each(function(){
				this.hrefdata = new $.yuga.Uri(this.getAttribute('href'));
			}).click(function(){
				var target = $('#'+this.hrefdata.fragment);
				if (target.length) {
					$.yuga.scroll.set({
						endY: target.offset().top
					});
					return false;
				}
			});
		});
	};

})(jQuery);

$(function(){
$('.news table.lastChild ').css('background','none');		   
		   
$('#footer ol li:first-child').css('border-left','none');
$('.child_faq.lastChild').css('border','none');
$('.reqtbl.lastChild').css('border','none');
$('.storebox').css('border-bottom','1px dotted #6d6d6d');
$('.confirmtbl1.lastChild .td1').css('background','none');
$('.p_box').before('<img src="img/linkbox_t.jpg" style="position:relative;float:left;clear:both;top:15px;">');
$('.p_box').after('<img src="img/linkbox_b.jpg" style="position:relative;float:left;clear:both;">');
$('.p_box2').before('<img src="../cmnfix/commentbox_t.jpg" style="position:relative;float:left;clear:both;top:15px;">');
$('.p_box2').after('<img src="../cmnfix/commentbox_b.jpg" style="position:relative;float:left;clear:both;">');

$('.kmBlue').after('<img src="img/kmBlue_b.jpg" style="position:relative;clear;both;float:left;left:7px;" class="kmBlue_btm">');
$('.kmBlue_btm').after('<img src="img/arr1.jpg" style="position:relative;left:-135px;margin: 10px 0 0 0;">');

$('.kmRed').after('<img src="img/kmRed_b.jpg" style="position:relative;float:left;top:8px;clear:both;left:16px;" class="kmRed_btm">');
$('.kmRed_btm').after('<img src="img/arr2.jpg" style="position:relative;left:-120px;margin: 18px 0 0 0;">');

$('.ansara').before('<img src="img/ansara_t.jpg" style="position:relative;float:left;clear:both;top:20px;left:6px;" class="kmansara_top">');
$('.ansara').after('<img src="img/ansara_b.jpg" style="position:relative;float:left;clear:both;left:6px;" class="kmansara_btm">');
$('.kmansara_btm').after('<img src="img/arr3.jpg" style="clear:both;float:left;margin: 10px 0 0 270px;">');

var blzIe=navigator.userAgent.indexOf("MSIE");
var blzIe6=navigator.userAgent.indexOf("MSIE 6.0");
	if(blzIe!=-1){
	$('.balunaga').css('margin','3px 0');
	$('.kmBlue_btm').css('left','14px');
	}
	if(blzIe6!=-1){
	$('.kmansara_btm').css('left','12px');
	$('.kmansara_top').css('left','12px');
	}
	
	$('#left_side1').after('<img src="../cmnfix/leftside_bottom1.jpg" style="position:relative;left:23px;">');
	$('#left_side2').after('<img src="../cmnfix/leftside_bottom2.jpg" style="position:relative;left:22px;">');
	$('#left_side3').after('<img src="../cmnfix/leftside_bottom3.jpg" style="position:relative;left:23px;">');

	$('.chasetbl0.lastChild').css('margin-bottom','60px');

	$('#contact form th:odd').css('background-color','#E0E0E0');
	$('.hissu').append('<span>*</span>');
	$('.home_sid_nav0.lastChild').css('background','#e3e3e3');

	
	
	$('#ech .history_tbl2').hover(
	function(){$(this).addClass('pink')},
	function(){$(this).removeClass('pink')}
	);

	$('#contact input,#contact textarea').focus(function(){$(this).addClass('formborder')});
	$('#contact input,#contact textarea').blur(function(){$(this).removeClass('formborder')});
	$('.imgfix img').css('margin-right','5px');
	$('.imgfix img.lastChild').css('margin-right','0');
});
