/**
 * @file slideshow.js
 */
jQuery(function() {
	function mainGallery() {
		var _elmn = jQuery('#slideshow img');
		var _total = _elmn.length;
		var _current = Math.floor(Math.random() * _total)
		var _time = 1000;
		var _delay = 5000;
		
		function loop() {
			if (_current >= _total - 1) {_current = -1;}
			_current++
			var _preCurrent = _current - 1;
			if (_current == 0) {_preCurrent = _total - 1;}
			
			_elmn.eq(_preCurrent).css('z-index','0');
			_elmn.eq(_current).css('z-index','10').fadeIn(_time, function() {
				_elmn.eq(_preCurrent).hide();
			});
			_timer = setTimeout(loop, _delay)
		}
		
		_elmn.hide();
		_elmn.eq(_current).show(0).delay(_delay).show(0, loop);
	}
	mainGallery();
	
	function amGallery() {
		var _parent = jQuery(".attraction .productShow .showAreaInner");
		var _elmn = jQuery(".attraction .productShow .showAreaInner .each");
		var _total = _elmn.length;
		var _current = 0;
		var _width = _elmn.eq(0).width();
		var _time = 500;
		var _easing = 'swing';
		var _delay = 10000;
		var _timer = null;
		
		_elmn.each(function(_e) {
			jQuery(this).css('left', _e * _width);
		});
		_parent.css('width', _width * (_total - 1));
		
		function bnMcAppendImg() {
			var _html = '<div class="each">' + jQuery('.each:first', _parent).html() + '</div>';
			_parent.append(_html);
			jQuery('.each:last', _parent).css('left', _width * _total);
		}
		
		function loop() {
			bnMcAppendImg();
			jQuery(".attraction .productShow .showAreaInner .each").each(function(_e) {
				var _tX = jQuery(this).position().left;

				jQuery(this).animate({
					'left': _tX - _width
				}, _time, _easing, function() {
					if ((_e + 1) == _total) {
						jQuery('.each:first', _parent).remove();
					}
				});
			});
			
			_timer = setTimeout(loop, _delay)
		}
		
		_elmn.parent().delay(_delay).show(0, loop);
	}
	amGallery();
	
	jQuery('#historyBooklet').booklet({
		auto: true,
		speed: 250,
		delay: 5000,
		width: 216,
		height: 162,
		pagePadding: 0,
		pageNumbers: false,
		shadow: true,
		manual: false,
		overlays: true,
		hovers: true
	});
});
