Cufon.replace('h1, h2, h3, h4, h5');
Cufon.replace('.header ul.language-switcher-locale-url a, .header p.social a', {
    hover: true
});
Cufon.replace('.content h2');
Cufon.replace('.sub-header h2');
Cufon.replace('.footer h2', {
    textShadow: '#000 1px 1px'
});
Cufon.replace('div.menu a', {
    textShadow: '#ceb47c 1px 1px',
    hover: {
        color: '#fff',
        textShadow: '#666 1px 1px'
    }
});
Cufon.replace('.submenu a', {
    textShadow: '#000 1px 1px',
    hover: true
});

var lightbox = new function() {

    var self = this;

    var $lightbox = $('<div class="modal"><a href="#" class="prev"></a><a href="#" class="next"></a><a href="#" class="close"></a></div>').animate({'opacity': 0}, 0).appendTo($('body'));
    var $overlay = $('<div class="overlay"/>').animate({'opacity': 0}, 0).appendTo($('body'));
    var $photos = $('<div/>').appendTo($lightbox);

    $lightbox.find('a.next').click(function(e) {
        e.preventDefault();
        self.show(self.current + 1);
    });

    $lightbox.find('a.prev').click(function(e) {
        e.preventDefault();
        self.show(self.current - 1);
    });

    $lightbox.find('a.close').click(function(e) {
        e.preventDefault();
        self.close();
    });

    this.queue = [];

    this.current = undefined;

    this.push = function(e) {
        self.queue.push(e);
        $('<img src="' + e + '" alt=""/>').animate({'opacity': 0}, 0).appendTo($photos);
        return self.queue.length - 1;
    }

    this.show = function(i) {

        if (self.queue.length == 0)
            return;

        if (typeof i == 'undefined')
            i = 0;

        if (i >= self.queue.length || i < 0)
            return;

        var $img = $photos.find('img:eq(' + i + ')');
        var $active = $img.siblings('.active');


        self.current = i;

        var w = $img.outerWidth();
        var h = $img.outerHeight();

        $img.animate({'opacity': 1}, 0);
        $lightbox.find('a').hide();
        $lightbox.animate({'height': h, 'width': w, 'margin-top': -Math.floor(h/2) + 'px', 'margin-left': -Math.floor(w/2) + 'px' }, 500, function() {
            $lightbox.find('a').show();
        });
        $active.animate({'opacity': 0}, 500, function() {
            $active.removeClass('active');
            $img.addClass('active');
        })
    }

    this.open = function(i) {
        if (self.queue.length == 0)
            return;

        if (typeof i == 'undefined')
            i = 0;

        if (i > self.queue.length)
            return;

        if (!$photos.find('img.active').length)
            $photos.find('img:eq(0)').addClass('active');

        $overlay.css('display', 'block').animate({'opacity': 0.7}, 500, function() {
            $lightbox.css('display', 'block');
            self.show(i);
            $lightbox.animate({'opacity': 1}, 500, function() {
                $lightbox.css('filter', '');
            });
        });
    }

    this.close = function() {
        $lightbox.animate({'opacity': 0}, 250, function() {
            $overlay.animate({'opacity': 0}, 500, function() {
                $lightbox.css('display', 'none');
                $overlay.css('display', 'none');
            });
        });
    }


}

$('a.lightbox').each(function() {
    var $a = $(this);
    var href = $a.attr('href').replace(/.*#/, '');

    var i = lightbox.push(href);

    $a.click(function(e) {
        e.preventDefault();
        lightbox.open(i);
    });
});


$('div.sub-header p.bottle').each(function() {
    var $bottle = $(this);

    if (!$bottle.hasClass('active')) {
        $bottle.css({'margin-left': '-79px', 'height': '323px', 'width': '158px', 'bottom': '100px'});
        if (!$.browser.msie || $.browser.version >= 9)
            $bottle.find('img:eq(1)').css({'display': 'block', 'opacity': 1});
    } else {
        $bottle.addClass('big').css({'margin-left': '-158px', 'height': '646px', 'width': '316px', 'bottom': '0'});
        if (!$.browser.msie || $.browser.version >= 9)
            $bottle.find('img:eq(1)').css({'display': 'block', 'opacity': 0});
    }
});


$('div.sub-header div.box').hover(function() {
    if ($(this).hasClass('active'))
        return;
    $('div.sub-header div.box').toggleClass('active');
    $('div.sub-header p.bottle').toggleClass('active');

    var $box = $(this);
    var $bottleActive = $('div.sub-header p.bottle.active');
    var $bottle = $bottleActive.siblings('p.bottle');

    $bottle.stop(true).animate({'margin-left': '-270px'}, 500, function() {
        if (!$.browser.msie || $.browser.version >= 9)
            $bottle.find('img:eq(1)').animate({'opacity': '1'}, 500);
    }).animate({'margin-left': '-79px', 'height': '323px', 'width': '158px', 'bottom': '100px'}, 500);

    $bottleActive.stop(true).animate({'margin-left': '30px'}, 500, function() {
        if (!$.browser.msie || $.browser.version >= 9)
            $bottleActive.find('img:eq(1)').animate({'opacity': '0'}, 500);

        $('div.sub-header p.bottle.active').addClass('big').siblings('p.bottle').removeClass('big');
    }).animate({'margin-left': '-158px', 'height': '646px', 'width': '316px', 'bottom': '0'}, 500);
});

