/* png 파일  */
function setPng24(obj) {
	obj.width = obj.height = 1;
	if (obj.className != "xP") {
		obj.className = "xP";
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "',sizingMethod='image');"
		obj.src = '';
	}
	return '';
}

/* 새창 띄우기 class */
$(document).ready(function() {
	$('.newWin, .blank').click(function(event){
		event.preventDefault();
		window.open(this.href);
	});
});


/* 게시판 hover 배경 변경 */
$(document).ready(function() {
	$('.basicList td').hover(function(event) {
		jQuery(event.target).parent('tr').css("background", "#F7F7F7");
	}, function(event) {
		jQuery(event.target).parent('tr').css("background", "");
	})
});



/* 폰트 사이즈 조절 */
var fSize = '0.75em';
 function fnFontSize(state) {
 	// fSize = getStyle(document.body, 'fontSize');
 	fSize = fSize.split('em')[0];
 	fSize = parseFloat(fSize);
 	if (state == 'up' && fSize <= parseFloat(1.5)) {
 		fSize = fSize + 0.2;
 	} else if (state == 'down' && fSize >= parseFloat(0.5)) {
 		fSize = fSize - 0.2;
 	} else if (state == 'default') {
 		fSize = 0.75;
 	} else {
 		alert('최소, 최대값입니다.');
 	}
 	fSize = fSize + 'em';
 	document.body.style.fontSize = fSize;
 	return false;
 }



