// JavaScript Document

	$(document).ready(function() {		
			$(".menu_chosen").children().each(function(){
					 var file="url(ximg/frame/"+$(this).attr("class")+"_h.jpg)";
					 $(this).css("background-image", file).css("color","#ffffff").css("font-weight","bold");
				 });
			
			$("a.menu_but").not('.menu_chosen').hover(
				function () {
				 $(this).children().each(function(){
					 var file="url(ximg/frame/"+$(this).attr("class")+"_h.jpg)";
					 $(this).css("background-image", file).css("orcolor", $(this).css('color')).css("color","#ffffff").css("text-decoration","none");
				});
			 },
			function () {
				 $(this).children().each(function(){
					 var file="url(ximg/frame/"+$(this).attr("class")+".jpg)";
					 $(this).css("background-image", file).css("color",$(this).css('orcolor'));
				 });

			 });
			
			$('#submenu_popup').hide();
			$('div.submenu_wrapper').hover(
				function(){
				if($(this).children('div.popup_menu').html()!==null){
					$('#submenu_popup div.popup_content').html($(this).children('div.popup_menu').html());
					var offset =$(this).offset();
					var leftpos=offset.left + ($(this).width()/2) - ($('#submenu_popup').width()/2);
					$('#submenu_popup').css('left', leftpos+"px");
					$('#submenu_popup').show();
					$('#submenu_popup').mouseleave(function(e){
						var offsetthis =$(this).offset();
						if(e.pageY>offsetthis.top+$(this).height() || e.pageX<offsetthis.left || e.pageX>offsetthis.left+$(this).width()){
	   						$('#submenu_popup').hide();
						}
					});
				}},
				function(e){
					var offsetthis =$(this).offset();
					var offsetpopup=$('#submenu_popup').offset();
					//alert(e.pageY);
					if(e.pageY<offsetthis.top || e.pageX<offsetpopup.left || e.pageX>offsetpopup.left+$('#submenu_popup').width()){
   						$('#submenu_popup').hide();
					}
				}
			);
			
			$('#topmenu_popup').hide();
			$('div.menu_wrapper').hover(
				function(){
				if($(this).children('div.popup_menu').html()!==null){
					$('#topmenu_popup div.popup_content').html($(this).children('div.popup_menu').html());
					var offset =$(this).offset();
					var leftpos=offset.left + ($(this).width()/2) - ($('#topmenu_popup').width()/2);
					$('#topmenu_popup').css('left', leftpos+"px");
					$('#topmenu_popup').show();
					$('#topmenu_popup').mouseleave(function(e){
						var offsetthis =$(this).offset();
						if(e.pageY>offsetthis.top+$(this).height() || e.pageX<offsetthis.left || e.pageX>offsetthis.left+$(this).width()){
	   						$('#topmenu_popup').hide();
						}
					});
				}},
				function(e){
					var offsetthis =$(this).offset();
					var offsetpopup=$('#topmenu_popup').offset();
					//alert(e.pageY);
					if(e.pageY<offsetthis.top || e.pageX<offsetpopup.left || e.pageX>offsetpopup.left+$('#topmenu_popup').width()){
   						$('#topmenu_popup').hide();
					}
				}
			);
			
			
			
		$("img.rollover").hover(
		function() {
				ext=this.src.substring(this.src.length-4 , this.src.length);
				this.src=this.src.replace(ext ,"_h"+ext);
			 },
		function () {
			ext=this.src.substring(this.src.length-4 , this.src.length);
				this.src=this.src.replace("_h"+ext ,ext);
			 }
		);
		
		$(".arrow_img").hover(
		function() {
			var newsrc=$(this).attr('src').replace('t.','t_h.');
				$(this).attr('src',newsrc);
			 },
		function () {
				var newsrc=$(this).attr('src').replace('t_h.','t.');
				$(this).attr('src',newsrc);			 
				}
		);
			
		$("#header_phone").hover(
		function () {
				$("#telephone_num").css("visibility","visible");
			 },
		function () {
				$("#telephone_num").css("visibility","hidden");
			 }
		);
		
		$("#input_nl").focus(function () {
				if(this.value=="Ihre Email") { this.value=""; };
			});
		
		$("#footer_nl_submit").click(function () {	  
				if($("#nl_hp").val().length == 0){
					$("#form_nl").submit();
				}		
		});
		
		$('#contact_submit').click(function(){
			
			if($('#kontakt_hp').val().length > 0){
				return false;
			}
			
				subit=true;
				
				$('.verify').each(function(){
					if($(this).val().length < 2){
						$(this).css("background", "#884b4b");
						//subit=false;
					}else{
						$(this).css("background","#636363");
					}
				 });
				
				if(subit){ 
					$('#kontaktformular').submit(); 
				}
		});
		
		
			
});
	
function getUrlVars() {
   var vars = {};
   var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}


function hidepopup(){
	$('#submenu_popup').mouseleave(function(){									 
			$('#submenu_popup').hide();
	});
	$('#topmenu_popup').mouseleave(function(){									 
			$('#topmenu_popup').hide();
	});
}