$(document).ready(function(){

	// Navigation *********************************************************
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
    $("ul.topnav li a") .mouseover(function() { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
        $(this).parent().hover(function() {
        }, function(){  
            $(this).parent().find("ul.subnav").slideUp('medium'); //When the mouse hovers out of the subnav, move it back up
        });
        //Following events are applied to the trigger (Hover events for the trigger)
        }).hover(function() { 
            $(this).addClass("subhover"); //On hover over, add class "subhover"
        }, function(){  //On Hover Out
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });

	// Accordion *********************************************************
	if ( document.getElementById("contentAccordion") ){
		$("#contentAccordion").accordion();
		$("#contentAccordion").accordion({ clearStyle: true }); // damit gleich beim ersten mal Content immer nur so hoch wie nötig
		$("#contentAccordion").accordion({ autoHeight: false }); // damit Content immer nur so hoch wie nötig
		$("#contentAccordion").accordion({ collapsible: true }); // damit sind alle Contents schließbar
		$("#contentAccordion").accordion( "option", "active", 0 ); // damit ist kein Content am Anfang geöffnet
		$("#contentAccordion").click(function() { $(".accordion_toggle").blur(); }); // verhindert, dass ein Element bei Auswahl mit einer Box markiert wird
	}
	if ( document.getElementById("neuwagenAccordion") ){
		$("#neuwagenAccordion").accordion();
		$("#neuwagenAccordion").accordion({ clearStyle: true }); // damit gleich beim ersten mal Content immer nur so hoch wie nötig
		$("#neuwagenAccordion").accordion({ autoHeight: false }); // damit Content immer nur so hoch wie nötig
		$("#neuwagenAccordion").accordion({ collapsible: true }); // damit sind alle Contents schließbar
		$("#neuwagenAccordion").accordion( "option", "active", 0 ); // damit ist kein Content am Anfang geöffnet
		$("#neuwagenAccordion").click(function() { $(".accordion_toggle").blur(); }); // verhindert, dass ein Element bei Auswahl mit einer Box markiert wird
		$(".accordion_toggle").blur(); // verhindert, dass das erste Element am Anfang selektiert ist
	}
	
	// Accordion *********************************************************
	$('p.Klapper').next().hide(); // Alle Klapper Bereiche anfangs schließen
	$('p.Klapper').next().css('margin', '0 7px 0 7px'); // Alle Elemente direkt nach Klapper einrücken
	$('p.Klapper').click(function(){
		if( $(this).next().css('display') == 'none' ){
			$(this).css('background-image', 'url(images/arrow-up-grey.png)');
		}else{
			$(this).css('background-image', 'url(images/arrow-down-grey.png)');
		}
		$(this).next().slideToggle();
	});
	
	// GoogleMaps *********************************************************
	if( $(".googleMap").length>0 ){
		$(".googleMap").fancybox({ 
			'width'				: 600,
			'height'			: 400,
			'autoScale'     	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
	}
	if( $("#googleMap_koelbl").length>0 ){
		$("#googleMap_koelbl").fancybox({ 
			'width'				: 600,
			'height'			: 400,
			'autoScale'     	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
	}
	if( $("#googleMap_westend").length>0 ){
		$("#googleMap_westend").fancybox({ 
			'width'				: 600,
			'height'			: 400,
			'autoScale'     	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
	}
	if( $("#googleMap_riedel").length>0 ){
		$("#googleMap_riedel").fancybox({ 
			'width'				: 600,
			'height'			: 400,
			'autoScale'     	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
	}
	
});
	
