HW.onload(function() {
	Tabs.init();
})

var Tabs = {
	
	content: null,
	
	tabs: null,
	
	init: function(){
		var obj = this;
		//permanently hide horizontal rule
		HW.hide(_$('.tabbedContent02 > hr'));
		//get tabs and corresponding content blocks
		this.content = _$$('.tabbedContent02 .Elem');
		this.tabs = _$$('.tab').reverse();
	
		//attach event handlers to each tab
		for(var i = 0; i < this.tabs.length; i++){
			var tabs = this.tabs;
			(function(){
				var index = i;
				HW.attachEvent(tabs[index], 'click', function(){obj.activate(index);}, false);
			})()
		}
		//var url = new String(window.location);
		HW.log(new String(window.location).split('#')[1]);
		if(new String(window.location).split('#')[1] == 'ad2009t')
			this.activate(0);
		else
			this.activate(1);
		
		//hide h2
		_$$('.tabbedContent02 h2').each(function(elem){HW.hide(elem);});
	},
	
	activate: function(index){
		if(index < this.tabs.length && index >= 0){
			//set correct tab to current and expose associated content
			//deactivate all other tabs and hide all other content
			for(var i = 0; i < this.tabs.length; i++){
				if(i == index){
					this.tabs[i].addClass('current');
					HW.hide(this.content[i]);
				}else{
					this.tabs[i].removeClass('current');
					HW.show(this.content[i]);	
				}
			}
		}
	}

}
