GGSB.modules.event = function(ggsb) {
	
	ggsb.initEvent = function() {
		$('.topRoundTabDisplay>div:visible .staticTable .holenum').live('click', function() {
			var holeId = ~~($(this).find('.holeNo').eq(0).html());
			if (!holeId) {
				ggsb.showCoverMapNoData();
				return;
			} else {
				ggsb.hideCoverMapNoData();
			}
			var scoreRecordId = ~~($(this).find('input[name=scoreRecordID]').val());
			
			var parent = $('li.jPicupRoundBox.selected');
			
			var obj = {holeId : holeId, index:$(this).index(), scoreRecordId : scoreRecordId, courseId : $(this).index() < 10 ? parent.find('.frontCourseID').eq(0).val() : parent.find('.backCourseID').eq(0).val()};
			
			$(window).trigger('changeHole', obj);
			
			ggsb.setScoreBoard(obj);
		}).css('cursor', 'pointer');
		
		$('.staticEachHoleTable .holeName span a').click(function() {
			//$('.popCourseSelect').toggle();
			
			return false;
		});
		
		$('.popCourseSelect li').bind('click', function() {
			
			var index = ($(this).index() + 2) + ($(this).parents('.inout').index() * 9);
			
			$('.topRoundTabDisplay>div:visible .staticTable .holenum:nth-child('+index+')').click();
			
			$('.popCourseSelect').toggle();
			
			return false;
		});
		
		$('table.staticEachHoleTable .holeName>.holeSelectBtnLeft>a').click(function() {
			
			var index = $('.topRoundTabDisplay>div:visible .staticTable>thead th.selected').index();
			if (index > 1) {
				$('.topRoundTabDisplay>div:visible .staticTable .holenum:nth-child('+(index)+')').click();
			} else {
				alert('これより前のホールは存在しません');
			}
			
			return false;
		});
		
		$('table.staticEachHoleTable .holeName>.holeSelectBtnRight>a').click(function() {
			
			var index = $('.topRoundTabDisplay>div:visible .staticTable>thead th.selected').index();
			if (index < 18) {
				$('.topRoundTabDisplay>div:visible .staticTable .holenum:nth-child('+(index+2)+')').click();
			} else {
				alert('これより後のホールは存在しません');
			}
			
			return false;
		});
		
		// スコア表示切替
		var first_time = true;
		$('.staticTable>tbody>tr:nth-child(2)').each(function() {
			$(this).find('td>span:not(.bottomLid)').hide();
		});
		$('.jsBtnChangeScoreMode').click(function() {
			var dom = $(this).parents('table').find('tbody>tr:nth-child(2)>td'),
				index = dom.find('span:visible:not(.bottomLid)').index();
			
			if (first_time || index <= 0) {
				first_time = false;
				index = 3;
			}
			
			//dom.find('span:nth-child('+index+'):not(.bottomLid)').hide();
			$('.staticTable>tbody>tr:nth-child(2)').each(function() {
				$(this).find('td>span:not(.bottomLid)').hide();
			});
			
			if (index++ >= dom.eq(0).find('span:not(.bottomLid)').length) {
				index = 1;
			}
			//dom.find('span:nth-child('+(index+1)+'):not(.bottomLid)').show();
			$('.staticTable>tbody>tr:nth-child(2)').each(function() {
				$(this).find('td>span:nth-child('+(index+1)+'):not(.bottomLid)').show();
			});
		}).click();
		
		
	};
	
	
	ggsb.setScoreBoard = function(args) {
		// スコア分布表更新
		var i,
			l,
			obj = ggsb.dataObj.getScoreRecord(args);
		
		// 自分のスコア
		var par;
		if (obj) {
			for (var key in obj) {
				$('.staticEachHoleTable tr:nth-child(2) .js'+key).html(obj[key]);
				if (key == 'PAR') {
					par = obj[key];
				}
			}
			if (par <= 3) {
				$('.staticEachHoleTable tr:nth-child(2) td:last span').attr('class', '').addClass('fwNotAvailable');
			} else
			if (obj.FAIRWAY_KEEP_FLG != false) {
				$('.staticEachHoleTable tr:nth-child(2) td:last span').attr('class', '').addClass('checkOn');
			} else {
				$('.staticEachHoleTable tr:nth-child(2) td:last span').attr('class', '').addClass('checkOff');
			}
		}
		
		
		// 地図上スコア表ハイライト
		$('.staticTable .selected').removeClass('selected');
		$('.topRoundTabDisplay>div:visible .staticTable tr:not(:first)>*:nth-child('+(args.index+1)+')').each(function() {
			$(this).addClass('selected');
		});
		
		
		$('#jsHoleName span a').empty().append('ホール'+args.holeId);
		
		$('.popCourseSelect li').removeClass('selected');
		var index = $('#HolenumSelected .selected').index();
		$('.popCourseSelect li').eq(index-1).addClass('selected');
	};
};

