var SC_Tabs = {
	
	tabs : [],
	
	start : function(buttons, contents, rotate)	{
		new this.newTabs(buttons, contents, rotate);
	},
	
	newTabs : function(buttons, contents, rotate)	{
		var _id = SC_Tabs.tabs.length;
		var _interval = 10;
		var _rindex = 0;
		
		this.buttons = buttons;
		SC_Tabs.tabs[_id] = this;
		
		this.swap = function()	{
			if(_interval > 0)	{
				clearTimeout(SC_Tabs.tabs[_id].rotateTimeout);
				clearInterval(SC_Tabs.tabs[_id]._swapInterval);
				SC_Tabs.tabs[_id]._currentContent.style.zoom = 1;
				SC_Tabs.tabs[_id]._nextContent = this._corresponds;
				SC_Tabs.tabs[_id]._swapInterval = setInterval('SC_Tabs.tabs[' + _id + '].hideCurrent()', 30);
			}
			else	{
				SC_Tabs.tabs[_id]._currentContent.style.display = "none";
				SC_Tabs.tabs[_id]._currentContent.style.zoom = 0;
				SC_Tabs.tabs[_id]._currentContent = SC_Tabs.tabs[_id]._nextContent;
				SC_Tabs.tabs[_id]._currentContent.style.display = "block";
				SC_Tabs.tabs[_id]._currentContent.style.zoom = 1;
				SC_Tabs.tabs[_id]._swapInterval = setInterval('SC_Tabs.tabs[' + _id + '].showCurrent()', 30);
			}
		};
		
		this.highlightSelected = function()	{
			var i = this.buttons.length;
			while(i--)	{
				if(this._nextContent == this.buttons[i]._corresponds)	{
					this.buttons[i].className = this.buttons[i]._className + " selected";
				}
				else	{
					this.buttons[i].className = this.buttons[i]._className;
				}
			}
		};
		
		this.hideCurrent = function()	{
			if(_interval > -1)	{
				this._currentContent.style.opacity = _interval / 10;
				this._currentContent.style.filter = "alpha(opacity=" + _interval * 10 + ")";
				_interval--;
			}
			else	{
				clearInterval(this._swapInterval);
				this.highlightSelected();
				this.swap();
			}
		};
		
		this.showCurrent = function()	{
			if(_interval < 11)	{
				this._currentContent.style.opacity = _interval / 10;
				this._currentContent.style.filter = "alpha(opacity=" + _interval * 10 + ")";
				_interval++;
			}
			else	{
				clearInterval(this._swapInterval);
				this._currentContent.style.zoom = 0;
				this.rotateTimeout = setTimeout('SC_Tabs.tabs[' + _id + '].rotate()', rotate);
			}
		};
		
		this.rotate = function()	{
			_rindex++;
			if(_rindex == buttons.length)	{
				_rindex = 0;
			}
			if(!window.addEventListener)	{
				buttons[_rindex].fireEvent("onclick");
			}
			else	{
				var e = document.createEvent("MouseEvent");
				e.initEvent("click", false, true);
				buttons[_rindex].dispatchEvent(e);
			}
			this.rotateTimeout = setTimeout('SC_Tabs.tabs[' + _id + '].rotate()', rotate);
		};
		
		if(rotate) this.rotateTimeout = setTimeout('SC_Tabs.tabs[' + _id + '].rotate()', rotate);
		
		var i = buttons.length;
		while(i--)	{
			if(buttons[i].tagName == "a")	{
				buttons[i].removeAttribute("href");
			}
			buttons[i]._corresponds = contents[i];
			buttons[i]._className = buttons[i].className;
			buttons[i].onclick = SC_Tabs.tabs[_id].swap;
			if(i == 0) buttons[i].className = buttons[i]._className + " selected";
		}
		
		i = contents.length;
		while(i--)	{
			if(i != 0)	{
				contents[i].style.display = "none";
				contents[i].style.opacity = 0;
				contents[i].style.filter = "alpha(opacity=0)";
			}
			else	{
				this._currentContent = contents[i];
			}
		}
	}
	
}
