/*

	madChickMenu 0.9 by ralf glaser 2004
	
	if there is a flash-movie that disturbes the dropDown, add the attribute 
	'madChickMenuFadeOut' to the object-tag:
	
	Example:
	<object type="application/x-shockwave-flash" data="http://www.metzingen.de/banner.swf" madChickMenuFadeOut="1">
  ..................................................
  
	include like this:
	
	..................................................
	<script language="JavaScript" type="text/JavaScript">
	
		items={
			'1':{
				'className':'dropDownBox',
				'contentClassName':'dropDownBoxContent',
				'items':new Array(
					{
						'className':'dropDownNavi',
						'onActive':'this.className=&amp;#039;dropDownNaviActive&amp;#039;;',
						'onDeactive':'this.className=&amp;#039;dropDownNavi&amp;#039;;',
						'href':'http://www.hitcom.de/dropDownNavi1.1',
						'html':'dropDownNavi1.1'
					},
					{
						'className':'dropDownNavi',
						'onActive':'this.className=&amp;#039;dropDownNaviActive&amp;#039;;',
						'onDeactive':'this.className=&amp;#039;dropDownNavi&amp;#039;;',
						'href':'http://www.hitcom.de/dropDownNavi1.2',
						'html':'dropDownNavi1.2'
					}
				)			
			},
			'2':{
				'className':'dropDownBox',
				'contentClassName':'dropDownBoxContent',
				'items':new Array(
					{
						'className':'dropDownNavi',
						'onActive':'this.className=&amp;#039;dropDownNaviActive&amp;#039;;',
						'onDeactive':'this.className=&amp;#039;dropDownNavi&amp;#039;;',
						'href':'http://www.hitcom.de/dropDownNavi2.1',
						'html':'dropDownNavi2.1'
					}
				)
			}
		};
			
		madChickMenu=new madChickMenuEngine('madChickMenu',items,'Math.round((document.body.clientWidth-780)/2)+780');
			
	</script>
	....................................................
	place topNavi-items like this:
	
	<div class="topNavi" onmouseover="madChickMenu.show('1');" onmouseout="madChickMenu.setTimer();">
		<script language="JavaScript" type="text/JavaScript">madChickMenu.renderItem('1');</script>
		<a href="#">topNavi1</a>
	</div>
	.....................................................
	note: class 'topNavi' has to positioned 'relative' !
	      class 'dropDownBox' has to positioned 'absolute' !
	

*/

function madChickMenuEngine(name,items,maxRightMargin)  {
	
	var machine=this;
		
	this.name=name;
	this.items=items;
	this.maxRightMargin=(maxRightMargin ? maxRightMargin : 'Math.round((document.body.clientWidth-780)/2)+780');
			
	this.timer=500;
	this.timerObj=false;
	
	/*********************/
	/*    public         */
	/*********************/
	
	//-----------------------------------------------------------------------------
	this.renderItem=function(id)  {

		html='';
									
		if (this.items[id] && this.items[id]['items'] && this.items[id]['items'].length>0) {
		
						
			html+='<div';
			html+=' id="'+this.name+'_'+id+'"';
			html+=' onmouseover="'+this.name+'.clearTimer();"';
			html+=' onmouseout="'+this.name+'.setTimer();"';
			html+=(this.items[id]['className'] ? ' class="'+this.items[id]['className']+'"' : '');
			html+='>';
		
			html+='<div';
			html+=' onmouseover="'+this.name+'.clearTimer();"';
			html+=' onmouseout="'+this.name+'.setTimer();"';
			html+=(this.items[id]['contentClassName'] ? ' class="'+this.items[id]['contentClassName']+'"' : '');
			html+='>';
		
			for (j=0;j<this.items[id]['items'].length;j++) {
			
				html+='<div';
				html+=' onmouseover="'+this.name+'.clearTimer();'+(this.items[id]['items'][j]['onActive'] ? this.items[id]['items'][j]['onActive'] : '')+'"';
				html+=' onmouseout="'+this.name+'.setTimer();'+(this.items[id]['items'][j]['onDeactive'] ? this.items[id]['items'][j]['onDeactive'] : '')+'"';
				html+=(this.items[id]['items'][j]['className'] ? ' class="'+this.items[id]['items'][j]['className']+'"' : '');
				html+='>';
								
				html+='<a';
				html+=' href="'+this.items[id]['items'][j]['href']+'"';
				html+=' onfocus="'+this.name+'.clearTimer();"';
				html+=' onblur="'+this.name+'.setTimer();"';
				html+='>';
				
				html+=this.items[id]['items'][j]['html'];
				
				html+='</a>';
				
				html+='</div>\n';
				
			}
		
			html+='</div>';
			html+='</div>\n';
			
		}
		
			
		document.write(html);

	}
	
	//-----------------------------------------------------------------------------
	this.show=function(id)  {
 		 		
 		id=this.name+'_'+id;
 		 		
		if (document.getElementById && document.getElementById(id))  {
 			
 			this.clearTimer();
 			
			this.hide();
						
			rightMargin=(parseInt(document.getElementById(id).offsetLeft))+parseInt(document.getElementById(id).parentNode.offsetLeft)+parseInt(document.getElementById(id).offsetWidth);
			maxRightMargin=(isNaN(this.maxRightMargin) ? eval(this.maxRightMargin) : parseInt(this.maxRightMargin));
			

			
			if (rightMargin>maxRightMargin) {
											
				newLeft=parseInt(document.getElementById(id).offsetLeft)+maxRightMargin-rightMargin;
				document.getElementById(id).style.left=newLeft+'px';
				
			}
			
			document.getElementById(id).style.visibility='visible';
 		
 			this.toggleObjectsVisibility('hidden');
 			
		}
	
	}

	//-----------------------------------------------------------------------------
	this.setTimer=function ()  {
		
		this.clearTimer();
		this.timerObj=setTimeout(this.callHide,this.timer);
				
	}
	
	//-----------------------------------------------------------------------------
	this.callHide=function ()  {
	
		// diese Prozedur ist etwas umständlich, aber nötig, damit der IE5 nicht abstürzt
		machine.hide();
	
	}
	
	//-----------------------------------------------------------------------------
	this.clearTimer=function ()  {
		
		clearTimeout(this.timerObj);
				
	}
	
	/*********************/
	/*    private        */
	/*********************/

	//-----------------------------------------------------------------------------
	this.hide=function ()  {
				
		if (document.getElementById)  {
			
			for (i in this.items) {
		
				if (obj=document.getElementById(this.name+'_'+i))  {
					
					obj.style.visibility='hidden';
					
				}
			
			}
		
		}
			
 		this.toggleObjectsVisibility('visible');
 			
	}	
	
	//-----------------------------------------------------------------------------
	this.toggleObjectsVisibility=function (visibility)  {
		
		if (document.body.getElementsByTagName)  {
			
			objs=document.body.getElementsByTagName('OBJECT');
						
			for (i=0;i<objs.length;i++)  {
				
				if (objs[i].getAttribute('madChickMenuFadeOut')) {
					
					objs[i].style.visibility=visibility;
					
				}
				
			}
	
		}
	
	}		

}
