$(document).ready(function() {
	$('img').each(function(index) {
		if ($(this).parent().get(0).tagName == 'A' && $(this).attr('src').indexOf('_off.gif') > 0) {
			if (location.href.indexOf($(this).parent().attr('href')) > 0)
				$(this).attr('src', $(this).attr('src').replace('_off.gif', '_on.gif'));
			else
				bindImageSwapping($(this));
		}
	});
});

function imgover(imgs, ext) {
	if (ext) {
		imgs.src = imgs.src.replace("off." + ext, "on." + ext);
	} else {
		imgs.src = imgs.src.replace("off.gif", "on.gif");
	}
}
function imgout(imgs, ext) {
	if (ext) {
		imgs.src = imgs.src.replace("on." + ext, "off." + ext);
	} else {
		imgs.src = imgs.src.replace("on.gif", "off.gif");
	}
}

// png 파일 투명 처리
function setPng24(obj) {
	obj.width = obj.height = 1;
	obj.className = obj.className.replace(/\bpng24\b/i, '');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src
			+ "',sizingMethod='image');"
	obj.src = '';
	return '';
}

// 퀵 메뉴
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	// obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof (window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof (document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if (document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}

// 글로벌 네비게이션(2Depth 메뉴그룹)에 대한 마우스 또는 키보드 반응(보임/숨김)설정
function openSub(id) {
	document.getElementById('all_gnb').style.display = 'block'; // sub1~sub4 까지
	// 숨긴 다음
}
function closeSub(id) {
	document.getElementById('all_gnb').style.display = 'none'; // sub1~sub4 까지
	// 숨긴 다음
}

/* 이미지 롤오버 */
function over(obj) {
	obj.src = obj.src.replace('.gif', '_on.gif');
	obj.onmouseout = function() {
		this.src = this.src.replace('_on.gif', '.gif');
	}
}

/* 팝업 */
function OpenPopup(url, w, h, name) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 3;
	var winform = window.open(url, (name || '_blank'), 'top=' + wint + ',left=' + winl
			+ 'toolbar=0, status=0, scrollbars=1, location=0, menubar=0, resizable=no, width=' + w + ', height=' + h);
	return winform;
}
/* 팝업닫기 */
function closeWin() {
	self.close();
}
function resizeImage(img, w, h) {
	img.removeAttribute('width');
	img.removeAttribute('height');
	if (h) {
		var scale;
		if (w / img.width > h / img.height)
			scale = h / img.height;
		else
			scale = w / img.width;
		var iw = img.width;
		var ih = img.height;
		img.width = Math.round(iw * scale);
		img.height = Math.round(ih * scale);
	} else {
		if (img.width && img.width > w)
			img.width = w;
	}
}
