$(document).ready(function(){
	// Bilder-Preload:
	
	var preLoadImages = function(imageList, callback) {
		var count = 0;
		var loading = false;
		var loadNext = function(){
			if(!loading){
				loading = true;
				count++;
				pic = new Image();
				pic.onload = function(){
					loading = false;
					if(count >= imageList.length-1){
							clearInterval(loadInterval);
							callback();
					}
				}
				pic.src = imageList[count];
			}
		}
		var loadInterval = window.setInterval(loadNext, 50);
	};

	var files = [
		'images/bg_main.jpg', 
		'images/frame_leftright_florals_y2700.png', 
		'images/frame_leftright.png', 
		'images/topnavigation_icons.png', 
		'images/navigation_bg.png', 
		'images/navigation.png', 
		'images/headlines.png', 
		'images/subnavigation_blase_90.png', 
		'images/subnavigation.png', 
		'images/animation0.jpg', 
		'images/animation1.jpg', 
		'images/animation2.jpg', 
		'images/animation3.jpg', 
		'images/animation4.jpg', 
		'images/animation5.jpg', 
		'images/animation6.jpg', 
		'images/animation7.jpg', 
		'images/logo_seniorenheim_jeberjahn_betriebs_gmbh.png', 
		'images/sub_ausbildung.png', 
		'images/sub_ausbildung_hov.png', 
		'images/sub_gaestebuch.png', 
		'images/sub_gaestebuch_hov.png', 
		'images/sub_galerie.png', 
		'images/sub_galerie_hov.png', 
		'images/sub_hausrundgang.png', 
		'images/sub_hausrundgang_hov.png', 
		'images/sub_impressum.png', 
		'images/sub_impressum_hov.png', 
		'images/sub_kontakt.png', 
		'images/sub_kontakt_hov.png', 
		'images/sub_pflegeleitbild.png', 
		'images/sub_pflegeleitbild_hov.png', 
		'images/sub_qualitaetssicherung.png', 
		'images/sub_qualitaetssicherung_hov.png', 
		'images/sub_start.png', 
		'images/sub_start_hov.png', 
		'images/sub_stellenangebote.png', 
		'images/sub_stellenangebote_hov.png', 
		'images/sub_ueber_uns.png', 
		'images/sub_ueber_uns_hov.png', 
		'images/sub_unsere_leistungen.png', 
		'images/sub_unsere_leistungen_hov.png'
	];

	preLoadImages(files, function(){ 
		// Let's Rock! ;-)
	});

		// --------------------------------------------------------------------------------------------------------------------------
		// Navigation alle Seiten:
		// --------------------------------------------------------------------------------------------------------------------------
		$("#Navi_Start").mouseover(function () {
				$("#nav_ueberuns").slideUp("fast");
				$("#nav_galerie").slideUp("fast");
				$("#nav_joebboerse").slideUp("fast");
				$("#nav_kontakt").slideUp("fast");
		});
		$("#Navi_UeberUns").mouseover(function () {
				$("#nav_ueberuns").slideDown("fast");
				$("#nav_galerie").slideUp("fast");
				$("#nav_joebboerse").slideUp("fast");
				$("#nav_kontakt").slideUp("fast");
		});
		$("#Navi_Galerie").mouseover(function () {
				$("#nav_ueberuns").slideUp("fast");
				$("#nav_galerie").slideDown("fast");
				$("#nav_joebboerse").slideUp("fast");
				$("#nav_kontakt").slideUp("fast");
		});	
		$("#Navi_Jobboerse").mouseover(function () {
				$("#nav_ueberuns").slideUp("fast");
				$("#nav_galerie").slideUp("fast");
				$("#nav_joebboerse").slideDown("fast");
				$("#nav_kontakt").slideUp("fast");
		});	
		$("#Navi_Kontakt").mouseover(function () {
				$("#nav_ueberuns").slideUp("fast");
				$("#nav_galerie").slideUp("fast");
				$("#nav_joebboerse").slideUp("fast");
				$("#nav_kontakt").slideDown("fast");
		});	

		// * Menü zuklappen:
		$("#content").mouseover(function () {
				$("#nav_ueberuns").slideUp("fast");
				$("#nav_galerie").slideUp("fast");
				$("#nav_joebboerse").slideUp("fast");
				$("#nav_kontakt").slideUp("fast");
		});	
		$("#contentssss").mouseover(function () {
				$("#nav_ueberuns").slideUp("fast");
				$("#nav_galerie").slideUp("fast");
				$("#nav_joebboerse").slideUp("fast");
				$("#nav_kontakt").slideUp("fast");
		});	
		
	

		// --------------------------------------------------------------------------------------------------------------------------
		// Alle Seiten: Input-Felder
		// --------------------------------------------------------------------------------------------------------------------------
		$("input").focus(function() {
			$(this).css("background-color","#f3ebd2");

		});

		$("input").blur(function() {
			$(this).css("background-color","#fff");

		});

		$("textarea").focus(function() {
			$(this).css("background-color","#f3ebd2");

		});

		$("textarea").blur(function() {
			$(this).css("background-color","#fff");

		});



		// --------------------------------------------------------------------------------------------------------------------------
		// Seite: Pflegekonzept und Seite Vollstationäre Pflege
		// --------------------------------------------------------------------------------------------------------------------------
		$("a#toggleHideShow_4").toggle(function(){ 				/* 2 Effekte hintereinander via toggle */
				$("#HideShow_4").animate({ height: 'show'}, 'slow');
			},function(){
				$("#HideShow_4").animate({ height: 'hide'}, 'slow');
		})



		// --------------------------------------------------------------------------------------------------------------------------
		// Alle Seiten mit Slideshow:
		// --------------------------------------------------------------------------------------------------------------------------
		// $.easing.def = "easeOutBounce";

		$('.slideshow').cycle({
			fx: 'fade' // transitionen: fade, scrollUp, shuffle, etc...
		});

		$('.slideshow_2').cycle({
			fx: 'zoom' // transitionen: fade, scrollUp, shuffle, etc...
		});
		
		$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});

		

		// --------------------------------------------------------------------------------------------------------------------------
		// Seite: Hausrundgang
		// --------------------------------------------------------------------------------------------------------------------------
		$("#hotspot1_1").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/saw20.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_2").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/saw6.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_3").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/w6.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_4").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/w3.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_5").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/w2.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_6").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/w4.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_7").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/s4.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_8").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/s3.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_9").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/s1.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_10").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/s2.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot1_11").click(function(){$("#tourbild_1").animate({"opacity":"0"},250,function(){$("#tourbild_1").attr("src","images/hausrundgang/w1.jpg").animate({"opacity":"1"},500)})});

		$("#hotspot2_1").click(function(){$("#tourbild_2").animate({"opacity":"0"},250,function(){$("#tourbild_2").attr("src","images/hausrundgang/s7.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot2_2").click(function(){$("#tourbild_2").animate({"opacity":"0"},250,function(){$("#tourbild_2").attr("src","images/hausrundgang/s6.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot2_3").click(function(){$("#tourbild_2").animate({"opacity":"0"},250,function(){$("#tourbild_2").attr("src","images/hausrundgang/s5.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot2_4").click(function(){$("#tourbild_2").animate({"opacity":"0"},250,function(){$("#tourbild_2").attr("src","images/hausrundgang/w7.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot2_5").click(function(){$("#tourbild_2").animate({"opacity":"0"},250,function(){$("#tourbild_2").attr("src","images/hausrundgang/w8.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot2_6").click(function(){$("#tourbild_2").animate({"opacity":"0"},250,function(){$("#tourbild_2").attr("src","images/hausrundgang/saw26.jpg").animate({"opacity":"1"},500)})});

		$("#hotspot3_1").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/saw28.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot3_2").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/saw27.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot3_3").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/s8.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot3_4").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/s7.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot3_5").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/saw30.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot3_6").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/s10.jpg").animate({"opacity":"1"},500)})});
		$("#hotspot3_7").click(function(){$("#tourbild_3").animate({"opacity":"0"},250,function(){$("#tourbild_3").attr("src","images/hausrundgang/saw29.jpg").animate({"opacity":"1"},500)})});


		// --------------------------------------------------------------------------------------------------------------------------
		// Seite: Galerie
		// --------------------------------------------------------------------------------------------------------------------------
		$(".scrollable").scrollable();

		$(".items img").click(function() {
		
			// see if same thumb is being clicked
			if ($(this).hasClass("active")) { return; }
		
			// calclulate large image's URL based on the thumbnail URL (flickr specific)
			var url = $(this).attr("src").replace("_t", "");
		
			// get handle to element that wraps the image and make it semitransparent
			var wrap = $("#image_wrap").fadeTo("medium", 0.5);
		
			// the large image from flickr
			var img = new Image();
		
			// call this function after it's loaded
			img.onload = function() {
		
				// make wrapper fully visible
				wrap.fadeTo("fast", 1);
		
				// change the image
				wrap.find("img").attr("src", url);
		
			};
		
			// begin loading the image from flickr
			img.src = url;
		
			// activate item
			$(".items img").removeClass("active");
			$(this).addClass("active");

	// when page loads simulate a "click" on the first image
		}).filter(":first").click();
		
		
	});

