var TabsInterface = Class.create();
TabsInterface.prototype = {

	initialize: function(varName, tabContainer, tabCount) {
		this.isAnimating = false;
		this.animationTime = .4;
		this.varName = varName;
		this.tabContainer = tabContainer;
		this.tabCount = tabCount;
		this.currentTab = 1;
		
		// Init Functions
		this.matchTabBodyHeights();
		this.matchTabHeights();
		this.setInitialTabsViewState();
		
	},
	matchTabBodyHeights: function (){
		var maxHeight = 0;
		for (var i=1; i<=this.tabCount; i++){
			if ($("tabBody"+i).clientHeight >maxHeight ){
				maxHeight = $("tabBody"+i).clientHeight;	
			}
		}
		for (var i=1; i<=this.tabCount; i++){
			$("tabBody"+i).style.height = maxHeight+"px";
		}
		maxHeight += 80;
		this.tabContainer.style.height = maxHeight+"px";
	},
	matchTabHeights: function (){
		var maxHeight = 0;
		for (var i=1; i<=this.tabCount; i++){
			if ($("tab"+i).clientHeight >maxHeight ){
				maxHeight = $("tab"+i).clientHeight;	
			}
		}
		for (var i=1; i<=this.tabCount; i++){
			$("tab"+i).style.height = maxHeight+"px";
		}
		
	},
	setInitialTabsViewState: function (){
		for (var i=2; i<=this.tabCount; i++){
			$("tabBody"+i).hide();
		}
	},
	switchToTab: function (id){
		if (this.isAnimating) return;
		if (this.currentTab == id) return;

		this.isAnimating = true;

	
		new Effect.Fade('tabBody'+this.currentTab,{duration:this.animationTime});
		$('tab'+this.currentTab).className = ""; 
		this.currentTab = id;
		$('tab'+this.currentTab).className = "current"; 
		window.setTimeout(  'new Effect.Appear(\'tabBody'+this.currentTab+'\',{duration:'+ this.animationTime+ '});',  this.animationTime*1000  );
		
		window.setTimeout(  this.varName+'.endAnimation();',  2*this.animationTime*1000  );
	},
	endAnimation: function (){
		this.isAnimating = false;
	}
};
function checkForTabs(){
	for (var i=2; i<7; i++){
		if ($("tabsViewer"+i) ){
			tabManager = new TabsInterface("tabManager", $("tabsViewer"+i), i);
		}
	}
}
var tabManager = null;
