﻿/**
 * @requires jQuery 1.4.1+
 * @requires jQuery Easing Plugin
 *
 */
jQuery.noConflict();
jQuery(function($) {

	function setSlideList( wrap, auto ){
		// settings
	
		// 最初の待ち時間
		var firstDelay	= 2000;

		// 動き終わり～動き始め
		var interval	= 10000;

		// 動くのにかける時間
		var duration	= 2000;

		// 動きの種類
		var easing	= 'easeOutExpo';

		// 動く幅
		var width = 179;
	
		// for Automation
		var enableAutomation = auto;
		var $wrapArea = $('.inner', wrap);
		var $list = $('.slide', wrap);
	
		var num = $('li', $list).size();
		var cur = 0;

		// 要素が三つ以下なら矢印を表示しない(機能もない)
		if( num <= 5 ) return false;
	
		$list.css({
			'width'	: ( width * num ) + 'px'
		});
	
		var $_prev = $('<p class="slidelist_prev"><a href="#">前へ</a></p>').appendTo($wrapArea);
		var $_next = $('<p class="slidelist_next"><a href="#">次へ</a></p>').appendTo($wrapArea);
	
		var $prev = $('a', $_prev);
		var $next = $('a', $_next);
	
		$.each([$prev, $next], function(i,v){
			v.click(function(e) { e.preventDefault(); });
		});
		$prev.click(function() {
			moveList(-1, false);
		});
		$next.click(function() {
			moveList(+1, false);
		});
	
		var _timer;
		function setListInterval(int) { 
			clearInterval(_timer);
			_timer = setInterval(function() { moveList(+1, true); }, int);
		};
	
		function moveList(n, rotation) {
			if ( n == 0 || cur + n < 0 ) {
				return;
			} else if ( cur + n >= num - 4 ) {
				if ( rotation ) {
					n = ( cur + n - num + 4 ) - cur;
					// 戻るときに時間をプラス
					// duration+=1500;
				} else {
					return;
				}
			}
	
			cur += n;
			$list.stop(true, true).animate({left: '-=' + width * n + 'px'}, duration, easing);
	
			if( enableAutomation ) setListInterval( interval + duration );
		};
	
		if( enableAutomation ) setListInterval(firstDelay);
	}

	setSlideList($('#banner'), true);
});

/**
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright c 2008 George McGinley Smith
 * All rights reserved.
 *
 */
jQuery.extend(jQuery.easing, {
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	}
});


