var TCATabs = Class.create({
	initialize: function(staticTabgroupId)
		{
			// find the tab group container based on the passed ID
			this.stgid = staticTabgroupId;
			this.stg = $(staticTabgroupId);
			this.stg.hide();

			this.currentIndex = null;
			
			// create a dynamic tab group, and move the tabs into it
			this.dtg = new Element('div');
			this.dtg.hide();
			this.dtg.addClassName('tab-group');
			this.dtg.setAttribute('id', staticTabgroupId + "-dynamic");
			
			this.tabs = this.stg.select('.tab-label');
			this.tabBodies = this.stg.select('div.tab-contents');

			var bodies = new Element('div'); // just for storing the bodies in the new dtg.
			//bodies.setStyle({position: 'relative'});
			bodies.addClassName('tab-bodies-container');

			for (i=0; i<this.tabs.length; i++) {
				var tab = this.tabs[i];
				var printTab = new Element(tab.tagName);

				printTab.addClassName('print-tab');
				printTab.innerHTML = tab.innerHTML;

				//Event.observe(tab, 'click', this.choose_tab.bindAsEventListener(this,i), false);
				Event.observe(tab, 'click', this.choose_tab.bind(this,i), false);
				this.dtg.appendChild(tab);
				bodies.appendChild(printTab);
				bodies.appendChild(this.tabBodies[i]);
			}

			this.dtg.appendChild(bodies);
			this.choose_tab(0);

			this.stg.replace(this.dtg);
			this.dtg.show();
		},
	choose_tab: function(index)
		{
			if (this.currentIndex != index) {
				this.tabs[index].addClassName('current');
				this.tabs[index].addClassName('tab-label-current');

				if (this.currentIndex != null) {
					this.tabs[this.currentIndex].removeClassName('current');
					this.tabs[this.currentIndex].removeClassName('tab-label-current');
					this.tabBodies[this.currentIndex].removeClassName('current');
				}
				this.currentIndex = index;

				this.tabBodies[index].addClassName('current');
			}
		}
	});