
/*
Tabs Html Rules:

<div id="tabs_xxx" behavior="onmouseover">
	<div id="tab_heads_xxx">
		<ul>
			<li value="1"><a href="#">xxx</a></li>
			<li value="2"><a href="#">xxx</a></li>
		</ul>
	</div>
	<div id="tab_contents_xxx_1">
		xxx
	</div>
	<div id="tab_contents_xxx_2">
		xxx
	</div>
</div>
*/


var tabs_identity = "tabs_";
var tab_heads_identity = "tab_heads_";
var tab_contents_identity = "tab_contents_";

//  tab: Tabs Effect
var Tabs = Class.create();
Tabs.prototype = {
	initialize: function ( tabs_id ) {
		this.id = tabs_id;
		this.name = tabs_id.substring( tabs_identity.length );
		this.author = 'liusida';
		this.firstitem = null;
	},
	attachEvent : function ( behavior ) {
		if (typeof(behavior)=='undefined' || behavior == null ) {
			behavior = 'onmouseover';
		}
		if (!$(tab_heads_identity+this.name))
			return;
		var lis = $(tab_heads_identity+this.name).getElementsByTagName('li');
		for (var i=0; i<lis.length; i++) {
			
			if (lis[i].value > 0) {
				lis[i].name = this.id;
				eval( 'lis[i].'+behavior+' = this._switchTo;' );
			}
		}
	},
	_switchTo : function () {
		//this is li.onmouseover

		var obj = new Tabs(this.name);
		obj.showItem( this.value );
		this.blur();
		return false;

	},
	hideAllContents : function () {
		var divs = $(this.id).getElementsByTagName('div');
		for (var i=0; i<divs.length; i++) {
			if (divs[i].id.indexOf(tab_contents_identity+this.name)==0 ) {
				divs[i].style.display = 'none';
			}
		}
	},
	showContent : function ( index ) {
		if ($(tab_contents_identity + this.name + '_' + index)) {
			$(tab_contents_identity + this.name + '_' + index).style.display = 'block';
		}
	},
	unHighlightAll : function () {
		var lis = $(tab_heads_identity + this.name).getElementsByTagName('li');
		for (var i=0; i<lis.length; i++) {
			if (lis[i].className == 'on') {
				lis[i].className = '';
			}
		}
	},
	showItem : function ( index ) {
		if (typeof(index)=='undefined') {
			index = 1;
		}
		if (!$(tab_heads_identity+this.name)) {
			return ;
		}
		var lis = $(tab_heads_identity+this.name).getElementsByTagName('li');
		for (var i=0; i<lis.length; i++) {
			if (lis[i].value == index) {
				this.firstitem = lis[i];
			}
		}
		this.hideAllContents();
		this.unHighlightAll();

		this.firstitem.className = 'on';
		this.showContent( this.firstitem.value );
	}

}



function initTabs() {
	var divs = document.getElementsByTagName('div');
	for (var i=0; i<divs.length; i++) {
		if (divs[i].id.indexOf('tabs_')==0) {
			var tabs = new Tabs(divs[i].id);
			tabs.attachEvent(divs[i].getAttribute("behavior"));
			tabs.showItem();
		}
	}
}
