var RHEINFILS={	
	history:{activepanel: null, activePhoto: null},	
	historyOverview:{activepanel: null, activePhoto: null},	
	dimensions:{defaultHeight: 61, submenuMarginTop: 15, submenuMarginBottom: 15}, // MENU height in closed modus, submenu content margin (top+bottom)
	animation:{durationOpen: 300, durationClose: 300}, //open and close animation duration
/*
* Buildmenu
*/	
	buildmenu:function(menuid){		
		var container = $("#"+menuid), menuUl = $(".menu"), aHeight = null, newHeight = null;
		//check for initial state, open li with class .active
		menuUl.children("li").each(function() {											 
				if($(this).hasClass('active') && RHEINFILS.history.activepanel == null){					
					if(RHEINFILS.history.activepanel == null){
						aHeight = $(this).find("ul li a").outerHeight(true) + RHEINFILS.dimensions.submenuMarginTop + RHEINFILS.dimensions.submenuMarginBottom; 
						newHeight = aHeight + RHEINFILS.dimensions.defaultHeight;
						container.css({'height':newHeight+'px'});	
						RHEINFILS.history.activepanel = $(this);
						return false;
					}else{
						$(this).removeClass('active');
					}
				}
		});			
		container.find("li").each(function() {
			// check for submenu items					  
			if ($(this).find("ul").length > 0) {
				// get current li
				var activeLi = $(this);
				//attach 'open' to click on first a
				activeLi.children("a:first").mouseover(function() {									
					//do nothing is panel is already open
					if(RHEINFILS.history.activepanel == activeLi){	return false; }
					//close open panel
					if(RHEINFILS.history.activepanel != null){
						RHEINFILS.history.activepanel.removeClass('active');}					
					activeLi.addClass('active');	
					//store active panel
					RHEINFILS.history.activepanel = activeLi;
					//calculate needed height
					//add top bottom margin	
					aHeight = activeLi.find("ul li a").outerHeight(true) + RHEINFILS.dimensions.submenuMarginTop + RHEINFILS.dimensions.submenuMarginBottom; 				
					//add new height to container					
					newHeight = aHeight + RHEINFILS.dimensions.defaultHeight; 
					container.animate({height: newHeight+'px'}, 
					  {
						 duration: RHEINFILS.animation.durationOpen, 
						 easeMethod:  'easein'				 							 
					  });							
				});			
					
			}// if has subitems
		});	
		$("#mainmenu").mouseleave(function () {
				if(RHEINFILS.history.activepanel != null){
				RHEINFILS.history.activepanel.removeClass('active');}
				RHEINFILS.history.activepanel=null;
				var activeLi=$(this).find("li.active2");
				
				activeLi.addClass('active');
				RHEINFILS.history.activepanel = activeLi;
					//calculate needed height
					//add top bottom margin	
					aHeight = activeLi.find("ul li a").outerHeight(true) + RHEINFILS.dimensions.submenuMarginTop + RHEINFILS.dimensions.submenuMarginBottom; 				
					//add new height to container					
					newHeight = aHeight + RHEINFILS.dimensions.defaultHeight; 
					if (activeLi.attr("id")) {
					container.animate({height: newHeight+'px'}, 
					  {
						 duration: RHEINFILS.animation.durationOpen, 
						 easeMethod:  'easein'				 							 
					  });						
					} else {
					container.animate({height: '61px'}, 
					  {
						 duration: RHEINFILS.animation.durationOpen, 
						 easeMethod:  'easein'				 							 
					  });						
						
						
					}
				
										});
				//attach 'open' to click on first a

					
	},
	
/*
* Function to bint click event to overlay thumbnails
*/
	switchphoto:function(containerDiv){					
		var container = $('#'+containerDiv);		
		container.find(".thumbs a").each(function() {
		$(this).click(function() {
				if(RHEINFILS.history.activePhoto == $(this)){
					return false;
				}else{
					// get overlay
					var overlay = $(this).parents('div.overlay');	
					// get main img
					var img = overlay.find('img:first');					
					// set main img
					img.attr('src',$(this).attr('href'));
					if(RHEINFILS.history.activePhoto != null){
						RHEINFILS.history.activePhoto.removeClass('active');
						RHEINFILS.history.activePhoto.find('div:last').attr('style','inline');
						RHEINFILS.history.activePhoto.find('div:first').attr('style','display:none');
					} else {
						var erst = overlay.find('a:first');
						erst.removeClass('active');
						erst.find('div:last').attr('style','inline');
						erst.find('div:first').attr('style','display:none');

					}
					
					$(this).addClass('active');
					$(this).find('div:first').attr('style','inline');
					$(this).find('div:last').attr('style','display:none');
					RHEINFILS.history.activePhoto = $(this);					
				}
			});
		});		
	},
	
/*
* Function to bint click event to overlay thumbnails
*/
	switchphotoOverview:function(containerDiv){					
		var container = $('#'+containerDiv);		
		container.find(".thumbsOverview a.miniThumb").each(function() {
		$(this).mouseover(function() {
				if(RHEINFILS.historyOverview.activePhoto == $(this)){
					return false;
				}else{
					// get overlay
					var overlay = $(this).parents('div.thumbsOverview');	
					// get main img
					var img = overlay.find('img:first');					
					// set main img
					img.attr('src',$(this).attr('href'));
					if(RHEINFILS.historyOverview.activePhoto != null){
						RHEINFILS.historyOverview.activePhoto.removeClass('active');
						RHEINFILS.historyOverview.activePhoto.find('span:last').attr('style','inline');
						RHEINFILS.historyOverview.activePhoto.find('span:first').attr('style','display:none');
					} else {
						var erst = overlay.find('a:eq(1)');
						erst.removeClass('active');
						erst.find('span:last').attr('style','inline');
						erst.find('span:first').attr('style','display:none');

					}
					
					$(this).addClass('active');
					$(this).find('span:first').attr('style','inline');
					$(this).find('span:last').attr('style','display:none');
					RHEINFILS.historyOverview.activePhoto = $(this);					
				}
			});
		});		
	},
	
/*
* Set/reset default form values
*/
	formfocus:function(el,defaultText){
		var field = $(el);	
		if (defaultText == field.val()) { field.val(' '); }
	},
	
	formblur:function(el,defaultText){
		var field = $(el);
		if (' ' == field.val()) { field.val(defaultText); }
	}		
}
