/**
*
*
* bxSlider: Content slider / fade / ticker using the jQuery javascript library.
*
* Author: Steven Wanderski
* Email: wandoledzep@gmail.com
* URL: http://bxslider.com
* 
*
**/

jQuery.fn.bxSlider = function(options){
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Declare variables and functions
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var defaults = {
		mode: 'ticker',
		speed: 2000,
		auto: true,
		width: $(this).children().width(),
		ticker_direction: 'left',
		wrapper_class: 'outerContainer',
		cover_width: '800px'
	};
	
	options = $.extend(defaults, options);
	
	var $this = $(this);
	var $parent_width = options.width;
	
	
	
	function ticker() {
		$this.animate({'left':'-' + $parent_width * 2 + 'px'}, options.speed, 'linear', function(){
			$this.css({'left':'-' + $parent_width + 'px'}).children(':first').appendTo($this);
			ticker();
		});
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Create content wrapper and set CSS
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	$this.wrap('<div class="' + options.wrapper_class + '"></div>');
	
	$this.parent().css({
		'overflow' : 'hidden',
		'position' : 'relative',
//			'width' : '800px'
		'width' : options.cover_width + 'px'
//			'width' : options.width + 'px'
	});
		
	$this.css({
		'width' : '999999px',
		'position' : 'relative',
		'left' : '-' + $parent_width + 'px'
	});
		
	$this.children().css({
		'float' : 'left',
		'width' : $parent_width
	});

	$this.children(':last').insertBefore($this.children(':first'));

	//マウスオーバーでストップ
	$this.live("mouseover", function() {
		//stop anim
		$("div#viewer").stop(true);
		
	});
	
	//マウスアウトでスタート
	$this.live("mouseout", function(e) {
		ticker();
	});

	ticker();

}


