var IsCursorInEventCalendarBox = 0;
var IsCursorInEventCalendarTip = 0;

jQuery(document).ready(
	function(){
		setEventCalendarEvent();
	}
);

function moveTopicsTab (tabid) {
	jQuery("div.TpcMainBoxpage").each(
		function() {
			if (jQuery(this).is(tabid)) {
				jQuery(this).css('display', 'block');
			}
			else {
				jQuery(this).css('display', 'none');
			}
		}
	);
}


function setEventCalendarEvent () {
	jQuery(
		function(){
			jQuery("div#EventCalendar").hover(
				function(){
					IsCursorInEventCalendarBox = 1;
					hideEventCalendar();
				},
				function(){
					IsCursorInEventCalendarBox = 0;
					if (IsCursorInEventCalendarBox == 0 && IsCursorInEventCalendarTip == 0) {
						hideEventCalendar();
					}
					//this.style.backgroundColor = "white";
					//hideEventCalendar();
				}
			);
		}
	);

	jQuery(
		function(){
			jQuery("div#EventCalendar li[id^='ec']").hover(
				function(){
					var posLeft = 0;
					var posTop = 0;
					if (typeof document.documentElement.style.maxHeight != 'undefined') {
						posLeft = parseInt(jQuery(this).offset().left);
						posTop  = parseInt(jQuery(this).offset().top);
					}
					else {
						posLeft = parseInt(jQuery(this).position().left);
						posTop  = parseInt(jQuery(this).position().top);
					}
					evid = jQuery(this).attr('id');
					showEventCalendar(evid, posLeft, posTop);
				},
				function(){
					//this.style.backgroundColor = "white";
					//hideEventCalendar();
				}
			);
		}
	);

	jQuery(
		function(){
			jQuery("div.EventCalendarTip").hover(
				function(){
					IsCursorInEventCalendarTip = 1;
				},
				function(){
					IsCursorInEventCalendarTip = 0;
					if (IsCursorInEventCalendarBox == 0 && IsCursorInEventCalendarTip == 0) {
						hideEventCalendar();
					}
					//this.style.backgroundColor = "white";
					//hideEventCalendar();
				}
			);
		}
	);

	jQuery("div#EventCalendar li[id^='ec']").each(function(){this.style.backgroundColor = '#FCF';});
}




function showEventCalendar (evid, posLeft, posTop) {
	jQuery("div.EventCalendarTip").each(
		function(){
			if (jQuery(this).is('#'+evid)) {
				jQuery(this).css('top', posTop - jQuery(this).outerHeight() + 10);
				jQuery(this).css('left', posLeft - jQuery(this).outerWidth() + 10);
							jQuery(this).css('display','block');
			}
			else{
							jQuery(this).css('display','none');
			}
		}
	);
}

function hideEventCalendar () {
	jQuery("div.EventCalendarTip").each(function(){jQuery(this).css('display','none');});
}

function moveEventCalendar (year, month) {
	var url = 'index.html.getEventCalendar.php';
	jQuery.post(
		url,
		{ YEAR: year, MONTH: month },
		function (data) {
			jQuery('div#EventCalendarBoxGroup').html(data);
			setEventCalendarEvent();
		}
	);
}

function showTopic (topicid) {
	//var url = 'topics/showTopicThickbox.php';
	/*
	var url = 'topics/LightBox.html';
	jQuery.post(
		url,
		{ TOPICID: topicid },
		function (data) {
			jQuery('div#TopicContentBox').html(data);
			tb_show('TOPICS 詳細', '#TB_inline?height=400&width=800&inlineId=TopicContentBox', 'dm');
		}
	);
	*/
	var url = 'topics/topicsInIframe.php?TOPICID='+topicid;
	tb_show('TOPICS 詳細', url + '&TB_iframe=true&height=400&width=800', 'dm');
}

function closeTopic () {
	tb_remove();
}

function ExecMemberLogin () {
	jQuery.post(
		'mmbLogin.php',
		jQuery("#FmLogin").serialize(),
		function (data) {
			if (data == 'OK') {
				alert('ログインしました');
			}
			else if (data == 'NGCOOKIE') {
				alert('ログインできません\n\nブラウザのCookieを有効にしてください');
			}
			else {
				alert('ログインできません\n\nメールアドレスまたはパスワードを確認してください\nメールアドレス・パスワードは大小文字を区別します');
			}
			reloadCoreClubMembersBox();
		}
	);
}

function ExecMemberLogout () {
	jQuery.post(
		'mmbLogout.php',
		function (data) {
			if (data == 'OK') {
				alert('ログアウトしました');
			}
			else {
				alert('ログアウトできませんでした');
			}
			reloadCoreClubMembersBox();
		}
	);
}

function reloadCoreClubMembersBox () {
	jQuery.post(
		'index.html.getCoreClubMembers.php',
		function (data) { jQuery('div#CoreClubMemberBox').html(data); }
	);
}

