$(function(){	
	$("ul.zebra-list li:odd").addClass("odd");	
	$('a.text-increase').click(function(){
		$('a.text-decrease').removeClass('active');
		$('a.text-increase').addClass('active');		
		$('body').addClass("text-increased");
		var today = new Date();
		today.setTime( today.getTime() );
		var expires_date = new Date( today.getTime() + (1000) );

		document.cookie = "font-size=large;";
		return false;
	})
	$('a.text-decrease').click(function(){
		$('a.text-increase').removeClass('active');
		$('a.text-decrease').addClass('active');
		$('body').removeClass("text-increased");
		var today = new Date();
		today.setTime( today.getTime() );
		var expires_date = new Date( today.getTime() + (1000) );

		document.cookie = "font-size=small;";
		return false;
	})
	$('a.text-contrast').click(function(){
		//toggle contrast
		if(!$('body').hasClass('text-contrasted')){
			$('.text-contrast').addClass("active");
			$('head').append('<link rel="stylesheet" type="text/css" href="$file/contrast.dark.css" />');
			$('body').addClass("text-contrasted");
			var today = new Date();
			today.setTime( today.getTime() );
			var expires_date = new Date( today.getTime() + (1000) );

			document.cookie = "contrast=dark;"
		} else {
			$('.text-contrast').removeClass("active");			
			$('body').removeClass("text-contrasted");
			var today = new Date();
			today.setTime( today.getTime() );
			var expires_date = new Date( today.getTime() + (1000) );

			document.cookie = "contrast=light;";
		}
		return false;
	})
	
	if( $("div.row div.image a").length > 0 ) {
		$("div.row div.image a img").each( function() {
			var link = $(this).parent('a').attr('href');			
			$(this).parent('a').css({"position":"relative"}).removeAttr("href"); 			
			var html_link= $('<a rel="gal" class="fb_image" style="position:absolute;right:2px;bottom:4px;" href="'+link+'"></a>');
			$(this).after(html_link);
			html_link.fancybox();
		});
	}
	
	// verstecke leere .row Elemente
	
	if( $(".row").length > 0 ) {
		$(".row").each( function() {
			if( $.trim( $(this).html() ) == "" ) {
				$(this).hide();
			}
		});		
	}
	
	
	/*
	if( $(".enlargable").length > 0 ) {
		$('img.enlargable').each(function(){
			var width = $(this).innerWidth();
			var height = $(this).innerHeight();
			var pos = new Object();
			pos.x = - 16 - 4; 
			pos.y = height - 16 - 4;
			var link = $(this).parent('a').attr('href');			
			$(this).parent('a').css({"position":"relative"}).removeAttr("href"); 			
			var html_link= $('<a rel="gal" class="fb_image" style="position:absolute;right:2px;bottom:4px;" href="'+link+'"></a>');
			$(this).after(html_link);
			html_link.fancybox();
		});
	}
	*/
    
    if( $(".eq").length > 0 ) {
        var max_height = 0;
        $("div.eq").each(function(){
           if ($(this).height() > max_height) { max_height = $(this).height(); }
        });
        $("div.eq").height(max_height);
    }
	
	if( $(".fancybox").length > 0 ) {
		$(".fancybox").fancybox({			
			'titlePosition' 	: 'inside'		
		});
	}
	
	if( $(".image-slideshow").length > 0  ) {
		$('.image-slideshow').slideshow({
		  active_image_width: 980,
		  slide_speed: 1200,
		  inactive_image_opacity: 0.2,
		  on_slide_disable_navi: true,
		  auto_slide: true,
		  auto_slide_speed: 8000,
		  auto_slide_mode: 'loop',
		  pause_slide_on_hover: true }
	   );
	}
   
	/* form validation */
	if( $(".form-container").length > 0 ) {
		$("[name='_formular']").validate();
	}
	/* navi */
	$("#search_query").click(function(){
		if($(this).val()=="Suchbegriff...")
		$(this).val("");
	});
	$("#start_search").click(function(){
		var query = $('#search_query').val();
		var dbpath = $("#dbpath").val();
		document.location.href= dbpath + "results?SearchView&Query="+query+" AND [sprache]=de&SearchOrder=1&SearchMax=1000&SearchWV=FALSE&SearchThesaurus=TRUE&lang=de"; 
		return false;
	});
    $("#search_query").bind("keypress", function(e) {
        if (e.keyCode == 13) {
            var query = $('#search_query').val();
            var dbpath = $("#dbpath").val();
            document.location.href= dbpath + "results?SearchView&Query="+query+" AND [sprache]=de&SearchOrder=1&SearchMax=1000&SearchWV=FALSE&SearchThesaurus=TRUE&lang=de"; 
            return false;
        }
    });

    
    
    
	// Bürger ABC
	if( $("#buergerABC").length > 0 ) {
		$("#buergerABC").appendTo( $("#content") );
	}
	
	// Subnav
	$('ul#nav>li').mouseenter(function(){
				
		if($(this).find('ul.sub-nav:hidden').length > 0)
		{
			$('a.opened').removeClass('opened');
			$('ul.sub-nav:visible').fadeOut('fast');
			$(this).find('a').addClass('opened');
			$(this).find('ul.sub-nav').show();
		}
		else
		{
			$('a.opened').removeClass('opened');
			$('ul.sub-nav:visible').fadeOut('slow');
		}
	})
	$('ul.sub-nav').mouseleave(function(){
		$(this).fadeOut('slow');
		$('a.opened').removeClass('opened');
	})
    
    $('ul#nav').mouseleave(function(){
		$('ul.sub-nav:visible').fadeOut('slow');
	})

	
	$('table.zebra-list tr:odd').addClass("odd");		
});
