var Tabs = Class.create();

Tabs.prototype = {
	selectTab: function (e) {
		var targ;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) targ = targ.parentNode;

		// Activate the pane.
		this.activatePane(targ.className.match(/pane[0-9]+/));

		// Cancel the action.
		e.returnValue = false;
	},
	
	activatePane: function(pane) {
		// Remove the current selected pane
		this.container.className = this.container.className.replace(/selected-pane[0-9]+/, "");

		// Add in a new current selected pane
		this.container.addClassName("selected-" + pane);
		
		// show or hide the bottom search border
		// pane2 = advanced search, always display the bottom search box border
		if (pane == "pane2"){
		    BottomSearchBoxBorder.removeClassName("invisible");
		}
		else {
		    // pane1 = quick\light search, always display when recent-search-box div box does not exists
		    if ($("recent-search-box") != null && this.container.hasClassName("selected-pane1"))
		    {
		        BottomSearchBoxBorder.addClassName("invisible");
		    }
		}
	},

	initialize: function(e, initialTab) {
		// Remember the container
		this.container = $(e);
		
		// Replace any default tabs with the one specified
		if (initialTab) {
			this.activatePane(initialTab);
		}

		// Get all links in the container
		var tabs = this.container.getElementsByTagName("a");
		for (i = 0; i < tabs.length; i++) {
			var tab = tabs[i];
			if (tab.className.match(/pane[0-9]+/)) {
				Event.observe(tab, "click", this.selectTab.bindAsEventListener(this));
			}
		}
	}
};
