function PanelBrowser(pHashState) {
	var self = this;
	this.hashState = pHashState;
	this.lastTabClicked = '';
	this.origPageTitle = document.title;
	this.filterSets = new Array();
	this.filters = new Array();
	this.filterParts = new Array();
	
	this.init = function() {
		$('a.tab').click(
			function() {
				return self.showContent(this);
			}
		);

		$('div.tabswrapper a.tab').show();
	}
	
	this.activateTabs = function() {
		if (self.hashState.hasItem('tabsState')) {
			var tabsState = self.hashState.getItem('tabsState');
			var tabsStateArray = tabsState.split(',');

			for (var i = 0; i < tabsStateArray.length; i++) {
				self.activateTab($('#' + tabsStateArray[i]));
			}
		} else {
//			$('.tab').filter('.l1').filter('.active').click();

//			if (!$('.tab').filter('.l1').eq(0).hasClass('active')) {
				$('.tab').filter('.l1').eq(0).click();
//			}

		}
	}

	this.activateTab = function(theTab) {
		theTab.siblings().removeClass('active');
		theTab.addClass('active');
	    
		var theTabPanel = $('#' + theTab.attr('id') + 'panel');
	    
		theTabPanel.siblings().filter('.' + theTabPanel.attr('class')).hide();
		theTabPanel.show();
		
		if (theTabPanel.find('.tab').length > 0) {
			self.ensureSomethingSelected(theTabPanel.find('.tab').eq(0).parent());
		}
		
		self.lastTabClicked = theTab.attr('id');
	}
	
	this.ensureSomethingSelected = function(listBox) {
		if(listBox.find('a:visible.active').length == 0) {
			$(listBox.find('a:visible')[0]).click();
		}
	}

	this.saveTabsState = function() {
		var tabsState = '';
		var tabsStateArray = new Array();
		var activeTabs = $('.tab').filter('.active');

		for (var i = 0; i < activeTabs.length; i++) {
			var currentTab = activeTabs.eq(i);
			if (currentTab.attr('id') != self.lastTabClicked) {
				tabsStateArray.push(currentTab.attr('id'));
			}
		}

		if (self.lastTabClicked != '') {
			tabsStateArray.push(self.lastTabClicked);
		}

		tabsState = tabsStateArray.join(',');
		self.hashState.setItem('tabsState', tabsState);
	}

	this.showContent = function(theElement) {
		self.activateTab($(theElement));

		self.saveTabsState();

		self.setPageTitle($(theElement));

		return false;
	}

	this.applyFilters = function() {
		for (var name in self.hashState.pairs) {
			
			if ($('#' + name) !== undefined) {
				var filter = $('#' + name);
				
				if (self.filterParts[name] !== undefined) {
					filter.val(self.hashState.pairs[name]);
					filter.change();
				}
			}
		}
	}

	this.applyFilter = function(theElement, filterTarget) {
		self.ensureSomethingSelected(filterTarget);
		self.hashState.setItem(theElement.attr('id'), theElement.val());
	}

	this.restoreState = function() {
		self.activateTabs();
		self.applyFilters();
	}

	this.setPageTitle = function(theElement) {
		var linkTitle = theElement.attr('title');
		if (linkTitle != "") {
			document.title = self.origPageTitle + ': ' + linkTitle;
		}
	}

	this.adjustListHeight = function(theTimerDelay) {
		var activeTabName = $('.l1').filter('.active').attr('id');
		var minHeight = 260;
		if (document.getElementById(activeTabName + 'listbox')) {
			var listBox = document.getElementById(activeTabName + 'listbox');
			var detailsBox = document.getElementById(activeTabName + 'detailsbox');
			if (detailsBox.scrollHeight > minHeight) {
				listBox.style.height = detailsBox.scrollHeight + 'px';
			} else {
				listBox.style.height = minHeight + 'px';
			}
		}
		setTimeout(self.adjustListHeight, theTimerDelay);
	}
}
