Tabstrip = function(tabstripId, switchMode, timeSwitch, timeInterval, clickOpenMore) {
	this.tabstripId = tabstripId;
	this.switchMode = switchMode;
	this.timeSwitch = timeSwitch;
	this.clickOpenMore = clickOpenMore;
	this.selectedIndex = 0;
	this.buttons = new Array();
	this.stopAutoSwitch = false; 
	var tabstrip = this;
	if(timeSwitch) { 
		window.setInterval(function(){tabstrip.autoSwitch();}, timeInterval*1000); 
	}
};
Tabstrip.prototype.addPage = function(mouseOverStyle, selectedStyle, unselectedStyle) { 
	var buttonIndex = this.buttons.length;
	var button = new TabstripButton(this, buttonIndex, mouseOverStyle, selectedStyle, unselectedStyle);
	this.buttons[buttonIndex] = button;
	if(buttonIndex==0) {
		button.setStyle(true);
	}
	
	
	if(this.timeSwitch) {
		var tabstrip = this;
		var tabstripBody = document.getElementById("tabstripBody_" + this.tabstripId + "_" + buttonIndex);
		
		tabstripBody.onmouseover = function() {
			tabstrip.stopAutoSwitch = true;
		};
		tabstripBody.onmouseout = function() {
			tabstrip.stopAutoSwitch = false;
		};
	}
};
Tabstrip.prototype.setMoreLink = function() { 
	var tabstrip = this;
	var moreLink = document.getElementById("tabstripMoreLink_" + this.tabstripId);
	
	moreLink.onmouseover = function() {
		tabstrip.stopAutoSwitch = true;
	};
	moreLink.onmouseout = function() {
		tabstrip.stopAutoSwitch = false;
	};
	this.resetMoreLink(); 
};
Tabstrip.prototype.autoSwitch = function(tabstrip) { 
	if(!this.stopAutoSwitch) {
		this.switchPage(this.selectedIndex<this.buttons.length-1 ? this.selectedIndex+1 : 0);
	}
};
Tabstrip.prototype.switchPage = function(pageIndex) { 
	if(pageIndex==this.selectedIndex) {
		return;
	}
	document.getElementById("tabstripBody_" + this.tabstripId + "_" + this.selectedIndex).style.display = 'none'; 
	this.buttons[this.selectedIndex].setStyle(false); 
	this.selectedIndex = pageIndex;
	document.getElementById("tabstripBody_" + this.tabstripId + "_" + this.selectedIndex).style.display = ''; 
	this.buttons[this.selectedIndex].setStyle(true); 
	
	this.resetMoreLink(); 
};
Tabstrip.prototype.resetMoreLink = function() { 
	
	var moreLink = document.getElementById("tabstripMoreLink_" + this.tabstripId);
	if(!moreLink) {
		return;
	}
	var divMore = document.getElementById("tabstripMore_" + this.tabstripId + "_" + this.selectedIndex);
	if(divMore) {
		var link = divMore.getElementsByTagName("A")[0];
		if(link) {
			moreLink.href = link.href;
			moreLink.setAttribute("onclick", link.getAttribute("onclick"));
		}
	}
};
Tabstrip.prototype.openMore = function(buttonIndex) { 
	var divMore = document.getElementById("tabstripMore_" + this.tabstripId + "_" + this.selectedIndex);
	if(divMore) {
		var link = divMore.getElementsByTagName("A")[0];
		clickElement(link);
	}
}
TabstripButton = function(tabstrip, buttonIndex, mouseOverStyle, selectedStyle, unselectedStyle) {
	this.tabstrip = tabstrip;
	this.buttonIndex = buttonIndex;
	this.buttonElement = document.getElementById("tabstripButton_" + tabstrip.tabstripId + "_" + buttonIndex);
	this.mouseOverStyle = mouseOverStyle;
	this.selectedStyle = selectedStyle;
	this.unselectedStyle = unselectedStyle;
	
	this.buttonElement.onmouseover = function() {
		tabstrip.stopAutoSwitch = true;
		if(buttonIndex==tabstrip.selectedIndex) {
			return;
		} 
		if(mouseOverStyle!="" && mouseOverStyle!="null") {
			this.style.cssText = mouseOverStyle;
		}
		if(tabstrip.switchMode=="mouseOver") {
			tabstrip.switchPage(buttonIndex);
		}
	};
	this.buttonElement.onmouseout = function() {
		tabstrip.stopAutoSwitch = false;
		if(buttonIndex!=tabstrip.selectedIndex && mouseOverStyle!="" && mouseOverStyle!="null") {
			this.style.cssText = unselectedStyle;
		}
	};
	if(tabstrip.switchMode=="click" || tabstrip.clickOpenMore) { 
		this.buttonElement.onclick = function() {
			if(tabstrip.switchMode=="click") { 
				tabstrip.switchPage(buttonIndex);
			}
			else {
				tabstrip.openMore(buttonIndex);
			}
		};
	}
};
TabstripButton.prototype.setStyle = function(selected) {
	var style = (selected ? this.selectedStyle : this.unselectedStyle);
	this.buttonElement.style.cssText = style;
};

