if(this.PRO === undefined) {
	var PRO = {};
}

(function() {

var W = this, D = this.document;

if(D) {
	if (!D.getElementById || !D.getElementsByTagName || !D.createElement || !D.createTextNode) {
		return;
	}
	var html = D.documentElement || byTag('html');
	if (html) {
		html.id = 'js';
	}
}

var byID = function(id) {
	return D.getElementById(id);
};

var byTag = function(tag, c) {
	c = c || D;
	return (tag == '*' && D.all) ? c.all : c.getElementsByTagName(tag);
};

W.PRO.activateMenuItem = function(datas) {
	W.PRO.activateMenuItemIsDone = true;
	W.addDomReadyListener(function() {
		if (datas.main) {
			$(datas.main).addClassName('on');
		}
		if (datas.submenu) {
			$(datas.submenu).addClassName('on');
		}
	});
};

var SimpleTabs = function(datas) {
	SimpleTabs.superclass.constructor.call(this);
	
	this.addEvents(['show', 'hide'], (datas) ? datas.listeners : null);
	
	this.initialize(datas);
};
W.PRO.extend(SimpleTabs, W.PRO.Observable, {
	initialize: function(datas) {
		var that = this;
		
		that.tabsZone = byID(datas.tabsZone);
		Event.observe(that.tabsZone, 'click', function(e) {that.click(e);});
		
		var lks = byTag('a', that.tabsZone);
		var i = lks.length, lk, href;
		while (i--) {
			lk = lks[i];
			if ($(lk.parentNode).hasClassName('on')) {
				that.activeTab = $(lk.parentNode);
				that.activeSection = $(lk.href.replace(/^([^#]*)/, '').replace('#', '').replace('-js', ''));
			}
		}
		
		this.fireEvent('load');
	},
	
	click: function(e) {
		var t = e.target;
		while (t != this && t.parentNode) {
			if (t.nodeName.toLowerCase() == 'a' && t.href.indexOf('#') > -1) {
				var href = t.href.replace(/^([^#]*)/, '').replace('#', '').replace('-js', '');
				var tab = $(t.parentNode);
				if (!tab.hasClassName('on')) {
					var section = $(href);
					this.show(tab, section);
				}
				Event.stop(e);
				break;
			}
			t = t.parentNode;
		}
	},
	
	show: function(tab, section) {
		if (this.activeTab) {
			this.hide(this.activeTab, this.activeSection);
		}
		this.activeTab = tab.removeClassName('off').addClassName('on');
		this.activeSection = section.removeClassName('off').addClassName('on');
		this.fireEvent('show', tab, section);
	},
	
	hide: function(tab, section) {
		tab.removeClassName('on').addClassName('off');
		section.removeClassName('on').addClassName('off');
		this.fireEvent('hide', tab, section);
	}
});
W.PRO.SimpleTabs = SimpleTabs;

})();