
var switchSystem = {
	activeIndex : 0,
	buttonList : null,

	init : function() {
		switchSystem.buttonList = $('.tabButton');

		var switchElems = $('.tabContent');

		var l = switchSystem.buttonList.length;

		if (!l) return;
	
		if (l != switchElems.length) alert(l + ' != ' + switchElems.length);
	
		for (var i = 0; i < l; ++i) {
			switchSystem.buttonList[i].myElem = switchElems[i];
			switchSystem.buttonList[i].myIndex = i;
		}

		switchSystem.activeIndex = 0;

		$(switchSystem.buttonList[0]).addClass('current');
		$(switchSystem.buttonList[0].myElem).show();

		switchSystem.buttonList.click(switchSystem.clickEvent);
		switchSystem.buttonList.show();
	},

	clickEvent : function (e) {
		if (e.stopPropagation) {
			e.stopPropagation();
		}
		e.cancelBubble = true;

		var activeElem = switchSystem.buttonList[switchSystem.activeIndex];

		$(activeElem).removeClass('current');
		$(activeElem.myElem).hide();

		switchSystem.activeIndex = this.myIndex;

		$(this).addClass('current');
		$(this.myElem).show();
	
	}
};

$(document).ready(switchSystem.init);

