// ----------------------------------------------------------------------------
//
//   file:      tmwat.js
//   function:       
//   Erstellt:	05/08/11
//   copyright: © 2011 <i-D> internet + Design GmbH & Co. KG
//              Erfurter Str. 35
//              99423 Weimar
//              Deutschland
//              Fon:     03643 7785 0
//              Fax:     03643 7785 29
//              E-Mail:  office@i-d.de
//              Web:     http://www.i.d.de/
//   author:    Michael Waack <m.waack@i-d.de>
//
// ---------------------------------------------------------------------------

idTools.Require('prototype');
	var tmwatNav= Class.create({
		initialize: function () {
			this.items = $$('ul.naviLevel1 li a');
			this.loader();
		},
		
		loader : function () {
			var url = 'nav.html';
			that = this;
			request = new Ajax.Request(url, {
				method: 'get',
				evalJS: true,
				onSuccess: function (transport) {that.loaderReady(that,transport); }
			});			
		},
		
		loaderReady : function(that,transport) {
			var result = transport.responseText;
			nav = new Element('div').update(result);
			that.naviOuter = nav;
			rx = /.*\/(.+)\/?$/; // RegEx für categorypfad, wird in der class gesucht um den richtigen abschnitt zu finden
			for (i=0;i<this.items.length;i++) {
				category = rx.exec(this.items[i].href)[1];
				category = category.replace(/\//,'');
				this.items[i].up().select('span').each(function(s){s.remove();});
				current = this.naviOuter.select('.'+category);
				if (current.length==1) {
					this.items[i].nav = current[0];
					this.items[i].nav.hide();
					this.items[i].up().insert(current[0]);
					Event.observe(this.items[i].nav, 'mouseover', this.show.bindAsEventListener(this, this.items[i].nav));
					Event.observe(this.items[i], 'mouseover', this.show.bindAsEventListener(this, this.items[i].nav));
					Event.observe(this.items[i].up(), 'mouseout', this.hide.bindAsEventListener(this, this.items[i].nav));
				}
			}			
		}, 
		show : function(ev, item) {
			item.show();	
		},
		hide : function(ev,item) {
			item.hide();	
		}
		
	});
	
document.observe('dom:loaded', function () {
	new tmwatNav();
});	

