var hauptnavigation = {
	/* Der Wert des Timers kann frei eingestellt werden: */
	closeTimer_timer : 1000,
	openTimer_timer : 200,
	default_background : '3a98d4',
	closeTimer_num : null,
	openTimer_num : null,
	openTimer_obj : null,
	open_obj : null,
	org_class : new Array(),
	org_color : new Array(),

	mark_color : function (obj,override)
	{
		if (override||hauptnavigation.org_class[obj.parent().attr('id')].indexOf('activ')==-1)
		{
			my_color=obj.attr('class').replace('navi_color_','');
			if (!my_color)
				my_color=hauptnavigation.default_background;

			if (override==1)
				hauptnavigation.org_color[hauptnavigation.org_color.length]=obj.parent().attr('id');

			obj.next().css('backgroundColor','#'+my_color);
			obj.parent().css('backgroundColor','#'+my_color);

			nextobj=obj.parent().next();

			if (nextobj)
				if(nextobj.attr('nodeType')!=1)
					nextobj=nextobj.next();

			if (nextobj&&nextobj.attr('nodeType')==1&&(nextobj.attr('class')=='point' || nextobj.attr('class')=='point inactive')) {
				nextobj.css('backgroundColor','#'+my_color);
				nextobj.children().css('visibility','hidden');
			}

			prevobj=obj.parent().prev();
			if (prevobj)
				if (prevobj.attr('nodeType')!=1)
					prevobj=prevobj.prev();

			if (prevobj&&prevobj.attr('nodeType')==1&&prevobj.attr('class')=='point')
			{
				prevobj.css('backgroundColor','#'+my_color);
				prevobj.children().css('visibility','hidden');
			}

			if (obj.children().attr('nodeName')=='IMG')
			{
				imgname=obj.children().attr('src');
				imgname=imgname.replace('_on','');
				imgname=imgname.replace('.gif','_on.gif');
				obj.children().attr('src',imgname);
			}
		}
	},

	unmark_color : function (obj,override)
	{
		if (this.org_class[obj.parent().attr('id')].indexOf('activ')==-1||override)
		{
			my_color=obj.attr('class').replace('navi_color_','');
			if (!my_color)
				my_color=this.default_background;
			obj.next().css('backgroundColor','transparent');
			obj.parent().css('backgroundColor','transparent');

			nextobj=obj.parent().next();

			if (nextobj)
				if(nextobj.attr('nodeType')!=1)
					nextobj=nextobj.next();

			if (nextobj&&nextobj.attr('nodeType')==1&&(nextobj.attr('class')=='point' || nextobj.attr('class')=='point inactive')) {
				nextobj.css('backgroundColor','transparent');
				nextobj.children().css('visibility','visible');
			}

			prevobj=obj.parent().prev();
			if (prevobj)
				if (prevobj.attr('nodeType')!=1)
					prevobj=prevobj.prev();

			if (prevobj&&prevobj.attr('nodeType')==1&&prevobj.attr('class')=='point')
			{
				prevobj.css('backgroundColor','transparent');
				prevobj.children().css('visibility','visible');
			}

			if (obj.children().attr('nodeName')=='IMG')
			{
				imgname=obj.children().attr('src');
				imgname=imgname.replace('_on','');
				obj.children().attr('src',imgname);
			}

			$.each(hauptnavigation.org_color,function (i) {
				hauptnavigation.mark_color($('#'+this).children(),2);
			});
		}
	},

	openTimer : function ()
	{
		if (hauptnavigation.open_obj)
			hauptnavigation.closeTimer();

		obj=hauptnavigation.openTimer_obj;

		obj.next().css('display','block');
		obj.parent().css('zIndex','10');

		obj.next().css('marginLeft',(obj.parent().attr('offsetLeft')*-1)+'px');
		obj.next().css('marginTop',obj.parent().attr('offsetHeight')+'px');

		hauptnavigation.mark_color(obj);


		obj.parent().attr('class',obj.parent().attr('class').replace(' activ',''));
		obj.parent().attr('class',obj.parent().attr('class')+' activ');
		hauptnavigation.open_obj=obj;
	},

	open : function (obj)
	{
		if (obj.attr('nodeName')!='A')
				obj=obj.prev();

		if (hauptnavigation.closeTimer_num)
		{
			window.clearTimeout(hauptnavigation.closeTimer_num);
			hauptnavigation.closeTimer_num=null;
		}

		same=0;
		if (hauptnavigation.open_obj)
			if (hauptnavigation.open_obj.parent().attr('id')==obj.parent().attr('id'))
				same=1;

		if (!same)
		{
			hauptnavigation.openTimer_num=window.setTimeout('hauptnavigation.openTimer()',hauptnavigation.openTimer_timer);
			hauptnavigation.openTimer_obj=obj;
		}
	},

	closeTimer : function ()
	{
		if (hauptnavigation.open_obj)
		{
			obj=hauptnavigation.open_obj;
			obj.parent().attr('class',hauptnavigation.org_class[obj.parent().attr('id')]);
			obj.next().css('display','none');
			obj.parent().css('zIndex','1');
			hauptnavigation.closeTimer_num=null;
			hauptnavigation.open_obj=null;
			hauptnavigation.unmark_color(obj);
		}
	},

	close : function (obj)
	{
		if (obj.attr('nodeName')!='A')
			obj=obj.prev();

		if (hauptnavigation.openTimer_num)
		{
			window.clearTimeout(hauptnavigation.openTimer_num);
			hauptnavigation.openTimer_num=null;
		}

		same=0;
		if (hauptnavigation.open_obj)
			if (hauptnavigation.open_obj.parent().attr('id')==obj.parent().attr('id'))
				same=1;

		if (same)
			hauptnavigation.closeTimer_num=window.setTimeout('hauptnavigation.closeTimer()',hauptnavigation.closeTimer_timer);
	},

	init : function ()
	{
	  var navEl = $('#naviNav');
		if (navEl.attr('nodeType')) {
		  var navElChildren = navEl.children();
			if (navElChildren.attr('nodeType')==1)
				var navigation=navElChildren.contents();
			else
				var navigation=navElChildren.next().contents();

				navigation.each(function (i) {
				  var currentEl = $(this);
				if (currentEl.attr('nodeType')==1)
				{
					if (currentEl.attr('class').substr(0,4)=='navi')
					{
						hauptnavigation.org_class[currentEl.attr('id')]=currentEl.attr('class');

						var currentElChildren = currentEl.children();
						if (currentEl.attr('class').indexOf('activ')!=-1)
							hauptnavigation.mark_color(currentElChildren,1);

						currentElChildren.bind('mouseover',function(){hauptnavigation.open($(this))});
						currentElChildren.bind('mouseout',function(){hauptnavigation.close($(this))});
						currentElChildren.next().next().bind('mouseover',function(){hauptnavigation.open($(this))});
						currentElChildren.next().next().bind('mouseout',function(){hauptnavigation.close($(this))});

						nextobj=currentEl.next();

						if (nextobj)
							if(nextobj.attr('nodeType')!=1)
								nextobj=nextobj.next();

						my_color=currentElChildren.attr('class').replace('navi_color_','');
						if (!my_color)
							my_color=hauptnavigation.default_background;

						if (nextobj&&nextobj.attr('nodeType')==1&&nextobj.attr('class')=='point')
							nextobj.children().css('backgroundColor','#'+my_color);

						// Farbe der Links für Mouseover setzen
						var anchors = $("div.inner td em a", this);
						anchors.bind('mouseover',function(){
							$(this).css("color", '#'+my_color);
						});
						anchors.bind('mouseout',function(){
							$(this).css("color", '#FFFFFF');
						});
					}
				}
			});
		}
	}

};

$(document).ready(function(){
	hauptnavigation.init();
});