  
  //Funktion um die Lightbox bei Klick auf ein Bild zu oeffnen
  $('a.open_ligthboxlink').click(function(event){
      event.preventDefault();
      var browserWindow = $('document').getPageSize();
      var browserWindowHeight = browserWindow[1];
      var browserWindowWidth = browserWindow[0];
      
      
      
      $('#lightBox .close').click();

      $("iframe, select, embed, object").hide();

      $('body').css('text-align','center');
      $('#wrapper').css({'z-index':'-1'});

      $('#lightBox a.step').click(function(){
          //$(this).attr('title');
      });
      /*
       * Zusammensuchen aller Bilder und füttern der pagination
       *
       */
       var actImage = $(this);
       var paginationBar = '';

       var imageTitle = $(this).attr('title');
       var imageDesc = $(this).children().attr('longdesc');
       
       var check = false;
       var paginationCount = 0;

       var images = '';
       var i = 1;
       $('.lightboxImage').each(function(){
          if($(this).parent())

          if($(this).attr('src')){
              var click = 'classClick'+i;

              images = images+'<img longdesc="'+$(this).attr('longdesc')+'"';
              var width = $(this).ak_giveImageSize();
              if(width > 0){
                images = images+' width="'+width+'"';
              }
              images = images+' src="'+$(this).parent().attr('href')+'" alt="'+$(this).attr('alt')+'" title="'+$(this).attr('title')+'"';
              paginationBar = paginationBar+'<a class="PaginationStep step"';
              
              if(i>15){
                  paginationBar = paginationBar+' hide';
              }

              paginationBar = paginationBar+'"';

              var bildSrc = $(this).attr('src')
              var bildHref = actImage.attr('href')



              if( bildSrc.substr(-8,8) == bildHref.substr(-8,8) && check == false){

                check = true;
                actImageCount = i;

                imageTitle = $(this).attr('title');
                imageDesc = $(this).attr('longdesc');

                paginationBar = paginationBar+' onclick="javascript:return false;" href="#" id="'+click+'" title="'+i+'"><span class="current">'+i+'</span></a>\n\
                ';
                images = images+' class="activeImage '+click+'"';
              }else{
                images = images+' class="'+click+'" style="display:none;"';
                paginationBar = paginationBar+' onclick="javascript:return false;" href="#" id="'+click+'" title="'+i+'">'+i+'</a>\n\
                ';
              }
              images = images+' />';

              paginationCount = i;
              i++;
          }

       });
      if(paginationCount > 15){
          paginationBar = paginationBar+'<a class="PaginationStep step" title="moreLinks-15" href="classClicknext" onclick="javascript:return false;">&raquo;</a>';
      }
      if(paginationBar != '' && paginationCount > 1){
        paginationBar = '<div class="pagination"><a href="#" class="nextStep" titlte="nextStep">weiter</a><a href="#" class="prevStep" titlte="prevStep">zur&uuml;ck</a>'+paginationBar+'</div>';
      }else{
          paginationBar = '';
      }
      var lightBox = '<div class="lightBoxOverlay">&nbsp;</div><div id="lightBox"><div class="content" style="margin:0 auto 0 auto;" >\n\
        <div class="lightboxHead"><h2>'+imageTitle+'&nbsp;</h2><a class="close" href="#" title="schliessen">&nbsp;</a></div>\n\
        '+images+'<div class="clearfix">\n\
        <p class="imageSubHeader">'+imageDesc+'</p>\n\
        </div>'+paginationBar+'</div></div>';

      $('#wrapper').before(lightBox);
      $('.lightBoxOverlay').css({
        height: browserWindowHeight,
        width: browserWindowWidth
      });

      var imageMaxWidth = 530;
      var imageMaxHeight = 420;
      $('#lightBox .content img').each(function(){
        if($(this).width() > imageMaxWidth && $(this).height() < imageMaxHeight ){
          $(this).attr('width',imageMaxWidth);
        }else if($(this).width() < imageMaxWidth && $(this).height() > imageMaxHeight ){
            $(this).attr('height',imageMaxHeight);
        }else if($(this).width() > imageMaxWidth && $(this).height() > imageMaxHeight ){
            if($(this).attr('width') > $(this).attr('height')){
                $(this).attr('height',imageMaxHeight);
            }else{
                $(this).attr('width',imageMaxWidth);
            }
        }
      });

      $('#lightBox .content img').ak_buildPagination();
        $('.PaginationStep').click(function(event){
            event.preventDefault();
            $('#lightBox .content img').css('display','none');
            var clickedStep = $(this).attr('id');
            $('#lightBox .pagination a span.current').parent().text($('#lightBox .pagination .current').text());
            $(this).parent().children().filter('a').each(function(i){
                if($(this).attr('id') == clickedStep){
                    $(this).html('<span class="current">'+$(this).text()+'</span>')
                }
            });
            
            $('#lightBox .content img.'+$(this).attr('id')).css('display','block');
            $('#lightBox .content .imageSubHeader').text($('img.'+$(this).attr('id')).attr('longdesc'));
        });
        $('.pagination a.prevStep').click(function(event){
            event.preventDefault();
            $('#lightBox .pagination a span.current').parent().prev().click();
        });
        $('.pagination a.nextStep').click(function(event){
           event.preventDefault();
           $('#lightBox .pagination a span.current').parent().next().click();
        });

      $('#lightBox .close').click(function(){
        $("iframe, select, embed, object").show();
        $('body').css('text-align','left');
        $('#wrapper').css({'z-index':'100'});
        $('#lightBox').remove();
        $('.lightBoxOverlay').remove();
      });

      $('html,body').animate({
        scrollTop: $('body')
        });

      $('#lightBox .pagination a').click(function(){

        $('#lightBoxImage').attr({'src':$(this).attr('src'),'alt':$(this).attr('alt'),'title':$(this).attr('title')});

        event.preventDefault();
        return false;
      });
      
      return false;
  });



    jQuery.fn.ak_buildPagination = function(sites){
        var paginationMax = $(this).length;
        var paginationViewedMax = 15;

        var nextPaginationSectionLink = '<a class="PaginationStepSection step" onclick="javascript:return false;" href="nextSection" title="nextSection">»</a>';
        var prevPaginationSectionLink = '<a class="PaginationStepSection step" onclick="javascript:return false;" href="prevSection" title="prevSection">»</a>';
        var nextPageLink = '<a titlte="nextStep" class="nextStep" href="#">weiter</a>';
        var prevPageLink = '<a titlte="prevStep" class="prevStep" href="#">zur&uuml;ck</a>';

        var checkPageCount = 0;
        var  paginationBar
        jQuery.each(jQuery(this), function(i,val){
            i++; // Start with 1

        })
    }

    /**
     * return width for the Picture
     */
    jQuery.fn.ak_giveImageSize = function(){
        //$(image).ak_giveImageSize();
        var maxWidth = 540;
        var maxHeight = 400;

        var newWidth = 0;

        var image = $(this);
        if(image.width > maxWidth){
            newWidth = maxWidth;
        }

        return newWidth;
    }

    jQuery.fn.getPageSize = function(){
        var xScroll, yScroll;

        if (window.innerHeight && window.scrollMaxY) {
                xScroll = window.innerWidth + window.scrollMaxX;
                yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
        }

        var windowWidth, windowHeight;

        if (self.innerHeight) { // all except Explorer
                if(document.documentElement.clientWidth){
                        windowWidth = document.documentElement.clientWidth;
                } else {
                        windowWidth = self.innerWidth;
                }
                windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
        }

        // for small pages with total height less then height of the viewport
        if(yScroll < windowHeight){
                pageHeight = windowHeight;
        } else {
                pageHeight = yScroll;
        }


        // for small pages with total width less then width of the viewport
        if(xScroll < windowWidth){
                pageWidth = xScroll;
        } else {
                pageWidth = windowWidth;
        }

        var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
        return arrayPageSize;
    };



