/*** forums.js
	This file contains javascript that is used throughout the forums area ***/

/*** TAB SWITCHING CLASS ***/
var tabSwap = new Class({
    initialize: function(containerID){
		this.tabItems = $$("#"+ containerID +" ul.toggleBtns li a");
		this.paneItems = $$("#"+ containerID +" .details ul");
		this.setupTabs();
    },
    setupTabs: function() {
		this.tabItems.each(function(tabItem,index) {
			tabItem.addEvent("click", function(e) {
				e = new Event(e);
				this.clearTabs();
				this.setTab(tabItem);
				this.clearPanes(index);
				this.setPane(index);
				e.stop();
			}.bind(this));
		}.bind(this));	
	},
    clearTabs: function() {
		this.tabItems.each(function(tabItem,i) {
			if (tabItem.hasClass("On")) {
				tabItem.removeClass("On");
				return;
			}
		});
    },
	setTab: function(tabItem){
		if (!tabItem.hasClass("On")) {
			tabItem.addClass("On");
		}
	},
    clearPanes: function(activeIndex) {
		this.paneItems.each(function(paneItem,index) {
			if (activeIndex != index) {
				paneItem.setStyle("display","none");
			}
		});
    },
	setPane: function(activeIndex) {
		this.paneItems.each(function(paneItem,index) {
			if (activeIndex == index && paneItem.getStyle("display") != "block") {
				paneItem.setStyle("display","block");
			}
		}.bind(this));
	}
});

window.addEvent('domready', function() {	
	var postsTab = new tabSwap('forumTopics');
});