/* 
	tabMaker.js
	- jb, 5/22/06


	to use this tabMaker object, you need to set up your document as follows:
	
		- each tab has a code word for reference. e.g., "recent", "popular", etc.
		- each tab must have an ANCHOR with the ID set to the code word followed by "Tab"
			for example, id="recentTab"
		- the anchors must have class="on" and class="off" defined. THEY CANNOT HAVE ANY
			other classes on them! this method overwrites the classes.
		- each tab must also have an associated div which holds the content to 
			display. the div needs to have ID set to the code word followed by "Content"
			for example, id="recentContent"
		
	that's it.

	to initialize it, pass in an array of strings ['one','two','three'].
	optionally, pass in startTab, which is the one assumed to be in the ON state.
	if you omit it, we'll assume the first tab in the array is ON.

	---------------

	HTML:
		<a id="recentTab" href="javascript:;" class="on">Recent Releases</a>
		<a id="popularTab" href="javascript:;" class="off">Most Popular</a>
		<a id="editorsPicksTab" href="javascript:;" class="off">Editors&rsquo; Picks</a>
	
		<div id="recentContent">...</div>			<< showing to start
		<div id="popularContent">...</div>			<< hidden to start
		<div id="editorsPicksContent">...</div>		<< hidden to start

	SCRIPT:
		tbm = new tabMaker( ['recent','popular','editorsPicks']);
*/

function tabMaker(tabList,startTab) {

	this.currentTab = (startTab ? startTab : tabList[0]);
	this.switchTab = function(anc) {
		switchTo = anc.tabID;
		
		if ( switchTo != this.currentTab) {
			$(this.currentTab+'Content').style.display = 'none';
			$(switchTo+'Content').style.display = 'block';
	
			setCls( $(this.currentTab+'Tab'), 'off');
			setCls( $(switchTo+'Tab'), 'on');
			
			this.currentTab = switchTo;
		}
	}

	// this function is really procedural here. "this" refers to
	// the anchor tag, which is passed thru from the event mgr
	function tabMakerSwitchTab() {this.tabMaker.switchTab( this);}
	
	for(i=0;i<tabList.length;++i) {
		anc = $(tabList[i]+'Tab');
		anc.tabMaker = this;
		anc.tabID = tabList[i];
		// attach an onclick event to the tab
		addEvent(anc,'click',tabMakerSwitchTab,true);
	}
}
