$(document).ready(function(){
    if ( $.browser.msie && $.browser.version.substr(0,1)<7 ){
        var bgImage = $("#background img").attr('src');
        $('body:not(.home, .kontakt)').css({
            "background": "url("+bgImage+") 0% 50% no-repeat",
            "backgroundAttachment": "fixed"
        });
    } else {
        $("#background").ezBgResize();
        $(window).bind("resize", function(){
            $("#background").ezBgResize();
        });
    }

    $("a#popup").fancybox({
        'easingIn': 300, 'easingOut': 300, 'overlayShow': false, 'padding': 30, 'frameHeight': 500
    });

    $('#slider').after('<div id="paginator">').cycle({
        fx:       'scrollHorz',
        speed:     '180',
        timeout:   0,
        pager:     '#paginator',
        next:      '#next',
        prev:      '#prev'
    });

    $('div#gallery ul li:first-child').addClass('first');
    $('div#gallery ul li:last-child').addClass('last');

    $("div#gallery ul li a").each( function(){
       $(this).prepend('<span></span>', '<div class="galleryOverlay"></div>');
    });

    if(!$.browser.msie){
        $("div#gallery ul li a span").hover( function(){
            $(this).stop().parent().find('.galleryOverlay').fadeOut(320);
            $(this).animate({ width: 154, height: 180, top: 0, left: 0}, 120);
        }, function(){
            $(this).stop().parent().find('.galleryOverlay').fadeIn(320);
            $(this).animate({ width: 172, height: 198, top: -10, left: -10}, 120);
        });
    }

    $("#slider li a").fancybox({
        titleShow:      false,
        padding:        0,
        overlayOpacity: 0.5
    });

    // Form stuff
    $('form#contact div.fieldHolder input, form#contact div.textHolder textarea').focus(function () {
        $(this).parent().addClass('focus');
    }).blur(function () {
        $(this).parent().removeClass('focus');
    });

    // Send form
    $('#feedback').hide();
    $('#sendmail').click(function() {
        $('#feedback').fadeIn();
        $('#preloader').show();
        $.post("./assets/mail/contact.php", {
            name: $('#name').val(), email: $('#email').val(), message: $('#message').val(), chk: $('#chk').val()
        }, function(response){
            $('#preloader').fadeOut();
            setTimeout("finishAjax('feedback', '"+escape(response)+"')", 800);
        });

        return false;
    });
    $('#contact').blur(function(){
        $('#preloader').fadeOut();
        return false;
    });
    $("#contact").bind("keypress", function(e) {
        if (e.keyCode == 13) return false;
    });
    $('#contact').blur(function(){
        $('#preloader').fadeOut();
        return false;
    });
    $("#contact").bind("keypress", function(e) {
        if (e.keyCode == 13) return false;
    });
    $('#accordion').accordion({ autoHeight: false });

    $("ul#menu").superfish({
        hoverClass:    'sfHover',
        pathClass:     'overideThisToUse',
        pathLevels:    1,
        delay:         800,
        animation:     {opacity:'show'},
        speed:         'normal',
        autoArrows:    false,
        dropShadows:   true
    });
});
Cufon.replace('#reference ul li', {textShadow: '#000 0px 1px', fontFamily: 'Helvetica Neue'});
Cufon.replace('#content h2', {textShadow: '0px 1px 12px rgba(0, 0, 0, 0.7)', fontFamily: 'Helvetica Neue'});
function finishAjax(id, response) {
  $('#preloader').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}