(function($){
	$.fn.navitation = function(settings){
		var config = {
			place		: "horizon",		//수직 수평 구분 vertical OR horizon
			local		: "fix",			//페이지 로케이션에 따른 네비게이션 고정 fix or none
			depth		: "0-0-0",			//뎁스표기-_-
			event		: "click",			//수직네비게이션의 이벤트 타입  click OR mouseover
			b_suffix	: "_off",			//기본 접미사
			c_suffix	: "_on",			//변경 접미사
			c_class		: ""				//변경클래스
		};

		if (config) $.extend(config, settings);
		
		function fixinit(val_fix, val_depth, val_root){
			$root	= val_root;
			if(val_fix == "fix"){
				$depth	= val_depth.split("-");
				$cont	= $root;
				$.each($depth, function(){
					$cont = $cont.children("li").eq(this);
					if($cont.length > 0){
						$target = $cont.children("a").children("img");
						$target.attr("src", $target.attr("src").replace(config.b_suffix, config.c_suffix));
					}
					$cont = $cont.find("ul:eq(0)").show();
				});
			}
		}

		$.fn.eventstart = function(eventype, pos){
			/**클릭이벤트시에 마우스오버 줄건가 말건가..ㄱ-**/
			if(eventype === "click"){
				$(this).bind("mouseover", function(){
					if($(this).parent().parent().attr("class") !== undefined && $(this).parent().parent().attr("class") !== ""){
						$n_other = $(this).parent().siblings();
						$n_other.each(function(){
							$(this).find("a img").each(function(){
								$(this).attr("src", $(this).attr("src").replace(config.c_suffix, config.b_suffix));
							});
						});
						$n_this = $(this).children("img");
						$n_this.attr("src", $n_this.attr("src").replace(config.b_suffix, config.c_suffix));
					}
				});
			}

			$(this).bind(eventype, function(){
				if(eventype === "mouseover"){
					$n_other = $(this).siblings();
					$n_other.each(function(){
						$(this).find("a img").each(function(){
							$(this).attr("src", $(this).attr("src").replace(config.c_suffix, config.b_suffix));
						});
						if(pos == "horizon"){
							$(this).find("ul").hide();
						}
					});
					$n_this = $(this).children("a").children("img");
					$n_this.attr("src", $n_this.attr("src").replace(config.b_suffix, config.c_suffix));
					if(pos == "horizon"){
						$(this).find("ul:eq(0)").show();
					}
				}else if(eventype === "click"){
					if($(this).next("ul").length > 0){
						$n_other = $(this).parent().siblings();
						$n_other.each(function(){
							$(this).find("ul").hide();
							$(this).find("a img").each(function(){
								$(this).attr("src", $(this).attr("src").replace(config.c_suffix, config.b_suffix));
							});
						});
						$n_this = $(this).children("img");
						$n_this.attr("src", $n_this.attr("src").replace(config.b_suffix, config.c_suffix));
						$(this).next("ul").show();
						return false;
					}
				}
			});
		};

		/**클릭이벤트시에 마우스오버 줄건가 말건가..ㄱ-**/
		/*
		$(this).find("ul li ul li").mouseover(function(){
			if(config.event == "click"){
				$(this).siblings().each(function(){
					$(this).find("a img").attr("src", $(this).find("a img").attr("src").replace(config.c_suffix, config.b_suffix));
				});
				$(this).find("a img").attr("src", $(this).find("a img").attr("src").replace(config.b_suffix, config.c_suffix));
			}
		});
		*/

		fixinit(config.local, config.depth, $(this).children("ul"));

		if(config.event == "mouseover" && config.place == "vertical"){
			$(this).find("ul").show();
		}

		if(config.event == "mouseover"){
			$(this).find("li").eventstart(config.event, config.place);
		}else if(config.event == "click"){
			$(this).find("li a").eventstart(config.event, config.place);
		}
	};
})(jQuery);