/* Navigation */
function naviAction() {
	var gnbD1 = $('#gnb > ul:first > li > a');
	var gnbD2 = gnbD1.parent().find('li > a');

	var lnbD2 = $('.lnb > li > a');
	var lnbD3 = $('.lnb > li > ul > li > a');
	var lnbD4 = $('.lnb > li > ul > li > ul > li > a');

	var className = 'on';
	var lFlag = false;
	var gFlag = false;

	var imgOn = 'On.gif';
	var imgOff = 'Off.gif';

	var gnbPrev = $('.topSearch').find('input:last');
	var gnbNext = lnbD2.eq(0);

	var docTitle = $('span:first', '#location').text();
	var lnbTitle;

	// LNB 4Depth 탐색
	lnbD4.each(function(){
		var onLnb = $(this);
		var onText = onLnb.text();
		if($.browser.msie){
			onText = $(onLnb.parent().html().replace('<BR>', ' ')).text();
		}
		if(onText == docTitle){
			var tImg = onLnb.addClass(className).parents('ul:first').parents('li:first').children('a:first').addClass(className).parents('ul:first').parents('li:first').children('a:first').addClass(className).children('img:first');
			lnbTitle = tImg.attr('src', tImg.attr('src').replace(imgOff, imgOn)).attr('alt');
			lFlag = true;
		}
	});

	// LNB 3Depth 탐색
	if(!lFlag && lnbD3.length > 0){
		lnbD3.each(function(){
			var onLnb = $(this);
			var onText = onLnb.text();
			if($.browser.msie){
				onText = $(onLnb.parent().html().replace('<BR>', ' ')).text();
			}
			if(onText == docTitle){
				var tImg = onLnb.addClass(className).parents('ul:first').parents('li:first').children('a:first').addClass(className).children('img:first');
				lnbTitle = tImg.attr('src', tImg.attr('src').replace(imgOff, imgOn)).attr('alt');
				lFlag = true;
			}
		});
	}

	// LNB 2Depth 탐색
	if(!lFlag && lnbD2.length > 0){
		lnbD2.each(function(){
			var onLnb = $(this);
			if(onLnb.children('img:first').attr('alt') == docTitle){
				var tImg = onLnb.addClass(className).children('img:first');
				lnbTitle = tImg.attr('src', tImg.attr('src').replace(imgOff, imgOn)).attr('alt');
			}else if(onLnb.text() == docTitle){
				onLnb.addClass(className);
				lnbTitle =  docTitle;
			}
		});
	}


	// GNB 2Depth 탐색
	if(lnbTitle)
	{
		gnbD2.each(function()
		{
			var onGnb = $(this);
			if(onGnb.children('img:first').attr('alt') == lnbTitle)
			{
				var tImg = onGnb.parents('ul:first').parents('li:first').find('a:first').addClass(className).find('img:first');
				tImg.attr('src', tImg.attr('src').replace(imgOff, imgOn)).parent().next('div:first').css({display:'block'});
				//
				var tImg2 = onGnb.addClass(className).find('img:first');
				tImg2.attr('src', tImg2.attr('src').replace(imgOff, imgOn));


			}
		});
	}

	// GNB 1Depth 탐색
	if(!gFlag && lnbTitle){
		gnbD1.each(function(){
			var onGnb = $(this);
			if(onGnb.children('img:first').attr('alt') == lnbTitle)
			{
				var tImg = onGnb.addClass(className).find('img:first');
				tImg.attr('src', tImg.attr('src').replace(imgOff, imgOn));
			}

			// fallback
			if(!lFlag && lnbD2.length == 1){
				if(onGnb.children('img:first').attr('alt') == $('.lnb').prev().find('img:first').attr('alt')){
					var tImg = onGnb.addClass(className).find('img:first');
					tImg.attr('src', tImg.attr('src').replace(imgOff, imgOn));
				}
			}
		});
	}


	// GNB 2Depth 롤오버
	gnbD2.bind('mouseover focus', function(){
		var onGnb = $(this);
		if(!onGnb.hasClass(className)){
			onGnb.children('img:first').attr('src', onGnb.children('img:first').attr('src').replace(imgOff, imgOn));
		}
	})
	.bind('mouseout blur', function(){
		var onGnb = $(this);
		if(!onGnb.hasClass(className)){
			onGnb.children('img:first').attr('src', onGnb.children('img:first').attr('src').replace(imgOn, imgOff));
		}
	});


	// GNB 1Depth 롤오버
	gnbD1.bind('mouseover focus', function(){
		var onGnb = $(this);
		gnbD1.next().hide();
		if(onGnb.next('div:first')){
			if(!onGnb.hasClass(className)){
				onGnb.children('img:first').attr('src', onGnb.children('img:first').attr('src').replace(imgOff, imgOn));
			}
			onGnb.next('div:first').show();
		}
	})
	.bind('mouseout blur', function(){
		var onGnb = $(this);
		if(onGnb.next('div:first')){
			if(!onGnb.hasClass(className)){
				onGnb.children('img:first').attr('src', onGnb.children('img:first').attr('src').replace(imgOn, imgOff));
			}
		}
	});

	// LNB 2Depth 롤오버
	lnbD2.bind('mouseover focus', function(){
		var onlnb = $(this);
		if(!onlnb.hasClass(className)){
			onlnb.children('img:first').attr('src', onlnb.children('img:first').attr('src').replace(imgOff, imgOn));
		}
	}).bind('mouseout blur', function(){
		var onlnb = $(this);
		if(!onlnb.hasClass(className)){
			onlnb.children('img:first').attr('src', onlnb.children('img:first').attr('src').replace(imgOn, imgOff));
		}
	});

	// gnb 2뎁스 활성화시 1뎁스 오버기능 활성화 시켜놓기
	$('#gnb > ul:first > li ul').mouseover(function(){
		var onlnb = $(this);
		var tmpImg = onlnb.parents('li:first').find('img:first');
		tmpImg.attr('src', tmpImg.attr('src').replace(imgOff, imgOn));
	}).mouseout(function(){
		var onlnb = $(this);
		var tmpImg = onlnb.parents('li:first').find('img:first');
		if(!onlnb.parents('li:first').find('a:first').hasClass(className)){
			tmpImg.attr('src', tmpImg.attr('src').replace(imgOn, imgOff));
		}
	});





	gnbD2.each(function(){
		var onlnb = $(this);
		onlnb.focus(function(){
			var tmpImg = onlnb.parents('ul:first').parents('li:first').find('img:first');
			tmpImg.attr('src', tmpImg.attr('src').replace(imgOff, imgOn));
		}).blur(function(){
			var tmpImg = onlnb.parents('ul:first').parents('li:first').find('img:first');
			if(!onlnb.parents('ul:first').parents('li:first').find('a:first').hasClass(className)){
				tmpImg.attr('src', tmpImg.attr('src').replace(imgOn, imgOff));
			}
		});

	});

	/* LNB 접기펴기, 기능 사용할 LNB에 fold 클래스 추가 */
	if($('.lnb').hasClass('fold')){
		$('.lnb > li > ul').hide();
		lnbD2.each(function(){
			var onLnb = $(this);
			if(onLnb.hasClass(className)){
				onLnb.parent().children('ul').show();
			}
		});
	}

	// GNB 초기화
	$('#gnb').bind('mouseleave', function(){
		initGnb();
	});

	gnbNext.focus(function(){
		initGnb();
	});

	gnbPrev.focus(function(){
		initGnb();
	});

	function initGnb(){
		gnbD1.next().hide().prev().filter('[class=on]').next('div:first').show();
	}
}



