﻿// JavaScript Document
/*
	动态的TAB标签切换
*/
	var dynamic_mode = {
		click:1,
		over:2
		}
	function dynamic_panel()
	{
		this.dynamicMode = dynamic_mode.over;
		this.currentButtonStyle = "current";
		this.buttons = new Array();
		this.panels = new Array();
	}
	dynamic_panel.prototype.AddPanel = function (button_id,panel_id)
	{
		var _button = document.getElementById(button_id);
		var _panel = document.getElementById(panel_id);
		try
		{
			_button.dp = this;
			_button._button_index = this.buttons.length;
			_button.onclick = function ()
			{
				this.dp.OnClick(this);
			}
			_button.onmouseover = function ()
			{
				this.dp.OnMouseOver(this);
			}
			this.buttons.push(_button);
			this.panels.push(_panel);			
		}
		catch(ex)
		{
			alert(ex.message);
		}
	}
	dynamic_panel.prototype.OnClick = function (sender)
	{
		if(this.dynamicMode==dynamic_mode.click)
		{
			for(var i=0;i<this.buttons.length;i++)
			{
				if(i!=sender._button_index)
				{
					this.buttons[i].className="";
				}
			}
			sender.className=this.currentButtonStyle;
			for(var i=0;i<this.panels.length;i++)
			{
				if(i!=sender._button_index)
				{
					this.panels[i].style.display="none";
				}
			}
			this.panels[sender._button_index].style.display="";
		}
		else
		{
			return false;	
		}
	}
	dynamic_panel.prototype.OnMouseOver = function (sender)
	{
		if(this.dynamicMode==dynamic_mode.over)
		{
			for(var i=0;i<this.buttons.length;i++)
			{
				if(i!=sender._button_index)
				{
					this.buttons[i].className="";
				}
			}
			sender.className=this.currentButtonStyle;
			for(var i=0;i<this.panels.length;i++)
			{
				if(i!=sender._button_index)
				{
					this.panels[i].style.display="none";
				}
			}
			this.panels[sender._button_index].style.display="";
		}
		else
		{
			return false;	
		}
	}
	dynamic_panel.prototype.Init = function (dm)
	{
		if(dm == dynamic_mode.over || dm == dynamic_mode.click)
		{
			this.dynamicMode=dm;
		}
		try
		{
			switch(this.dynamicMode)
			{
				case dynamic_mode.over:
					this.OnMouseOver(this.buttons[0]);
					break;
				case dynamic_mode.click:
					this.OnClick(this.buttons[0]);
					break;
			}
		}
		catch(e){}
	}