
    $(function () {
        $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $(this);//;$('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);

			info.append('<div class="bubbleTail"></div>');


            trigger.mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: -90,
                        left: -33,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 0.9
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });



(function($) {

    $.fn.myModal = function() {

        var link = $(this);
        var current = 0;
        var modalDefWidth = 0; //jeweils 30px an jeder Seite
        var modalDefHeight = 0; //30 Pixel oben und unten
        var maskHeight = $(window).height();
        var maskWidth = $(document).width();
		var windowWidth = $(window).width();
        var overlay = $('<div id="modalOverlay"></div>');
        var leftArrow = $('<div id="modalToLeft"></div>');
        var rightArrow = $('<div id="modalToRight"></div>');
        var mouseIn = false;
        var modalWindowDefault = $('<div id="modalWindow"><div class="modalCloseButton"></div><div id="modalImg"></div><div id="modalText"></div></div>');
        var modalWindow = modalWindowDefault;
        var images = new Array();
        //var imageLock = true;

        link.click(function(e) {
            //set top-position of modal window
            modalWindow.css({top:e.pageY, left: e.pageX});
            //add grey overlay
            $("body").append(overlay.click(function() {
                  modalHide();
            }));
            $(document).keydown(handleEscape);

            //create image list
            var buffer = link.parents('div.sample').find('a').not('.noGallery');//;$('a.myModal[rel="'+link.attr('rel')+'"]');
            jQuery.each(buffer,function(i) {
                images[i] = {'href' : $(this).attr('href'),  'description' : $(this).attr('title')};
                if($(this).attr('href') == link.attr('href')) current = i;
            });

            //add clicked image
            $('body').append(modalWindow);
            modalWindow.children('#modalImg').prepend(leftArrow).prepend(rightArrow);
            modalWindow.fadeIn();
            //show grey overlay
            overlay.css({'width':maskWidth,'height':maskHeight,'opacity':0.6}).fadeIn();


            changeImage(current);

            $('.modalCloseButton').click(function() { modalHide(); });

            listenArrows();

            return false;
        });

        function modalHide() {
            $(document).unbind("keydown", handleEscape);
            overlay.fadeOut();
            modalWindow.fadeOut(function() {
                modalWindow.css({width:modalDefWidth}).find('img').remove();
                modalWindow.children('div#modalText').hide().html('');

            });
        }

        //Our function that listens for escape key.
        function handleEscape(e) {
            if (e.keyCode == 27) {
                modalHide();
            }
        }

        function changeImage(i) {
            var img = new Image();
            $(img).load(function() {
				modalWindow.children('#modalImg').fadeOut(250);
                modalWindow.animate({
                    width:modalDefWidth + img.width,
					top:'50px',
                    left: $(window).scrollLeft() + (windowWidth - img.width - modalDefWidth) / 2
                }, 250,function() {
                    leftArrow.css('top',(img.height - 20) /2);
                    rightArrow.css('top',(img.height - 20) /2);
                    modalWindow.find('img').remove();
                    modalWindow.find('#modalImg').append($(img).show()).show();//fadeIn(100,function() {
                    modalWindow.find('#modalText').html('<p>'+images[i].description+'</p>').show();
                    if(current == 0) {
                        leftArrow.hide();
                    } else if(mouseIn) leftArrow.show();
                    if(current == images.length - 1) {
                        rightArrow.hide();
                    } else if(mouseIn) rightArrow.show();
                });

            }).attr({src: images[i].href});
        }

        function listenArrows() {
            modalWindow.children('#modalImg').mouseenter(function() {
                mouseIn = true;
                if(current > 0) leftArrow.stop(false,true).fadeIn();
                if(current < images.length - 1) rightArrow.stop(false,true).fadeIn();
            }).mouseleave(function() {
                mouseIn = false;
                leftArrow.stop(false,true).fadeOut();
                rightArrow.stop(false,true).fadeOut();
            });

            leftArrow.click(function() {
                if(current <= 0) return;

                current--;
                changeImage(current);
            });

            rightArrow.click(function() {
                if(current >= images.length - 1) return;

                current++;
                changeImage(current);
            });
        }

    };

})(jQuery);




$(document).ready(function () {


	$('.sample a').not('.noGallery').each(function() { $(this).myModal(); });

	//animation for impressum
    var impressum = $('#impressum');
    var height = impressum.height();
    impressum.hide().css({top:'311px', 'background-color':'#121212',padding:'0 15px 13px 15px'});

    $('a#showImpressum').click(function () {
        if (impressum.is(':visible')) {
            impressum.fadeOut(250);
        } else {
            impressum.fadeIn(250);
        }
        
        return false;
    });
});

