$(document).ready(function() {

// Open links in new window
$("a[rel='external']").click(function(){window.open(this.href); return false;});

$('.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: 17,
                    right: -117,
                    display: 'block'
                }).animate({
                    top: 17,
                    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: 17,
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });

				
});//End document ready

// Fancybox
$(document).ready(function() {
	if ($('a[rel=group]').length) {
		$("a[rel=group]").fancybox({
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'titlePosition': 'over',
			'titleFormat': function(title, currentArray, currentIndex, currentOpts){
			return '<span id="fancybox-title-over">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	if ($('a[rel=group2]').length) {
		$("a[rel=group2]").fancybox({
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'titlePosition': 'over',
			'titleFormat': function(title, currentArray, currentIndex, currentOpts){
			return '<span id="fancybox-title-over">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
});//End Fancybox

