/* 내 단어장 */
var calendarCategoryValue = null;

function onChangedCalendarCategory(oItem)
{
	calendarCategoryValue = oItem.value ;

	ajax.action(gSelf);
	ajax.clearValue();
	ajax.setValueFromObject({
			action:'GetCalendar',
			calendar_category:oItem.value,
			inquiryMonth:g('inquiryMonth').value
		}); // form 값

	// 결과 처리 후, 화면 갱신이 이뤄질 AJAX ID
	ajax.call("calendar", false, function()
	{
		setTimeout(function()
		{
			applyJQuerySelect();
		},1);
	});
}

function redrawCalendar(inquiryMonth)
{
	g('inquiryMonth').value = inquiryMonth;

	var oRadio = $(':radio[name="calendar_category"]:checked');

	if (oRadio.length < 1)
	{
		alert("선택된 분류가 없습니다.\n\n달력에 표시될 강좌를 선택하세요.");
		return ;
	}

	onChangedCalendarCategory(oRadio[0]);
}

function applyJQuerySelect()
{
	jQuery(function($){
		
		// Common
		var select_root = $('div.select');
		var select_value = $('.myValue');
		var select_a = $('div.select>ul>li>a');
		var select_input = $('div.select>ul>li>input[type=radio]');
		var select_label = $('div.select>ul>li>label');
		
		// Radio Default Value
		$('div.myValue').each(function(){
			var default_value = $(this).next('.iList').find('input[checked]').next('label').text();
			$(this).append(default_value);
		});
		
		// Line
		select_value.bind('focusin',function(){$(this).addClass('outLine');});
		select_value.bind('focusout',function(){$(this).removeClass('outLine');});
		select_input.bind('focusin',function(){$(this).parents('div.select').children('div.myValue').addClass('outLine');});
		select_input.bind('focusout',function(){$(this).parents('div.select').children('div.myValue').removeClass('outLine');});
		
		// Show
		function show_option(){
			$(this).parents('div.select:first').toggleClass('open');
		}
		
		// Hover
		function i_hover(){
			$(this).parents('ul:first').children('li').removeClass('hover');
			$(this).parents('li:first').toggleClass('hover');
		}
		
		// Hide
		function hide_option(){
			var t = $(this);
			setTimeout(function(){
				t.parents('div.select:first').removeClass('open');
			}, 1);
		}
		
		// Set Input
		function set_label(){
			var v = $(this).next('label').text();
			$(this).parents('ul:first').prev('.myValue').text('').append(v);
			$(this).parents('ul:first').prev('.myValue').addClass('selected');
		}
		
		// Set Anchor
		function set_anchor(){
			var v = $(this).text();
			$(this).parents('ul:first').prev('.myValue').text('').append(v);
			$(this).parents('ul:first').prev('.myValue').addClass('selected');
		}

		// Anchor Focus Out
		$('*:not("div.select a")').focus(function(){
			$('.aList').parent('.select').removeClass('open');
		});

		select_value.click(show_option);
		select_root.removeClass('open');
		select_root.css('visibility','visible');
		select_root.mouseleave(function(){$(this).removeClass('open');});
		select_a.click(set_anchor).click(hide_option).focus(i_hover).hover(i_hover);
		select_input.change(set_label).focus(set_label);
		select_label.hover(i_hover).click(hide_option);
	});
}

applyJQuerySelect();

function showStudyInfo(current_date)
{
	ajax.action(gSelf);
	ajax.clearValue();
	ajax.setValueFromObject({
			action:'GetStudyInfo',
			current_date:current_date,
			calendarCategoryValue:calendarCategoryValue
		}); // form 값

	// 결과 처리 후, 화면 갱신이 이뤄질 AJAX ID
	ajax.call("studyInfo", false, function()
	{
		setTimeout(function()
		{
			var title = $('#studyInfo_title').val();

			var body = 'divStudyInfo';
			var width = 495;
			var height = 200;

			showMsgBox(title, body, width, height);			
		},1);
	});
}


