// JavaScript Document

(function($) { // hide the namespace
					
function Tabs() {
	
	this.name = '';
};
	
$.extend(Tabs.prototype, {
					 
	init: function(name,index) {
		
		this.name = name;
		
		if (index == null) index = 1;

		$("#" + this.name + " div.off_tab").hover(
			function () {
				$.tabs._activate(this,true);
			}, 
			function () {
				$.tabs._activate(this,false);
			}
		).click(function () {
				
			$.tabs._select(this);

		});
		
		$("#" + this.name + " div.off_tab:eq(" + (index-1) + ")").click();
		
	},
	
	_activate: function(obj,over) {
		
		if ($(obj).hasClass("active") == true) return;
		
		if ($(obj).attr("id") == "start") {
			pos = "l";
		} else if ($(obj).attr("id") == "end") {
			pos = "r";
		} else {
			pos = "lc";
		}
		
		if (over) {
			
			$(obj).attr("class","on_tab");
			$(obj).children("div").attr("class","on_tab_l");
								
			if (pos == "r") $("#rrtab").attr("class","on_tab_r");

		} else {
			
			$(obj).attr("class","off_tab")
			
			if (pos == "l") {
				$(obj).children("div").attr("class","off_tab_l");
			} else if (pos == "r") {
				$(obj).children("div").attr("class","off_tab_lc");
				$("#rrtab").attr("class","off_tab_r");
			} else {
				$(obj).children("div").attr("class","off_tab_lc");
			}
		}
	},

	_select: function(obj) {
		
		var active = $("#" + this.name + " div.active");
		
		$("#" + this.name + " div.active").removeClass("active");
		$.tabs._activate(active,false);
		
		$.tabs._activate(obj,true);
		$(obj).addClass("active");
	}
	
});

$.tabs = new Tabs(); // singleton instance

})(jQuery);
