/*@cc_on _d=document;eval('var document=_d')@*/

/*--------------------------------------
Image Rollover Plugin
--------------------------------------*/

$(function(){
	$('img.rollover, .rollGroup img, input.rollover')
	.not('[src*="_o."]')
	.mouseover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_o$2'));
	})
	.mouseout(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)_o(\.[a-z]+)$/, '$1$2'));
	})
	.each(function(){
		$('<img>').attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_o$2'));
	})
	$('img.current')
	.mouseover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)_c(\.[a-z]+)$/, '$1_o$2'));
	})
	.mouseout(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)_o(\.[a-z]+)$/, '$1_c$2'));
	})
	.each(function(){
		$('<img>').attr('src',$(this).attr('src').replace(/^(.+)_c(\.[a-z]+)$/, '$1_o$2'));
	})
});

/*--------------------------------------
Fading Plugin
--------------------------------------*/

$(function(){
	$('.fading')
	.mouseover(function(){
		$(this).stop().fadeTo('fast', 0.6);
	})
	.mouseout(function(){
		$(this).stop().fadeTo('fast', 1);
	});
});

/*--------------------------------------
Page Scroller Plugin
--------------------------------------*/

(function($){
	$(function(){
		$('.scroll a[href^=#]').initScroll();
	});
	$.fn.initScroll = function(){
		return (this.each(function(){
			$(this).click(function(){
				var target = $('#' + this.getAttribute('href').split('#')[1]);
				if (target){
					$.scroller.start.init({
						endY:target.offset().top
					});
					return false;
				}
			});
		}));
	};
	$.scroller = {
		start: (function(){
			var params;
			var timerId;
			var stepCount = 0;
			var startY = 0;
			var endY = 0;
			var lastY = 0;
			function move(){
				if (stepCount == params.step){
					window.scrollTo(getCurrentX(), params.endY);
					stepCount = 0;
				}
				else if (lastY == getCurrentY()){
					stepCount++;
					window.scrollTo(getCurrentX(), getEasingY());
					lastY = getEasingY();
					timerId = setTimeout(move, Math.floor(1000/params.fps));
				}
			};
			var getCurrentY = function(){
				return (document.body.scrollTop || document.documentElement.scrollTop);
			}
			var getCurrentX = function(){
				return (document.body.scrollLeft || document.documentElement.scrollLeft);
			}
			var getEasingY = function(){
				return (Math.floor(getEasing(params.startY, params.endY, stepCount, params.step, params.easing)));
			}
			var getEasing = function(start, end, stepCount, step, easing){
				var s = stepCount / step;
				return ((end - start) * (s + easing / (100 * Math.PI) * Math.sin(Math.PI * s)) + start);
			}
			return {
				init: function(options){
					params = $.extend({
						easing:100,
						step:30,
						fps:80
					}, options);
					stepCount = 0;
					lastY = params.startY = getCurrentY();
					timerId = setTimeout(move, Math.floor(1000/params.fps));
				}
			};
		})()
	};
})(jQuery);

/*--------------------------------------
Simple Tabs Plugin
--------------------------------------*/

$(function(){
	$('.tabNav').each(function(){
		var tabs = $(this).find('a[href^=#]');
		var contents;
		tabs.each(function(){
			var selecter = $(this).attr('href');
			if (contents) {
				contents = contents.add(selecter);
			} else {
				contents = $(selecter);
			};
			$(this).click(function(){
				tabs.removeClass('active');
				$(this).addClass('active');
				$(selecter).fadeIn();
				contents.hide();
				$(selecter).show();
				return false;
			});
		});
		tabs.eq(0).trigger('click'); // eq(index)番目のタブを現行選択とする
	});
});

/*--------------------------------------
Accordion Plugin
--------------------------------------*/

$(function(){
	$('.question').hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','default');
		});
	$('.answer').css('display','none');
	$('.question').click(function(){
		$(this).next().toggle();
		});
});

/*--------------------------------------
Focus Form Plugin
--------------------------------------*/

$(function(){
	$('input[type="text"], input[type="password"], textarea, select').addClass('idle')
	.focus(function(){
		$(this).addClass('focus');
	})
	.blur(function(){
		$(this).removeClass('focus');
	});
});

/*--------------------------------------
Pop Up Window Plugin
--------------------------------------*/

$(function(){
	$('.popupWin').click(function(){
		w=window.open(this.href, 'popupWin', 'top=0, left=0, width=460, height=696, scrollbars=0, status=1, resizable=0');
		w.focus();
		return false;
	});
});

