(function($) { // block scope

$.fn.navigation = function(settings) {
	var active = ["",""];
	var temp = null;
	var timer = null;
	var timeout = 1000;
	
	if (!!settings)
		active = settings;
	
	temp = active;
	
	var container = this[0];

	var tags = $("div.head a[name]", container);
	var subs = $("div.body a", container);
	
	tags	
	.mouseover(function(){
		show([this.name]);
	})
	.mouseout(function(){
		timer = setTimeout(function(){hide()}, timeout);
	});
	
	subs
	.mouseover(function(e){
		$("div.body a[name].on", container).removeClass("on");
		//e.stopPropagation();
	})

	var containers = $("div.body div[id^=nav-]", container);
	containers
	.mouseover(function(){
		clear();
	})
	.mouseout(function(){
		timer = setTimeout(function(){hide()}, timeout);
	});
	
	show(active);
	
	function show(val) {
		clear();
		
		tags.each(function(){
			if (this.name == val[0])
				$(this).addClass("on")
			else
				$(this).removeClass("on")
		})
		
		containers.each(function(){
			if (this.id=="nav-"+val[0])
				$(this).show();
			else
				$(this).hide();
		})
		
		$("div.body a[name].on", container).removeClass("on");

		if (val[1]) {
			$("div.body div[id=nav-" + val[0] + "] a[name=" + val[1] + "]", container).addClass("on");
		}

		temp = val;
	};
	
	
	function hide() {
		show(active);
	}
	
	function clear() {
		if(timer)
			clearTimeout(timer);
	};
	
}

})(jQuery);