jQuery(document).ready(function(){
	// Preloade images
	$('img.flickr').preload({
		onComplete: function(data){
			// hier die Liste aufbauen
			// erst bild berechnen dann - liste bild pro bild verlängern
		},
		onFinish: function(data){
			$("ul > li > div.preload").remove();	
			
			// Gallery
			$('#gallery').galleryslider({
				width: "100%",
				height: 480,
				direction: "horizontal",
				hideScollBar: true 
			}); 
		}
	});	
	
	// Navigation
	var navbtnpos = $('img.navigationbtn').position();
	var browsebarpos = $('div.browsebar').offset();
	
	$('div.nopen').css({ right: ( $(window).width() - (navbtnpos.left + browsebarpos.left + 220 - 23) ) },"fast");
	
	$('img.navigationbtn').add('a.contact').click(function(){
		$('div.navoverlay').animate({ right: ( $(window).width() - (navbtnpos.left + browsebarpos.left + 220 - 23) ) },"fast");
	});
	$('div.navbtnwhite').add('ul.picturelist').add('a.contact').add('#index').click(function(){
		if ($('div.navoverlay').css("right") >= "0px") 
			$('div.navoverlay').animate({right: -220}, "fast");
	});		

	$(".navlink img").hover(
	 function(){
	  this.src = this.src.replace("_off","_on");
	 },
	 function(){
	  this.src = this.src.replace("_on","_off");
	 }
	);

	// bubbles
	$(function () {
        $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 250;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).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: -150,
                        left: -70,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, 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 () {
        $('.bubbleInfo2').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 250;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).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: -220,
                        left: -70,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, 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;
            });
        });
    });	
	
});