$(document).ready(function() {
	naviAction();

	$('input[type=text]').each(function(){
		var oInput = $(this);
		var oText = oInput.attr('value');
		oInput.focus(function(){
			if(oInput.attr('value') == oText){
				oInput.attr('value', '');
			}
		});
		oInput.blur(function(){
			if(oInput.attr('value') == ''){
				oInput.attr('value', oText);
			}
		});
	});

	$('a', '.special').bind('focus mouseover', function(event){
		var oImg = $(this).find('img:first');
		var oSrc = oImg.attr('src');
		oImg.attr('src', oSrc.replace('Off.gif', 'On.gif'));
	});
	$('a', '.special').bind('blur mouseout', function(event){
		var oImg = $(this).find('img:first');
		var oSrc = oImg.attr('src');
		oImg.attr('src', oSrc.replace('On.gif', 'Off.gif'));
	});

	// 퀵메뉴 이미지 오버
	$('a', '#quickMenu').bind('focus mouseover', function(event){
		var oImg = $(this).find('img:first');
		var oSrc = oImg.attr('src');
		oImg.attr('src', oSrc.replace('Off.gif', 'On.gif'));
	});
	$('a', '#quickMenu').bind('blur mouseout', function(event){
		var oImg = $(this).find('img:first');
		var oSrc = oImg.attr('src');
		oImg.attr('src', oSrc.replace('On.gif', 'Off.gif'));
	});

});


