
    document.observe("dom:loaded", function() {
    
    	show_active_menue();
    	
    	function show_active_menue() {
   		
    		var ms = $$('#mainmenue a.active'); 		
			ms.each(function(m) {
    			 m.up("ul").setStyle({display:'block'});
    		});
			_show_sub_menue(ms.last());
    	}
    
    $$('#mainmenue a').invoke('observe', "click", function(event) {
        $$('#mainmenue a').invoke('stopObserving');
       });
    $$('#mainmenue a').invoke('observe', 'mouseover', show_sub_menue);
    	
    	 function show_sub_menue(event) {
        	event.stop();
        	_show_sub_menue(this)
        	
        	return; 

          }
    	 
    	 
    	 function _show_sub_menue(element) {
    		 if(element) {
	    		var uls = element.up("ul").select("ul");
	         	var as = element.up("ul").select("a");
	
	         	as.each(function(a) {
	         		a.removeClassName("active");
	         	});
	
	         	uls.each(function(ul) {
	         		ul.setStyle({display:'none'});
	         	});
	
	         	var act_menue = element.up().childElements()[1];    	
	         	if(act_menue) { //aktuelle Liste einblenden
	 				if(act_menue.tagName == "UL") { 
	            			act_menue.setStyle({display:'block'});
	            		}
	 			}
	 			
	         	element.addClassName("active");
    		 }
    	 }
    	 
    
        $$('#themes a.theme_menu_link').invoke('observe', 'click', toggle_theme_menu_link);
        
        
        
        var duration = 0.3;
        var transition = function(pos) {
        	return Math.sqrt(pos);
        };
        
        function toggle_theme_menu_link(event) {
        	event.stop();
            var that = this;
            this.blur();
            $$("#themes a.open").each(function(a) {
                if(a != that) {
                    a.removeClassName("open");
                    new Effect.Morph(a.up("div"), {
                      style: 'height:50px;top:0px;', // CSS Properties
                      duration: duration, // Core Effect properties
                      transition:transition
                    });
                    
                }
            });
            
           
            
            var parent_div = this.up("div");
            var header;
            if(this.hasClassName("open")) {
                // dann schließen:
                this.removeClassName("open");
                new Effect.Morph(parent_div, {
                  style: 'height:50px;top:0px;', // CSS Properties
                  duration: duration, // Core Effect properties
                  transition:transition
                });
               header = "theme_default";
            } else {
                // dann öffnen
                this.addClassName("open");
                new Effect.Morph(parent_div, {
                  style: 'height:200px;top:-150px;', // CSS Properties
                  duration: duration, // Core Effect properties
                  transition:transition,
                  afterFinish: function() {
                	 if(parent_div.down("input")) {
                		 parent_div.down("input").focus();
                     }
                 }
                });
                
                 header = parent_div.id;
                
            }
           // Hintergrundbilder
           $$('#header div.header_box').invoke('hide');
           
            new Effect.Appear(header + "_header", {
                duration: duration * 1.5,
                afterFinish: function() {
                    if(Prototype.Browser.IE) {
                        $$("#" + header + "_header div.header_box").invoke('show');
                    }
                }
            });
            if(! Prototype.Browser.IE) {
                if($(header + "_header").down("div.header_box")) {
                    new Effect.Appear($(header + "_header").down("div.header_box"), {
                    duration: duration * 1.5
                    });
                }
            }
            
            $$("#header >div.header_box").invoke("hide");
             $$("#header >div").each(function(div) {
                if(div != $(header + "_header")) {
                    new Effect.Fade(div, {duration: duration  * 1.5, transition:transition});
                }
            });
        }
        
        // Portrait:
        if($('klw_station_map_container')) {
        	// Link "Vereinbaren Sie einen Beratungsermin"
        	$('consultation_hint_button').observe("click", function(event) {
        		event.stop();
        		Effect.Appear('contact_drive_container', {duration:duration, transition:transition});
        		Effect.ScrollTo('klw_contact_button');
        	});
        	// Buttons zum Anzeigen 7 Verstecken der YellowMap-Karte
        	$('klw_driver', 'klw_undriver').invoke("observe", "click", function(event) {
        		event.stop();
        		$('klw_station_map_container').toggle();
        		if(this.name && ! $('station_map').src) {
        			$('station_map').src = this.name;
        		}
        	})
        	
        	$('klw_contact_button').setStyle({cursor:"pointer"});
        	$('contact_drive_container').hide();
        	$('klw_contact_button').observe("click", function(event) {
        		// Formular einblenden
        		Effect.toggle('contact_drive_container', 'blind', {duration:duration, transition:transition});
        	});
        } // end if
        
        if($('tx_konosdk_pi19_city')) {
        	if(!$F('tx_konosdk_pi19_city')) {
        		$('tx_konosdk_pi19_city').value = 'PLZ oder Ort';
        	}
        	$('tx_konosdk_pi19_city').observe("click", clear_field);
        	$('tx_konosdk_pi19_city').observe("keyup", clear_field);
        }
        
        
        if($('lerncheck')) {
			// label-for simulieren in Tabellenzellen
			$('lerncheck').observe("click", function(event) {
				if(event.target.tagName.toLowerCase() == 'td') {
					var td = $(event.target);
					if(td) {
						td.down("input").checked = true;
					}
				}
			});
		}
        
    });
    
     function clear_field(event) {
        var imp = '';
        if(event.type == 'keyup') {
            imp = String.fromCharCode(event.which ? event.which : event.keyCode);
        }
       
    	if (this.getAttribute("type") != 'submit'
    			&& this.getAttribute("type") != 'button') {
    		this.setValue(imp);
    	}
    	this.stopObserving('click', clear_field);
    	this.stopObserving('keyup', clear_field);
    	this.setStyle({color:'#333'});
    }
    
     
     function check_required(event) {
    		event.stop();
    		if ($('required_hint')) {
    			$('required_hint').removeClassName('error');
    		}

    		var inputs = this
    				.select('input.required')
    				.map( function(input) {
    					input.removeClassName('error');
    					// console.info(input.id);
    						input.up().down("label[for='" + input.id + "']")
    								.removeClassName('error');
    						if (input.getAttribute('type') == 'radio') {
    							var id = input.id.substr(0, input.id.length - 2);
    							if ($(id)) {
    								$(id).removeClassName('error');
    							}
    							// console.info($A(document.getElementsByName(input.name)).find(function(i)
    							// {return i.checked}));
    							if (!$A(document.getElementsByName(input.name)).find(
    									function(i) {
    										return i.checked
    									})) {
    								return input;
    							}

    							return;
    						}
    						var value = $F(input);
    						if (!value) {
    							return input;
    						}

    						if (input.hasClassName("email")) {
    							emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
    							if (!emailpat.test(value)) {
    								return input;
    							}
    						}

    					});
    		inputs = inputs.compact();
    		// // console.info(inputs);
    		if (inputs.length > 0) {

    			if ($('required_hint')) {
    				$('required_hint').addClassName('error');
    			}
    			inputs.each( function(input) {
    				input.addClassName('error');
//    				new Effect.Highlight(input.up().down("label[for='" + input.id + "']").addClassName(
//    						'error'), {startcolor:'#ff0000', endcolor:'#FF7E14', restorecolor:'#FF7E14'});
    				if (input.getAttribute('type') == 'radio') {
    					var id = input.id.substr(0, input.id.length - 2);
    					if ($(id)) {
    						$(id).addClassName('error');
    					}
    				}
    			});
    			// console.info("Fehler");
    		} else {
    			this.submit();
    		}
    	}

    
