
var preloadImages = function(image_links, callback) {
  var self = this;
  // assume image_links is an array here
  var count = image_links.length;
  $.each( image_links, function(){
    $('<img/>', {
      'src': this, // url
      'load': function(){
        if( --count == 0 ) {
          callback.apply(self);
        }
      }
    });
  });
}


$(document).ready(function() {	
    $('#click_choose_language').click ( function ()
    {
            $(".wrapper_choose_language").toggle ();
    } );
    $('#click_choose_language_en').click ( function ()
    {
        $(".wrapper_choose_language").toggle ();
    });
    $("#mainMenu ul.menuLevel_0 li:last").addClass("very");
    if ($("#mainMenu li a.active").length)
    {
        if ($("#mainMenu li a.active").html()!= "Aktuelles" && $("#mainMenu li a.active").html() != "News")
        {
            $(".contentItem h1").first().html($("#mainMenu li a.active").html());
        }       
        //$(".wrapper_content_nav h4").html(
    }
    else if($("#hiddenPathInput").val()!="")
    {
        if ($("#hiddenPathInput").html()!= "Aktuelles" && $("#hiddenPathInput").html() != "News")
        {
            $(".contentItem h1").first().html($("#hiddenPathInput").val());
        }
    }

    $("a.button.top").click(function(e) {
        $("html, body").animate({scrollTop:0}, 500);
        e.preventDefault();
   });


    $(".wrapper_content_nav li").hover(function() {
       if (!$(this).hasClass("active"))
       {
            $(this).addClass("hover");
       }
    }, function() {
       if (!$(this).hasClass("active"))
       {
        $(this).removeClass("hover");
       }
    });

   if ($(".wrapper_content_nav.level_1").find("li.active").length==0)
   {       
        $(".wrapper_content_nav.level_1").find("li").first().addClass("active");
   }

   $(".wrapper_content_nav.level_1").find("ul").each(function() {
      if (!$(this).find("li").length)
      {
         $(this).remove();
      }
   });

});




var timer = 10; // Sekunden wann gewechselt werden soll
var count = 1;

function changeHeader() {
    var maxItems = $(".header_image").length;
    var prev = (count-1);

    if (count >= maxItems) {
            count = 0;
            prev = (maxItems-1);
    }

    if ( $(".header_image:eq(" + prev + ")").css("display") != "none" )
            $(".header_image:eq(" + prev + ")").fadeOut();

    $(".header_image:eq(" + count + ")").fadeIn();

    count++;
}

$(document).ready(function() {

    
    $("a[rel=fancybox]").fancybox({"type":"image", "titleShow":true,"showNavArrows":false,"enableArrowKeys":false});
	$("a[rel=infobox]").fancybox({"titleShow":false,"showNavArrows":false,"enableArrowKeys":false, "autoDimensions": false, width:680, height:500, "autoScale": true });

    //$("a.item")

    if ($(".header_image").length > 1)
    {
    	window.setInterval("changeHeader()", timer * 1000);
    }

    $(".wrapper_content_nav > li > .wrapper_content_nav.level_2").hide();
    $(".wrapper_content_nav > li.active > .wrapper_content_nav").show();
        
    $("#thumb").superbgimage().hide();
    $('#content').fadeTo('slow', 0.75);

	
});
function toggleSearchForm()
{
    $(".wrapper_search").toggleSlide(1000);
}


/*
$(function() {

	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		id: 'superbgimage', // id for the containter
		z_index: 0, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: 1, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 0, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 0, // 0-none, 1-show title
		slideshow: 0, // 0-none, 1-autostart slideshow
		slide_interval: 5000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 'slow', // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: superbgimage_show, // function-callback show image
		onClick: superbgimage_click, // function-callback click image
		onHide: superbgimage_hide, // function-callback hide image
		onMouseenter: superbgimage_mouseenter, // function-callback mouseenter
		onMouseleave: superbgimage_mouseleave, // function-callback mouseleave
		onMousemove: superbgimage_mousemove // function-callback mousemove
	};

	// initialize SuperBGImage
	$('#thumbs').superbgimage().hide();
$('#content').fadeTo('slow', 0.75);
});
*/
