// usage: new TabMaker('menu');

// ul id="menuIndex" -> li
// div id="menuBoxIndex" -> div class="menuBox"

var TabMaker = function(name) {
	if((typeof jQuery) != 'function') {
		alert('TabMaker requires jquery.');
		return;
	}
	
	var tab = this;
	tab.divs = $('#'+name+'BoxIndex .menuBox').get();
	tab.menu = $('#'+name+'Index li').get();
	tab.current = tab.divs[0];
	
	tab.set = function(target) {
		$(tab.current).hide();
		tab.current = target;
		$(tab.current).show();
	};
	
	for(var i=0 ; i<tab.divs.length && i<tab.menu.length ; i++) {
		if(tab.current != tab.divs[i]) {
			$(tab.divs[i]).hide();
		}
		var li = tab.menu[i];
		var child = li.childNodes[0];
		var a = document.createElement('A');
		li.removeChild(child);
		li.appendChild(a);
		a.appendChild(child);
		
		a.href = '#';
		$(a).click((function(target) {
			return function() {
				tab.set(target);
				return false;
			};
		})(tab.divs[i]));
	}
};

