//common jQuery command(commonJ)
jQuery(function() {
	var $ = jQuery;

	// 검색 바 클릭하면 input에 포커스 주도록
	$('#clickArea').click(function() {
		$('#searchValue').focus();
	});

	$('.bx_search form').submit(function() {
		f = document.search;
		str = f.searchValue.value;
		str = str.trim();
		if (!str) {
			alert("\n 검색어를 입력하세요");
			f.searchValue.focus();
			return false;
		}
		f.searchValue.value = str;

	});

	$('#wrapper').click(function() {
		$('#wInfo').hide();
	});

	$('.writer').live("click", function(event) {

		// 박스 o 원래사람 - 닫으면 됨
			// 박스 o 다른사람 - 닫고 정보 불러오고 위치 바꾼 후 켜야 함
			// 박스 x 다른사람 - 정보 불러오고 위치 바꾼 후 켜야 함
			// 박스 x 원래사람 - 켜야 함

			$('#wInfo dl dt, #wInfo dl dd').text('');

			var box = $('#wInfo').css('display');

			var sameW = ($('#wInfo dl dt').text() == $(this).find('.writerName').text());

			if (!sameW) {
				$('#wInfo').hide();
				// 정보 불러오는 로직
				$.post('/show/writerContents.marx', {
					writerNo : $(this).find('.writerNo').text(),
					hosu : $(this).find('.hosu').text()
				}, function(data) {
					$('.wInfoInner2').html(data);
					$('#wInfo').css( {
						'top' : event.pageY + 'px',
						'left' : event.pageX-200 + 'px'
					});
					$('#wInfo').fadeIn();
				});

			}
			if (box == 'none' && sameW) {
				$('#wInfo').fadeIn();
			}
		})
		$('.writerName').css({
			'cursor':'pointer',
			'border-bottom':'1px dashed #566A8B',
			'color':'#566A8B'
		});
	$('.cButton').live('click', function() {
		$(this).parent().parent().hide();
	});

	$('.hoName').click(function() {
		var hoName = $(this);
		if (hoName.next().css('display') == 'none') {
			$.post("/show/preLists.marx", {
				hosu : $(this).find('.hosu').text()
			}, function(data) {
				hoName.next().html(data).show();
			});
		} else {
			hoName.next().hide();
		}
	});
	// 최신호 보이게 하기
	$('#snb .latestHo .hoName').click();

	$('.gray').each(function() {
		$(this).height($(this).parent().height() - 10);
	});
	
	//js켰을 때 보이게 할 것들
	$('.showIfJs').show();
	
	// openNext 클래스를 가진 놈 부모($(this).parent())의 다음 놈은 다
	// 감추고($(this).parent().next().hide()), 누르면 다음 놈이 열리게 만든다.
	$('.openNext').each(function() {
		$(this).parent().next().hide();
	});

	$('.openNext').live('click',function() {
		$(this).parent().next().slideToggle('slow');
	});

});

/**
 * 정보 메세지 출력 함수 by mytory
 */
function infoMsg(text) {
	jQuery('body').append('<div class="infoArea"></div>');
	jQuery('.infoArea').text(text).css( {
		left : (jQuery('body').width() - jQuery('.infoArea').width()) / 2 + 'px',
		top : 0
	}).fadeIn('slow').delay(3000).fadeOut('slow', function() {
		jQuery(this).remove();
	});
}

