(function() {
	
	/**
	 * インデザ用のタブ機能です。
	 */
	jQuery.fn.indezatab = function(config) {
		
		/** 引数 */
		config = jQuery.extend({
			/** 各項目用のセレクタ */
			itemSelector : "li", 
			/**  */
			defaultFocused : "", 
			/** 選択中を表すクラス */
			focusedClass : "focused", 
			/** 非選択中を表すクラス */
			hiddenClass : "hidden"
		}, config);
		
		/** タブグループ */
		var tabGroup = $(this);
		
		/** 各タブ */
		var tabItems = new Array();
		
		/** 各タブに対応した表示エリア */
		var displayAreas = new Array();
		
		/** 初期化します。 */
		function init() {
			count = 0;
			$(config.itemSelector, tabGroup).each(function() {
				_this = $(this);
				tabItems[count] = _this;
				displayAreas[_this.attr("id")] = $($("a", _this).attr("href"));
				count++;
			});
		}
		
		/** フォーカスします。 */
		var focusThis = function(e) {
			_this = $(this);
			$.each(tabItems, blurThis);
			_this.addClass(config.focusedClass);
			displayAreas[_this.attr("id")].removeClass("hidden");
			e.preventDefault();
		};
		
		/** アンフォーカスします。 */
		var blurThis = function() {
			this.removeClass(config.focusedClass);
			displayAreas[this.attr("id")].addClass("hidden");
		};
		
		/** 実行関数 */
		function exec() {
			$.each(tabItems, function() {
				this.bind("click", focusThis);
			});
		}
		
		init();
		exec();
	};
	
}) (jQuery);
