$(function(){
    if ($.browser.safari) 
        $('body').addClass('safari');
    $('body').addClass('mocha');
    var fadeSpeed = ($.browser.safari ? 600 : 450);
    $('#logotype a, #menu_breakfast a').append('<span class="hover"></span>');
    $('.hover').css('opacity', 0);
    $('.hover').parent().hover(function(){
        $('.hover', this).stop().animate({
            'opacity': 1
        }, fadeSpeed)
    }, function(){
        $('.hover', this).stop().animate({
            'opacity': 0
        }, fadeSpeed)
    });
});
//******************************************************
var Navigation = function(){
    var me = this;
    var args = arguments;
    var self = {
        c: {
            navItems: '#navigation .home, #navigation .exhibitions, #navigation .gallery, #navigation .news, #navigation .contact, #navigation .catherine',
            navSpeed: ($.browser.safari ? 600 : 350),
            snOpeningSpeed: ($.browser.safari ? 400 : 250),
            snOpeningTimeout: 150,
            snClosingSpeed: function(){
                if (self.subnavHovered()) 
                    return 123450;
                return 150
            },
            snClosingTimeout: 700
        },
        init: function(){
            $('.level_1', this.c.navItems).css({
                'opacity': 0
            });
            this.initHoverFades()
        },
        initHoverFades: function(){
            $('#navigation .main').append('<span class="hover"></span>');
            $('#navigation .hover').css('opacity', 0);
            $('#navigation .main').hover(function(){
                self.fadeNavIn.apply(this)
            }, function(){
                var el = this;
                setTimeout(function(){
                    if (!el.open) 
                        self.fadeNavOut.apply(el)
                }, 10)
            })
        },
        fadeNavIn: function(){
            $('.hover', this).stop().animate({
                'opacity': 1
            }, self.c.navSpeed)
        },
        fadeNavOut: function(){
            $('.hover', this).stop().animate({
                'opacity': 0
            }, self.c.navSpeed)
        }
    };
    self.init.apply(self);
    return self
};
$(function(){
    new Navigation()
});

/////////////////////////////////////////////////////////////////////////////////

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

            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: 135,
                        left: 595,
                        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;
            });
        });
    });
	
/* */
$(document).ready(function(){
$("div.info").fadeTo("slow", 0.3); // This sets the opacity of the thumbs to fade down to 30% when the page loads
$("li.nextexhib").hover(function(){
		$("> :eq(1)", this).fadeTo("slow", 0.7); // This should set the opacity to 100% on hover
	}
	,function(){
		$("> :eq(1)", this).fadeTo("slow", 0.3); // This should set the opacity back to 30% on mouseout
   	});
});

$(document).ready(function(){
$("img.img_gallery").fadeTo("slow", 0.8); // This sets the opacity of the thumbs to fade down to 30% when the page loads
$("img.img_gallery").hover(function(){
		$(this).fadeTo("slow", 1); // This should set the opacity to 100% on hover
	}
	,function(){
		$(this).fadeTo("slow", 0.8); // This should set the opacity back to 30% on mouseout
   	});
});
/* */
$(function() {
	$("#contact_map p").slideToggle("slow");
	$("#contact_map").hover(function() {
		$("> :eq(1)", this).slideToggle("normal");
	},
	function() {
		$("> :eq(1)", this).slideToggle("normal");
	});
});
