//var lifeCheckStatusObj = new Object({'stat':false,'width':50,'height':50,'lastWidth':520,'lastHeight':590});
var lifeCheckStatusObj = new Object({'stat':false,'width':520,'height':590,'lastWidth':520,'lastHeight':590});

$(function() {
	$('#showResultButton').click(function () {
		if (lifeCheckStatusObj.stat) return;	//現在表示中であれば、中止
		lifeCheckStatusObj.stat = true;
//		alert(document.body.scrollHeight);
		var count = 0;
		//チェック数をカウント
		$("#checksheet-ch input:checked").each(function() {
			count++;
		});

		var rendWidth = rendHeight = 0;
		//レンダリングエリアサイズの取得
		if(!window.innerWidth) {		//IEの場合
			rendWidth = document.documentElement.offsetWidth - 20;
			rendHeight = document.documentElement.offsetHeight;
			delay = 2;
		} else {
			rendWidth = window.innerWidth - 16;
			rendHeight = window.innerHeight;
			delay = 1;
		}
		bodyHeight = document.body.scrollHeight;

		lifeCheckStatusObj.resultDivLeft = Math.floor(((rendWidth - lifeCheckStatusObj.width) / 2),0);
		lifeCheckStatusObj.resultDivTop = Math.floor(((rendHeight - lifeCheckStatusObj.height - 15) / 2),0) -10;

		$('body').append('<div id="resultBackground"></div>');
		$('#resultBackground').css('background-color','#fff');
		$('#resultBackground').css('position','absolute');
		$('#resultBackground').css('z-index','1000');
		$('#resultBackground').css('filter', 'Alpha(opacity=80)');
		$('#resultBackground').css('-moz-opacity','0.8');
		$('#resultBackground').css('opacity','0.8');
		$('#resultBackground').css('height', (bodyHeight) + 'px');
//		$('#resultBackground').css('width', rendWidth + 'px');
		$('#resultBackground').css('width', '100%');
		$('#resultBackground').css('top', '0');
		$('#resultBackground').css('left', '0');

		$('#resultBackground').animate({
			opacity:'0.6',
			'-moz-opacity':'0.6',
			filter: 'Alpha(opacity=60)'
		}, 100*delay, "linear");
/*
		$('#resultBackground').animate({
			opacity:'0.5',
			'-moz-opacity':'0.5',
			filter: 'Alpha(opacity=50)'
		}, 200, "linear");
*/
//		$('body').append($.get('/img/wd-check/check_result2.gif',{},alert(rData)));
		if (count <= 2) {
			$('body').append('<div style="" id="resultDIV"><img id="resultImg" src="/img/wd-check/check_result2.gif" width="520" height="590"></div>');
		} else if (count>=5) {
			$('body').append('<div style="" id="resultDIV"><img id="resultImg" src="/img/wd-check/check_result5.gif" width="520" height="590"></div>');			
		} else {
			$('body').append('<div style="" id="resultDIV"><img id="resultImg" src="/img/wd-check/check_result3.gif" width="520" height="590"></div>');			
		}
		$('#resultDIV').css('position','absolute');
		$('#resultDIV').css('z-index','1001');
		$('#resultDIV').css('margin','0');
		$('#resultDIV').css('padding','0');
		$('#resultDIV').css('left', lifeCheckStatusObj.resultDivLeft + 'px');
		$('#resultDIV').css('top', lifeCheckStatusObj.resultDivTop + $(document).scrollTop() + 'px');
		$('#resultDIV').css('width', (lifeCheckStatusObj.width)+'px');
		$('#resultDIV').css('height', lifeCheckStatusObj.height + 'px');

		$('#resultImg').click(function() {
			$('#resultDIV').fadeOut('slow').slideUp("slow");
			$('#resultBackground').fadeOut('slow');
			$('#resultDIV').remove();
			$('#resultBackground').remove();
			lifeCheckStatusObj.stat = false;
		});

		$('#resultBackground').click(function() {
			$('#resultDIV').fadeOut('slow').slideUp('slow');
			$('#resultBackground').fadeOut('slow');
			$('#resultDIV').remove();
			$('#resultBackground').remove();
			lifeCheckStatusObj.stat = false;
		});
		$('#resultDIV').animate(({
			opacity:'1.0',
			'-moz-opacity':'1.0',
			filter: 'Alpha(opacity=100)',
			top:lifeCheckStatusObj.resultDivTop + $(document).scrollTop() + 10
		}), 500*delay, "linear");
	});
});