/**
 * @version 1.1
 * @date April 27, 2011
 * @author Elkha (elkha1914@hotmail.com)
 * @copyright (c) 2011 Elkha (http://elkha.kr/)
 **/

/*
	$("#gnb").navi({
		show : { opacity: "show", height: "show"},
		hide : { height: "hide"},
		delay : 100
	});
 */

(function($){
	$.fn.navi = function(args){

		var elkha = $.extend({
			show : { height: "show" },
			hide : { opacity: "hide" },
			speed: "fast",
			delay: 0,
			click: false,
			show_func : false,
			hide_func : false
		}, args);

		// ieSelect
		var ieSelect = false;
		if($.browser.msie == true) ieSelect = parseInt($.browser.version);

		this.each(function(){
			var gnb = $(this);

			gnb.find("li:has(ul)").hover(function(){
				$(this).addClass("hover");
				if(elkha.click && $(this).children("a").attr("href")=="#") return;
				if(elkha.speed==0 || (ieSelect && ieSelect <= 6)) $(this).children("ul").show(null, elkha.show_func);
				else $(this).children("ul:not(:animated)").animate(elkha.show, elkha.speed, elkha.show_func); 
			}, function(){
				$(this).removeClass("hover");
				if(elkha.click && $(this).children("a").attr("href")=="#") return;
				var hover = $(this);
				setTimeout(function(){
					if(hover.hasClass("hover")) return;
					if(elkha.speed==0 || (ieSelect && ieSelect <= 6)) hover.children("ul").hide(null, elkha.hide_func);
					else hover.children("ul").animate(elkha.hide, elkha.speed, elkha.hide_func);
				}, elkha.delay);
			});
			gnb.find("a").focus(function(){
				$(this).parent("li").prev("li").find("ul").hide(null, elkha.hide_func);
				$(this).parent("li").next("li").find("ul").hide(null, elkha.hide_func);
				if(elkha.click && $(this).attr("href")=="#") return;
				$(this).next("ul").show(null, elkha.show_func);
			});
/*
			$("*:not(#gnb a)").focus(function(){ // 변수 gnb 이용한 셀렉터를 아시면 elkha1914@hotmail.com 으로 좀..
				gnb.find("li > ul").hide();
			});
*/
			gnb.find("a").click(function(){
				if($(this).attr("href")=="#") {
					if(elkha.click) {
						if( $(this).next("ul").css("display")=="block" ) $(this).next("ul").hide(null, elkha.hide_func);
						else $(this).next("ul").show(null, elkha.show_func);
					}
					return false;
				}
			});

		});

		return this;
	};
})(jQuery);
