/*
 * siaTabs 0.1 - jQuery plugin
 * 
 * Copyright (c) 2008 Sukharev Ivan (www.siarion.net)
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.siatabs.js 1 2008-06-11 00:14 $
 *
 */
;(function($) {

	$.extend($.fn, {
		siatabs: function(settings) {

			function SelectTab(item,BoxID) {
				CACHE.selected = "#"+$(item).attr("id");
				$(BoxID+" > ul > li").removeClass(CLASSES._selected);
				$(BoxID+" > div").css("display","none");
				$(item).addClass(CLASSES._selected);
				$("#"+$(item).attr("id").substr(1),Box).css("display","block");
				if ( settings.onselect ) {
					var args = new Array(1);
					args[0] = CACHE.selected;
					settings.onselect.apply($(this),args);
				}				
			}

			var Box = this;
			var BoxID = "#"+this.attr("id");
			$(BoxID+" > ul > li").each( function (i) {
				var text = $(this).text();
				$(this).html("<u>" + text + "</u>");
			});	
			$(BoxID+" > ul").addClass("clear");
			$(BoxID+" > ul > li").click(function(){SelectTab(this,BoxID);});
			$(BoxID+" > ul > li").mouseover(function(){$(this).addClass(CLASSES._hover);});
			$(BoxID+" > ul > li").mouseout(function(){$(this).removeClass(CLASSES._hover);});
			if (settings.selected.length>0) {
				CACHE.selected = settings.selected;
			};	
			if (CACHE.selected.length>0) {
				if ($(CACHE.selected)) {
				} else {
					CACHE.selected = "#"+$(BoxID+" > ul > li:first").attr("id");
				}
			} else {
				CACHE.selected = "#"+$(BoxID+" > ul > li:first").attr("id");
			};
			SelectTab($(CACHE.selected), BoxID);
		}
	});
	
	var CACHE = $.fn.siatabs.cache = {
		selected : ""  
	};
	
	var CLASSES = $.fn.siatabs.classes = {
		_hover    :   "hover",
		_selected :   "selected"
	};
	
	var VERSION = $.fn.siatabs.version="0.1";

})(jQuery);
