var slideShow1;
var slideShow2;
var slideShow3;

  function AsyncLoadPage( destinationDivId, url, changeLoc){
  	$('#'+destinationDivId).load( url, { 'ajax': 'true' }, function(response, status, xhr){
      if (status == "error") {
        var msg = "Sorry but there was an error: ";
        $('#'+destinationDivId).html(msg + xhr.status + " " + xhr.statusText);
      } else {
        if (changeLoc)
          window.location.hash = urlArgs;
      }        
    });
  }

function AsyncPageLoader() {

  var asyncLinkClass;
  var destinationDivId;
  var loadContentUrl;
  var destinationLoadingDivId;
  var defaultAnimation = false; 
  
  var innerAsyncLinkClass;
  var innerDestinationDivId;
  var innerLoadContentUrl; 

  var innerLightboxDivId;
  var innerLightboxCss;
  
  this.initialize = initialize;
  this.setAsyncLink = setAsyncLink;
  this.setInnerAsyncLink = setInnerAsyncLink;
  this.setInnerLightbox = setInnerLightbox;
  this.setAnimation = setAnimation;
  
  function setAsyncLink(pAsyncLinkClass, pDestinationDivId, pLoadContentUrl) {
    asyncLinkClass = pAsyncLinkClass; 
    destinationDivId = pDestinationDivId; 
    loadContentUrl = pLoadContentUrl;     
  }
   
  function setInnerAsyncLink(pInnerAsyncLinkClass, pInnerDestinationDivId, pInnerLoadContentUrl) {
    innerAsyncLinkClass = pInnerAsyncLinkClass;
    innerDestinationDivId = pInnerDestinationDivId;
    innerLoadContentUrl = pInnerLoadContentUrl;        
  } 
  
  function setInnerLightbox(pInnerLightboxDivId, pInnerLightboxCss) {
    innerLightboxDivId = pInnerLightboxDivId;
    innerLightboxCss = pInnerLightboxCss;
  } 
  
  function setAnimation(pAnimation, pDestinationLoadingDivId) {
    defaultAnimation = pAnimation;
    destinationLoadingDivId = pDestinationLoadingDivId;
  }
  
  function initialize() {
  	$(asyncLinkClass).click( function( event ) {
  		set_ajax_link( $(this), event, defaultAnimation, true);
  	});
    // check if the picture div is opened already
    var content = $('#'+destinationDivId).length;
    if ($('#'+destinationDivId).length == 0) {
      var args;
      var currentHash = document.location.hash;  
      //if there is not anchor, open default site
      if(currentHash.length = 0) {
        args = '?';
      } else {
  		  //Creates the  string callback. This converts the url URL/#a=b&c=d in URL/?a=b&c=d
  	   	var args = currentHash.substring(1)
      }
      if (args != null && args != '')
  		  load_page( args, false, false);
  	}
  }

  function set_ajax_link( el, event, animation, changeLoc){
  	event.preventDefault();
  	var urlArgs = el.attr('href');
  	load_page( urlArgs, animation, changeLoc);
  }
  
  function load_page( urlArgs, animation, changeLoc){
  	if (animation) {
  		$('#'+destinationDivId).hide('fast',loadContent);
  	  $('#'+destinationLoadingDivId).remove();
//  	  $('#'+destinationContentDivId).append('<span id="load">&nbsp;LOADING...</span>');
  	  $('#'+destinationLoadingDivId).fadeIn('normal');
  	} else {
  		loadContent();
  	}

    function loadContent() {
      var url = '';
      if (loadContentUrl != null)
        url = loadContentUrl;
      if (urlArgs != null)
        url += urlArgs;
    	$('#'+destinationDivId).load( url, { 'ajax': 'true' }, function(response, status, xhr){
        if (status == "error") {
          var msg = "Sorry but there was an error: ";
          $('#'+destinationDivId).html(msg + xhr.status + " " + xhr.statusText);
        } else {
          if (innerAsyncLinkClass != null) {
        		$('#'+destinationDivId+' '+innerAsyncLinkClass).click( function( event ) {
        			set_ajax_link( $(this), event, animation, false);
        		});
          }
          if (innerLightboxDivId != null && innerLightboxCss != null) {  
      		  $('#'+innerLightboxDivId+' '+innerLightboxCss).lightBox();
          }
          if (animation) 
            showNewContent();
          if (changeLoc)
            window.location.hash = urlArgs;
        }        
      });
    }

    function showNewContent() {
      $('#'+destinationDivId).show('normal',hideLoader());
    }
    
    function hideLoader() {
      $('#'+destinationLoadingDivId).fadeOut('normal');
    }
  	
  }
  
}

