$(function() {
	slideShow();
	initEnjoy();
});

function slideShow()
{
	$('#bg img:first').addClass('current');
	var list = $('#bg img');
	var num = list.length;
	var current = list.eq(0);
	var next = list.eq(1);
	var nextNum = 1;
	
	function changeImage()
	{
		current.fadeOut(1500, function(){
			
			current.removeClass('current');
			current = next;
			if(nextNum >= num-1)
			{
				nextNum = 0;
			}
			else
			{
				nextNum++;
			}
			next = list.eq(nextNum);
		});
		
		current.css('z-index', '20');
		next.css('z-index', '10');
		
		next.show();
		next.addClass('current');
		setSize();
	}
	
	/*
	setTimeout(function(){
			changeImage();
			setInterval(changeImage, 6000);
		}, 4000);
	*/
	
	function setSize()
	{
		//画像サイズ指定
		var img = $('#bg img');
		var imgW = img.width();
		var imgH = img.height();
			
		//ウィンドウサイズ取得
		var winW = $(window).width();
		var winH = $(window).height();
		var scaleW = winW / imgW;
		var scaleH = winH / imgH;
		var fixScale = Math.max(scaleW, scaleH);
		var setW = imgW * fixScale;
		var setH = imgH * fixScale;
		var moveX = Math.floor((winW - setW) / 2);
		var moveY = Math.floor((winH - setH) / 2);
		
		$('#bg img.current').css({
			'width': setW,
			'height': setH
		})
		$('#bg').css({
			'left' : moveX,
			'top' : moveY
		});
	}
	
	$(window).resize(function(){
	   setSize();
	});
	
	setSize();
	setTimeout(setSize, 200);
}

function initEnjoy()
{
	var isShow = false;
	var enjoyBalloon = $('#enjoy');
	var enjoyHitarea = $('#enjoy-bg-area');
	
	enjoyHitarea.toggle(slideUp, slideDown);
	
	/*
	enjoyHitarea.mouseover(function(e) {
		
		slideUp();
	});
	
	enjoyHitarea.click(function(e) {
		
		slideDown();
	});
	*/
	
	function slideUp()
	{
		isShow = true;
		
		enjoyBalloon
			.stop()
			.animate({ 
				'bottom':'74px'
			 },
			 800,
			 "easeOutExpo");
			 
		$('#enjoy-bg-show').css('display', 'block');
		$('#enjoy-bg-hide').css('display', 'none');
	}
	
	function slideDown()
	{
		enjoyBalloon
			.stop()
			.animate({ 
				'bottom':'-4px'
			},
			700,
			"easeOutExpo",
			function(){ isShow = false }
			);
		
		$('#enjoy-bg-show').css('display', 'none');
		$('#enjoy-bg-hide').css('display', 'block');
	}
}

