/*
 *
 * Requires jQuery!
 *
 */
 
// Headerimage Crossfader: start with 2 (1 allready displayed)
imgID = 2;
var host = 'http://senioreninfo-magazin.de';

$(document).ready(function()
{
	//create image to be cross-faded in html container
	$('.headerimage').append('<img src="'+host+'/img/headers/2.png" style="z-index:0;position:absolute;top:0;left:0;" alt="imagebild"/>');
	
	img2switch = 0;
  imgLoaded = 1;
  switchDuration = 5000;
  
	//change image all 10 seconds
	setInterval('HeaderSwitch()',switchDuration);
  
 });

function HeaderSwitch() 
{
  // skip switch if image to be shown hasn't loaded yet
  if (imgLoaded == 1)
  {
    if (imgID > 2) imgID = 0;
    // fade out currently shown image
    $('.headerimage img:eq('+img2switch+')').animate({opacity:0}, 2000, function(){
      
      // set the z-index of the now to be shown image to 1
      
      
      imgLoaded = 0;

      // put the image behind the second one and set to display again, then change the source to the next image
      $(this).attr({src:imgSet[imgID]}).load(function(){
        imgLoaded = 1;
        $('.headerimage img').not(this).css({'z-index':1});
        $(this).css({'z-index':0, opacity:1});
        
      });

      // switch which image is to be shown next
      img2switch = img2switch == 0 ? 1 : 0;
      imgID++;
    });
  }
}

// array of images to be switched through (-> read in folder or set of images and write to cdata)
var imgSet = new Array();
imgSet = {'0':''+host+'/img/headers/1.png',
          '1':''+host+'/img/headers/2.png',
          '2':''+host+'/img/headers/3.png'
          };