function AsyncPictureLoader() {

  var pictureClass;
  var pictureDivId;
  var pictureContentDivId;
  var pictureListDivId;
  var pictureLoadingDivId;
  var loadContentUrl;
  var slideShowDelay = 0;
  var slideShowVariableName;
  var defaultAnimation = false; 
  
  var thumbInactive = 'images/blau.gif';
  var thumbActive = 'images/grau.gif';
  var thumbActiveHref = null;
  var thumbActiveImage = null;
  
  var theTime;
  var slideSwitchActive = false;

  this.initialize = initialize;
  this.setPictureDiv = setPictureDiv;
  this.setThumnails = setThumnails;
  this.addThumnail = addThumnail;
  this.setAutoSlideShow = setAutoSlideShow;
  this.startSlideSwitching = startSlideSwitching;
  this.stopSlideSwitching = stopSlideSwitching;
  this.slideSwitch = slideSwitch;
  this.setAnimation = setAnimation;
  
  function setPictureDiv(pPictureContainerDivId, pPictureContentDivId, pPictureListDivId, pPictureLoadingDivId, pLoadContentUrl) {
    pictureDivId = pPictureContainerDivId;
    pictureContentDivId = pPictureContentDivId;
    pictureListDivId = pPictureListDivId; 
    pictureLoadingDivId = pPictureLoadingDivId;
    loadContentUrl = pLoadContentUrl;
  }
  
  function setThumnails(pPictureClass, pThumbInactive, pThumbActive) {
    pictureClass = pPictureClass; 
    thumbInactive = pThumbInactive;
    thumbActive = pThumbActive;
  }
  
  function addThumnail(pHref, pImage) {
    if (thumbActiveHref == null) {
      thumbActiveHref = new Array();
      thumbActiveImage = new Array();
    }
    thumbActiveHref[thumbActiveHref.length] = pHref; 
    thumbActiveImage[thumbActiveImage.length] = pImage;
  }
  
  function setAnimation(pAnimation) {
    defaultAnimation = pAnimation;
  }
  
  function setAutoSlideShow(pDelay, pAsyncPictureLoaderVariable) {
    slideShowDelay = pDelay;
    slideShowVariableName = pAsyncPictureLoaderVariable;     
  }
   
  function initialize() {
    $(pictureClass).click( function( event ) {
      set_ajax_link( $(this), event, defaultAnimation, false, true );
    });
    // check if the picture div is opened already
    var content = $('#'+pictureDivId).length;
    if ($('#'+pictureDivId).length == 0) {
      var args;
      var currentHash = document.location.hash;  
      //if there is not anchor, open default site
      if(currentHash.length = 0) {
        args = '?';
      } else {
  		  //Creates the  string callback. This converts the url URL/#a=b&c=d in URL/?a=b&c=d
  	   	var args = currentHash.substring(1)
      }
      if (args != null && args != '')
  		  load_page( args, true, false, true);
  	}
    if (slideShowVariableName != null) {
      $(function() {
        theTime = setInterval( slideShowVariableName+'.slideSwitch()', slideShowDelay );
      });
    }
  }

  function set_ajax_link( el, event, animation, stopSlideshow, changeLoc ){
    event.preventDefault();
    var urlArgs = el.attr("href");
    load_page( urlArgs, animation, stopSlideshow, changeLoc);
  }
  
  function load_page( urlArgs, animation, stopSlideshow, changeLoc){
  	if (animation) {
  		$('#'+pictureDivId).hide('fast',loadContent);
  	  $('#'+pictureLoadingDivId).remove();
  	  $('#'+pictureContentDivId).append('<span id="load">&nbsp;LOADING...</span>');
  	  $('#'+pictureLoadingDivId).fadeIn('normal');
  	} else {
  		loadContent();
  	}
  	if (stopSlideshow){
  	  stopSlideSwitching();
  	} else if (!slideSwitchActive) {
  		startSlideSwitching();
  	}
  	
    function loadContent() {
      var url = '';
      if (loadContentUrl != null)
        url = loadContentUrl;
      if (urlArgs != null)
        url += urlArgs; 
  		$('#'+pictureDivId).load( url, { 'ajax': 'true' }, function(response, status, xhr){
        if (status == "error") {
          var msg = "Sorry but there was an error: ";
          $('#'+destinationDivId).html(msg + xhr.status + " " + xhr.statusText);
        } else {
    			$('#'+pictureDivId+' '+pictureClass).click( function( event ) {
    				set_ajax_link( $(this), event, set_ajax_link, true, false );
    			});
    			var test = $('#'+pictureDivId+' '+pictureClass);
    			if (animation) {
    				showNewContent();
    			}
        }
        if (changeLoc) {
  			 window.location.hash = urlArgs;
        }
  		});
  	}
  	
    function showNewContent() {
      $('#'+pictureDivId).show('normal',hideLoader());
    }
    
    function hideLoader() {
      $('#'+pictureLoadingDivId).fadeOut('normal');
    }
  	
  }
  
  function slideSwitch() {
  	if (slideSwitchActive) {
      var $active = $('#'+pictureContentDivId+' .activePicture');
      if ( $active.length == 0 ) $active = $('#'+pictureContentDivId+' DIV:last');
  
      var $next =  $active.next().length ? $active.next()
          : $('#'+pictureContentDivId+' DIV:first');
  
      var $pictureList = $('#'+pictureListDivId+' a');
      if ($pictureList.length <= 1)
          return;
  
      $active.addClass('lastActivePicture');
      $next.css({opacity: 0.0})
          .addClass('activePicture')
          .animate({opacity: 1.0}, 1000, function() {
              $active.removeClass('activePicture lastActivePicture');
          });
  
  //    $next.addClass('activePicture');
      $active.removeClass('activePicture');
      $active.removeClass('lastActivePicture');
      $active.addClass('inactivePicture');
      $next.removeClass('inactivePicture');
  
      $active = $('#'+pictureListDivId+' a.activeThumb');
      if ( $active.length == 0 ) $active = $('#'+pictureListDivId+' a:last');
  
      var $next =  $active.next().length ? $active.next()
          : $('#'+pictureListDivId+' a:first');
  
      $('#'+pictureListDivId+' a.activeThumb img').attr('src',thumbInactive);
  
      $active.addClass('inactiveThumb');
      $active.removeClass('activeThumb');
  
      $next.addClass('activeThumb');
      $next.removeClass('inactiveThumb');
      
      var actThumbImage;
      if (thumbActiveHref != null) {
        var pHref = $('#'+pictureListDivId+' a.activeThumb').attr('href');
        for(i=0;i<thumbActiveHref.length;i++){
          if (thumbActiveHref[i] == pHref) {
            actThumbImage = thumbActiveImage[i];
          } 
        }
      }
      if (actThumbImage == null)
        actThumbImage = thumbActive; 
      $('#'+pictureListDivId+' a.activeThumb img').attr('src',actThumbImage);
  	}
  }
  
  function startSlideSwitching() {
  	 slideSwitchActive = true;
  }
  
  function stopSlideSwitching() {
  	 slideSwitchActive = false;
  }  
}


