function TabContainer(id) {
    this.id = id;
    this.tab_no;
    this.number_of_tabs;
    this.component = document.getElementById(this.id);
    this.timerstopped;
    this.initial_tab;
    this.timer;
}
TabContainer.prototype.select = function(new_tab_no) {
    this.pause;
    this.timerstopped = true;
    return this.switchto(new_tab_no);
};
TabContainer.prototype.switchto = function(new_tab_no) {
    if(this.component) {
        var current_tab_body = document.getElementById(this.id + "-" + this.tab_no);
        if(current_tab_body) {
            current_tab_body.style.visibility = "hidden"; 
        } else {
			console.debug("no current tab body");
		}
        var new_tab_body = document.getElementById(this.id + "-" + new_tab_no);
        if(new_tab_body) {
            new_tab_body.style.visibility = "visible"; 
        } else {
			console.debug("no new tab body");
		}
        var current_tab_head = document.getElementById(this.id + "-" + this.tab_no + "-tab");
        if(current_tab_head) {
            current_tab_head.className = "tab" + this.tab_no; 
        } else {
			console.debug("no current tab head");
		}
        var new_tab_head = document.getElementById(this.id + "-" + new_tab_no + "-tab");
        if(new_tab_head) {
            new_tab_head.className = new_tab_head.className + " active " + new_tab_head.className + "-active"; 
            if(new_tab_no==this.number_of_tabs) {
                new_tab_head.className = new_tab_head.className + " last"; 
            }
        } else {
			console.debug("no new tab head");
		}
        if(this.component && new_tab_head && new_tab_body) {
            this.setContainerHeight(new_tab_head.offsetHeight + new_tab_body.offsetHeight);
        }
        this.tab_no = new_tab_no;
    } else {
		console.debug("no component");
	}
    return false;
};
TabContainer.prototype.setContainerHeight = function(height) {
    if(!height) {
        var tab_head = document.getElementById(this.id + "-" + this.initial_tab + "-tab");
        var tab_body = document.getElementById(this.id + "-" + this.initial_tab);
        if(tab_head && tab_body) {
            height = tab_head.offsetHeight + tab_body.offsetHeight;
        }
    }
    this.component.style.height = height + "px";
    return;
};
TabContainer.prototype.nextTab = function() {
    if(this.tab_no<this.number_of_tabs) {
        return this.switchto(this.tab_no + 1);
    } else {
        return this.switchto(1);
    }
};
TabContainer.prototype.startTimer = function(interval, method) {
    if(interval > 0) {
        var that = this;
        var args = Array.prototype.slice.apply(arguments,[2]);
        if(typeof method==="string") {
            method = that[method];
        }
        this.timer = setInterval(function() { method.apply(that, args); }, interval);
        return that;
    }
    return;
};
TabContainer.prototype.pause = function() {
    if(this.timer) {
        clearInterval(this.timer);
    }
    return;
};
TabContainer.prototype.start = function() {
    if(!this.timerstopped) {
        this.startTimer(this.interval*1000, "nextTab"); 
    }
    return;
    
};
TabContainer.prototype.initialise = function(number_of_tabs, interval, initial_tab) {
    this.number_of_tabs = number_of_tabs;
    this.interval = interval;
    if(initial_tab) {
        this.initial_tab = initial_tab;
    } else {
        this.initial_tab = 1;
    }
    this.tab_no = this.initial_tab;
    //this.setContainerHeight();
	this.start();
	this.switchto(this.initial_tab);
    return;
};
