var numImg = 6;
var countImg = numImg -1;
var currentImg = 1;
var currentIndex = 0;
var nextImg = 2;
var fadeImg = false;
var jsondata = "";


var srcImg = "";
var counterImg = 0;
var nextsrcImg = "";
var numgalImg = 0;
var pfadImg = "";
			
			// Bildwechsel
			function changeImage(){
			
				if(fadeImg == false){
						$("#img1").fadeOut("slow", function() {
								fadeImg = true;
								if (currentImg >= countImg){
										currentImg = 1;
										$(this).attr('src', 'images/slideshow/slide0'+   currentImg +'.jpg');
										$('.teaserBox h3').html(jsondata.headlines[countImg]);
										$('.teaserBox p').text(jsondata.text[countImg]);
										$('.teaserBox a').attr('href' , jsondata.url[countImg]);
										Cufon.replace('.teaserBox h3',{color: '#ffffff',textShadow: '1px 1px #916932'});
								}else{
										currentImg = currentImg +2;
										currentIndex = currentImg -2;
										$(this).attr('src', 'images/slideshow/slide0'+   currentImg +'.jpg');
										$('.teaserBox h3').html(jsondata.headlines[currentIndex]);
										$('.teaserBox p').text(jsondata.text[currentIndex]);
										$('.teaserBox a').attr('href' , jsondata.url[currentIndex]);
										Cufon.replace('.teaserBox h3',{color: '#ffffff',textShadow: '1px 1px #916932'});
								}
								
						});
				}else{
						$("#img1").fadeIn("slow", function() {
								fadeImg = false;
								if (nextImg >= numImg){
										nextImg = 2;
										$("#img2").attr('src', 'images/slideshow/slide0'+ nextImg +'.jpg');
										$('.teaserBox h3').html(jsondata.headlines[0]);
										$('.teaserBox p').text(jsondata.text[0]);
										$('.teaserBox a').attr('href' , jsondata.url[0]);
										Cufon.replace('.teaserBox h3',{color: '#ffffff',textShadow: '1px 1px #916932'});
								}else{
										nextImg = nextImg + 2;
										currentIndex = nextImg -2;
									    $("#img2").attr('src', 'images/slideshow/slide0'+ nextImg +'.jpg');
										$('.teaserBox h3').html(jsondata.headlines[currentIndex]);
										$('.teaserBox p').text(jsondata.text[currentIndex]);
										$('.teaserBox a').attr('href' , jsondata.url[currentIndex]);
										Cufon.replace('.teaserBox h3',{color: '#ffffff',textShadow: '1px 1px #916932'});
								}
						});
				
				}
			
				
								
			}
			
			
			
			
var imgInterval = window.setInterval("changeImage();",4000);


$(document).ready(function() {
				
				  // Json-Data laden und in var speichern
				  $.getJSON("js/slideshow.json",
					function(data){
					  jsondata = data;
				  });
				  
				  //Fachberater anzeigen
				  $('.fachberater').hover(function() {
					 $('.infobox').stop(true, true);
 					 $('.infoBox').not(":animated").slideDown('slow');
					}, function(){
						$('.infoBox').not(":animated").slideUp('slow');
					});
				  
				  //Fachberater anzeigen _ Neu
					$('.fachberaterBox').hover(function(){
						$('.fachberaterBoxInfo').stop(true, true)
						$('.fachberaterBoxInfo').slideToggle(400);
					});
				  
				  //FensterInfo anzeigen
				  $('.l01').click(function() {
 					 $('.infoBox2').not(":animated").slideToggle('slow');
					 $('.infoBox, .infoBox3, .infoBox4, .infoBox5').slideUp('slow');
					 return false;
					});
				  
				  //FensterInfo anzeigen
				  $('.l02').click(function() {
 					 $('.infoBox3').not(":animated").slideToggle('slow');
					 $('.infoBox, .infoBox2, .infoBox4, .infoBox5').slideUp('slow');
					 return false;
					});
				  
				   //FensterInfo anzeigen
				  $('.l03').click(function() {
 					 $('.infoBox4').not(":animated").slideToggle('slow');
					 $('.infoBox, .infoBox2, .infoBox3, .infoBox5').slideUp('slow');
					 return false;
					});
				  
				   //FensterInfo anzeigen
				  $('.l04').click(function() {
 					 $('.infoBox5').not(":animated").slideToggle('slow');
					 $('.infoBox, .infoBox2, .infoBox3, .infoBox4').slideUp('slow');
					 return false;
					});
				  				  
				  
				  //Notdienst-Karte anzeigen
				  $('.contentMain .notdienst').click(function() {
 					 $('.karte').not(":animated").slideToggle('slow');
					 return false;
					});
				  
				  // Galerie
				  
				  numgalImg = $('.gal img').size();
				  
				  
				  $('.gal img').click(function() {
					 srcImg = $(this).attr('id');
					 blub =  $(this).attr('src');
					 var laenge = srcImg.length;
					 var laenge2 = blub.length;
					 var teil = laenge- 1;
					 counterImg=  srcImg.substring(teil, laenge);
					 speicher =  blub.substring(7, laenge2);					 
					 pfadImg =  speicher.substring(0, speicher.length - 8);


					 $('.anzeige img').attr('src', 'images/'+  pfadImg  +'pic' + srcImg + '.jpg');
 					 $('.anzeige').not(":animated").slideDown('slow');
					 return false;
					});
				  
				$('.anzeige .close').click(function() {
 					 $('.anzeige').not(":animated").slideUp('slow');
					 return false;
					});
				
				$('.anzeige .next').click(function() {
					if(counterImg >= numgalImg){							   
							counterImg = 0;
					}
					nextsrcImg = parseInt(counterImg) + 1;
					$('.anzeige img').attr('src', 'images/'+  pfadImg  +'picBig' + nextsrcImg + '.jpg');
					counterImg++;
					return false;
						
					});
				
				$('.anzeige .prev').click(function() {
					if(counterImg <= 1){							   
							counterImg = numgalImg +1;
					}
					nextsrcImg = parseInt(counterImg) - 1;
					$('.anzeige img').attr('src', 'images/'+  pfadImg  +'picBig' + nextsrcImg + '.jpg');
					counterImg--;
					return false;
						
					});

});