/* 탭메뉴 - 메인공지등 */
function useTab(node1, node2, node3, isOff, png) {
	var wrapId = node1;
	var btnTag = (!node2 ? 'h2' : node2);
	var contTag = (!node3 ? 'ul' : node3);
	var offString = (!isOff ? '' : isOff);
	var isPng = (!png ? false : true);
	var onString = 'On';
	var menus = $(wrapId + '>' + btnTag);

	$(wrapId).addClass('script');

	$(menus)
			.each(
					function(i) {
						$(this).find('a').bind('focusin mouseover', function() {
							focusEvent(i)
						});

						if (i == 0) {
							$(menus[i]).next(contTag).show();

							if (isPng) {
								var path = $(menus[i]).find('img').attr('src')
										.replace(onString, '').split('.');
								var dataLength = path.length;
								$(menus[i])
										.find('img')
										.attr(
												'style.filter',
												"\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'\""
														+ path[dataLength - 2]
														+ onString
														+ '.png'
														+ "\"\',sizingMethod=\'image\');\"");
							}
							if ($(wrapId + '> p')[i])
								$(wrapId + '> p')[i].style.zIndex = 1;
						} else {

							$(menus[i]).next(contTag).hide();
							if ($(menus[i]).find('img')) {
								if (isPng) {
									var path = $(menus[i]).find('img').attr(
											'src').replace(onString, '').split(
											'.');
									var dataLength = path.length;
									$(menus[i])
											.find('img')
											.attr(
													'style.filter',
													"\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'\""
															+ path[dataLength - 2]
															+ offString
															+ '.png'
															+ "\"\',sizingMethod=\'image\');\"");
								} else {
									var data = $(menus[i]).find('img').attr(
											'src').replace(onString, '').split(
											'.');
									var dataLength = data.length;
									$(menus[i]).find('img').attr(
											'src',
											data[dataLength - 2] + offString
													+ '.'
													+ data[dataLength - 1]);
								}
							}
						}
					});

	function focusEvent(x) {
		if ($(menus[x]).find('img')) {
			if (isPng) {
				var data = $(menus[x]).find('img').attr('style').split('.png');
				var dat = data[0].split('src=');
				$(menus[x]).find('img')[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="
						+ dat[1]
						+ onString
						+ '.png'
						+ "\',sizingMethod=\'image\');";
			} else {
				var data = $(menus[x]).find('img').attr('src').replace(
						onString, '').split('.');
				var dataLength = data.length;
				$(menus[x]).find('img').attr(
						'src',
						data[dataLength - 2] + onString + '.'
								+ data[dataLength - 1]);
			}
			if ($(wrapId + '> p')[x])
				$(wrapId + '> p')[x].style.zIndex = 1;
		}

		$(menus[x]).css( {
			'z-index' : '2'
		});
		$(menus[x]).addClass('On');
		$(menus[x]).next(contTag).show();

		for ( var i = 0; i < menus.length; i++) {

			if (i != x) {
				if ($(menus[i]).find('img')) {
					if (isPng) {
						var data = $(menus[i]).find('img').attr('style').split(
								'.png');
						var dat = data[0].split('src=');
						$(menus[i]).find('img')[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="
								+ dat[1]
								+ offString
								+ '.png'
								+ "\',sizingMethod=\'image\');";
					} else {
						var data = $(menus[i]).find('img').attr('src').replace(
								onString, '').split('.');
						var dataLength = data.length;
						$(menus[i]).find('img').attr(
								'src',
								data[dataLength - 2] + offString + '.'
										+ data[dataLength - 1]);
					}
				}
				$(menus[i]).css( {
					'z-index' : '0'
				});
				$(menus[i]).removeClass('On');
				$(menus[i]).next(contTag).hide();
				if ($(wrapId + '> p')[i])
					$(wrapId + '> p')[i].style.zIndex = -1;
			}
		}
	}
}





(function($) {
	$.fn.nCarousel = function(o) {
		o = $.extend( {
			btnPrev : null,
			btnNext : null,
			btnGo : null,
			mouseWheel : false,
			auto : null,

			speed : 200,
			easing : null,

			vertical : false,
			circular : true,
			visible : 5,
			start : 0,
			scroll : 1,

			centerFocus : false, // 가운데 이미지 확대여부
			focusSizeW : 150, // 확대되는 이미지의 폭
			focusSizeH : 245,
			clickMove : false, // 클릭된 이미지 이동 여부

			dispLayer : null, // 디스플레이 대상 영역
			dispClass : null, // 디스플레이 영역에 표현될 컨텐츠 영역
			dispName : '', // 디스플레이 영역에 표현될 이미지 추가 이름
			dispSize : 300, // 디스플레이 영역에 표시될 이미지 크기

			beforeStart : null,
			afterEnd : null,

			linkOn : false, // 이벤트 발생후 링크를 작동 시킬지 결정
			listType : 'ul' // 리스트 타입
		}, o || {});

		return this
				.each(function() {
					var running = false, animCss = o.vertical ? "top" : "left", sizeCss = o.vertical ? "height"
							: "width";

					var div = $(this), ul = $(o.listType, div), tLi = $("li",
							ul), tl = tLi.size(), v = o.visible;

					if (o.circular) {
						ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(
								tLi.slice(0, v).clone());
						o.start += v;
					}

					var li = $("li", ul), itemLength = li.size(), curr = o.start, oWidth = li
							.find('img').width(), oHeight = li.height(), autoInt, centerPos = parseInt(o.visible / 2);

					if (o.centerFocus && 1 == o.visible % 2) {
						for ( var i = 0; i < li.size(); i++) {
							$('img', li[i]).css( {
								width : o.reduceSize
							});
						}
					}

					li.css( {
						overflow : "hidden",
						float : o.vertical ? "none" : "left"
					});
					ul.css( {
						margin : "0",
						padding : "0",
						position : "relative",
						"list-style-type" : "none",
						"z-index" : "1"
					});
					div.css( {
						overflow : "hidden",
						position : "relative",
						"z-index" : "2",
						left : "0px",
						visibility : "visible"
					});

					var liSize = o.vertical ? height(li) : width(li); // 애니메이션을
																		// 위한
																		// 아이템의
																		// 길이
					var ulSize = liSize * itemLength; // 보여지지 않는 아이템을 포함한 전체
														// 길이
					var divSize = liSize * v;

					li.css( {
						width : li.width(),
						height : li.height()
					});
					ul.css(sizeCss, ulSize + "px").css(animCss,
							-(curr * liSize));
					div.css(sizeCss, divSize + "px"); // 리스트 표시 영역 폭. 보여지는
														// 아이템의 전체길이

					if (o.centerFocus && 1 == o.visible % 2) {
						var ulWidth = ulSize + o.focusSizeW - li.width();
						var divWidth = divSize + o.focusSizeW - li.width();
						ul.css( {
							width : ulWidth
						});
						div.css( {
							width : divWidth
						});
					}

					li
							.find('img')
							.click(function(event) { // 개별 이미지 클릭시 디스플레이 및 이동
										if (o.dispLayer) {
											var data = $(event.target).clone();
											var image = data.attr('src').split(
													'.');
											var iamgeSrc = data
													.attr('src')
													.replace(
															'.' + image[image.length - 1],
															o.dispName
																	+ '.'
																	+ image[image.length - 1]);
											data.attr('src', iamgeSrc);
											if (o.dispSize && o.dispSize != '') {
												data.css( {
													width : o.dispSize
												});
											}
											if (!o.centerFocus) {
												$(o.dispLayer).html(data);
											}
										}

										var obj = (window.event ? window.event.srcElement
												: event.target);
										var movePos;

										for ( var i = 0; i < itemLength; i++) {
											if (li.find('img')[i] == obj) {
												if (i != curr + centerPos) {
													movePos = i - curr
															- centerPos;
												}
											}
										}

										if (o.clickMove) {
											go(curr + movePos);
										}

										if (!o.linkOn) {
											event.preventDefault();
										}
									});

					li.find('img').mouseover(function() {
						stopAuto();
					});

					li.find('img').mouseout(function() {
						runAuto();
					});

					li.find('img').focus(function() {
						return false;
					});

					if (o.btnPrev) {
						$(o.btnPrev).click(function() {
							return go(curr - o.scroll);
						});
						$(o.btnPrev).bind("mouseover focus", function() {
							stopAuto();
						});
						$(o.btnPrev).bind("mouseout blur", function() {
							runAuto();
						});
					}

					if (o.btnNext) {
						$(o.btnNext).click(function() {
							return go(curr + o.scroll);
						});
						$(o.btnNext).bind("mouseover focus", function() {
							stopAuto();
						});
						$(o.btnNext).bind("mouseout blur", function() {
							runAuto();
						});
					}

					if (o.btnGo)
						$.each(o.btnGo, function(i, val) {
							$(val).click(function() {
								return go(o.circular ? o.visible + i : i);
							});
						});

					if (o.mouseWheel && div.mousewheel)
						div.mousewheel(function(e, d) {
							return d > 0 ? go(curr - o.scroll) : go(curr
									+ o.scroll);
						});

					runAuto();

					function stopAuto() {
						if (o.auto) {
							clearInterval(autoInt);
						}
					}

					function runAuto() {
						if (o.auto) {
							autoInt = setInterval(function() {
								go(curr + o.scroll);
							}, o.auto + o.speed);
						}
					}

					function vis() {
						return li.slice(curr).slice(0, v);
					}
					;

					function disp() { // 리스트의 지정된 컨텐츠를 다른 곳에 추가로 디스플레이
						if (o.dispLayer) {
							var data;
							var num;
							if (1 == o.visible % 2) { // visible이 홀수인경우 가운데,
														// 아닌경우 첫번째 영역 내용 표시
								num = curr + centerPos;
								data = $(li.find(o.dispClass)[num]).clone()
										.css( {
											'display' : 'block'
										});
							} else {
								num = curr;
								data = $(li.find(o.dispClass)[num]).clone()
										.css( {
											'display' : 'block'
										});
							}
							// alert(o.dispClass);
							if (data.get(0).nodeName == 'IMG') {/* */
								var image = $(li.find(o.dispClass)[num]).attr(
										'src').split('.');
								var iamgeSrc = $(li.find(o.dispClass)[num])
										.attr('src')
										.replace(
												'.' + image[image.length - 1],
												o.dispName
														+ '.'
														+ image[image.length - 1]);
								data.attr('src', iamgeSrc);
								if (o.dispSize && o.dispSize != '') {
									data.css( {
										width : o.dispSize
									});
								}
							}

							$(o.dispLayer).html(data);
						}
					}

					function resize() {
						if (o.centerFocus && 1 == o.visible % 2) {
							for ( var i = 0; i < itemLength; i++) {
								if (i == curr + centerPos) {
									$(li[i]).css( {
										width : o.focusSizeW,
										height : o.focusSizeH,
										margin : "0"
									});
									$('img', li[i]).css( {
										width : o.focusSizeW,
										height : o.focusSizeH
									});
								} else {
									var marginTop = parseInt(oHeight / 2);
									$(li[i]).css( {
										width : oWidth,
										height : oHeight,
										margin : marginTop + "px 0 0 0"
									});
									$('img', li[i]).css( {
										width : oWidth,
										height : oHeight
									});
								}
							}
						}
					}

					resize();
					disp();

					function go(to) {

						if (!running) {
							if (o.beforeStart)
								o.beforeStart.call(this, vis());

							if (o.circular) { // If circular we are in first
												// or last, then goto the other
												// end
								if (to <= o.start - v - 1) { // If first,
																// then goto
																// last
									ul.css(animCss,
											-((itemLength - (v * 2)) * liSize)
													+ "px");
									// If "scroll" > 1, then the "to" might not
									// be equal to the condition; it can be
									// lesser depending on the number of
									// elements.
									curr = to == o.start - v - 1 ? itemLength
											- (v * 2) - 1 : itemLength
											- (v * 2) - o.scroll;
								} else if (to >= itemLength - v + 1) { // If
																		// last,
																		// then
																		// goto
																		// first
									ul.css(animCss, -((v) * liSize) + "px");
									// If "scroll" > 1, then the "to" might not
									// be equal to the condition; it can be
									// greater depending on the number of
									// elements.
									curr = to == itemLength - v + 1 ? v + 1 : v
											+ o.scroll;
								} else
									curr = to;
							} else { // If non-circular and to points to
										// first or last, we just return.
								if (to < 0 || to > itemLength - v)
									return;
								else
									curr = to;
							} // If neither overrides it, the curr will still
								// be "to" and we can proceed.

							running = true;

							ul.animate(animCss == "left" ? {
								left : -(curr * liSize)
							} : {
								top : -(curr * liSize)
							}, o.speed, o.easing, function() {
								if (o.afterEnd)
									o.afterEnd.call(this, vis());
								running = false;
							});

							// Disable buttons when the carousel reaches the
							// last/first, and enable when not
							if (!o.circular) {
								$(o.btnPrev + "," + o.btnNext).removeClass(
										"disabled");
								$(
										(curr - o.scroll < 0 && o.btnPrev)
												|| (curr + o.scroll > itemLength
														- v && o.btnNext) || [])
										.addClass("disabled");
							}
						}
						disp();
						resize();
						return false;
					}
					;
				});
	};

	function css(el, prop) {
		return parseInt($.css(el[0], prop)) || 0;
	}
	;
	function width(el) {
		return el[0].offsetWidth + css(el, 'marginLeft')
				+ css(el, 'marginRight');
	}
	;
	function height(el) {
		return el[0].offsetHeight + css(el, 'marginTop')
				+ css(el, 'marginBottom');
	}
	;

})(jQuery);

