
Cufon.replace('#mainMenu li a, #subnav li a, #b_title', { hover: true, textShadow: '1px 1px 1px #130C02', fontFamily: 'Georgia' })
Cufon.replace('.fiftyone #mainMenu li a, .fiftyone #mainMenu li a:hover, .fiftyone #subnav li a, .fiftyone #b_title', { hover: true, textShadow: '1px 1px 1px #ffffff', fontFamily: 'Georgia' })

Cufon.replace('.subLevelMenu a, .sameLevelMenu a', { hover: true, fontFamily: 'Georgia' })
Cufon.replace('h1, h2, h3, .big, .ttl', { fontFamily: 'RotisSerif' })
Cufon.replace('.eventtitle', { hover: true, fontFamily: 'RotisSerif' })
Cufon.replace('#payoff h1', { textShadow: '1px 1px 1px #130C02', fontFamily: 'RotisSerif' })

$(document).ready(function () {

    welcome()
    
    resize();
    carousel();
    cycleCustom();
    tabs();
});

function welcome() {
    $("#body_13 #thumbsH a").hover(
    function () {
        $('#thumbsH a img').not($(this).find('img')).stop().fadeTo('fast', 0.6);
    }
    ,
    function () {
        $('#thumbsH a img').stop().fadeTo('fast', 1);
    }
    );
}

$(window).resize(function () {
    resize();
})

function resize() {
    var wh = $(window).height();
    var ww = $(window).width() + 20;
    var top = (wh / 2) - ($('#loader').height() / 2);
    var left = (ww / 2) - ($('#loader').width() / 2)
    $('#loader').css('top', top);
    $('#loader').css('left', left);
    $('#nxtFull, #prvFull').css('top', top);

    var ratio = 1.5; //1440x950
    var imgw = wh * ratio;
    var x;
    if (imgw <= ww) {
        x = ww / ratio;
        $('#fullscreen img').height(x).width(ww);
    } else {
        x = wh;
        $('#fullscreen img').height(x).width(imgw);
    }
    $('#fullscreen img').css('top', -(x - wh)/2 );

}

function carousel() {

    //single image
    if ($('#cycle img.sigleImg').length > 0) {
        $('#cycle img.sigleImg').show().css('display', 'block')//.css('cursor', 'default');
        $('#nxtCycle, #prvCycle').hide();
        $('#nxtf, #prvf').hide();
        //return
    }
    
    $('#cycle').cycle({
        fx: 'fade',
        speed: 500,
        timeout: 4500,
        next: '#prv',
        prev: '#nxt'
    });

    $("#prv, #nxt, #cycle img").click(function () {
        $('#cycle').cycle('pause');
    })
        
    $('#cycle img').each(function() {
        $(this).click(function() {
            var imgbig = $(this).attr('src').replace('small_', 'big_');
            var imgcpt = $(this).attr('cpt');
            var imgid = $(this).attr('id');
            $('#loader').fadeIn(function() {
                $('#fullscreen').show();
                $('html, body').css('overflow', 'hidden');
                $('<img src="' + imgbig + '" />').load(loadBigImg(imgbig, imgcpt, imgid));
            })

        })
    })

    $("#fullscreen img").click(function() {
        //change small img in header
        var index = $('#cycle img').index($('#' + $(this).attr('ids')))
        $('#cycle').cycle(index);   
        $("#fullscreen").fadeOut(function() {
            $('html, body').css('overflow', 'auto');
            $('#fullscreen img').hide().attr('src', '').attr('ids', '');
            $('.cycleCanvas a').removeClass('active');
            $('#fullscreen').removeClass('fullscreenBgColor');
        });
    })

    //navigation between big images
    $("#nxtf, #prvf").click(function () {
        $('#fullscreen').addClass('fullscreenBgColor');
        var ids = $('#fullscreen img').attr('ids');
        var index = $('#cycle img').index($('#' + ids));
        var $active = $('#cycle img').eq(index);

        var $next;
        $next = $active.next().length ? $active.next() : $('#cycle img:first');
        if ($(this).attr('id') == 'nxtf') {
            $next = $active.prev()
            if ($active.attr('src') == $('#cycle img:first').attr('src')) {
                $next = $('#cycle img:last');
            }
        }

        var imgbig = $next.attr('src').replace('small_', 'big_');
        var imgcpt = $next.attr('cpt');
        var imgid = $next.attr('id');
        $('#loader').fadeIn(function () {
            $('<img src="' + imgbig + '" />').load(loadBigImg(imgbig, imgcpt, imgid));
        })
    })  
    
}


function loadBigImg(imgbig, imgcpt, imgid) {
    $('#caption').fadeOut()
    $("#fullscreen img").fadeOut(function() {
        $('#caption').empty().hide();
        $('#loader').fadeOut()
        $(this).attr('src', '').attr('src', imgbig).attr('ids', imgid).fadeIn();
        if (imgcpt != '') {
            $('#caption').html("<p>" + imgcpt + "</p>")
            Cufon.replace('#caption p', { textShadow: '1px 1px 1px #130C02', fontFamily: 'Georgia' })
            $('#caption').fadeIn();
        }
    });
}




function over(event) {
    $(this).find('img').stop().fadeTo('fast', 1);
}

function out(event) {
    $(this).find('img').stop().fadeTo('fast', 0.6);
}

function cycleCustom() {

    $(".cycleCanvas").hover(over, out);

    $(".cycleCanvas").click(function () {
        var canvasid = $(this).attr('id');
        var $link = $(this).find('a:first');
        var imgbig = $link.attr('href');

        var capt = 'de';
        if ($('body').hasClass("body_en")) {capt = 'en'}

        if ($(this).find('a').length == 1) {
            $('#nxtf, #prvf').hide();
        } else {
            $('#nxtf, #prvf').show();
        }

        $('#loader').fadeIn(function () {
            $('#fullscreen').show();
            $('html, body').css('overflow', 'hidden');
            $link.addClass('active');
            $('<img src="' + imgbig + '" />').load(loadBigImg2(imgbig, canvasid, $link.attr('capt' + capt)));

        })

        $("#nxtf, #prvf").unbind('click').click(function () {
            $('#fullscreen').addClass('fullscreenBgColor');
            var canvasid = $("#fullscreen img").attr('ids');
            var obj = '#' + canvasid + '.cycleCanvas a';
            var index = $(obj).index($(obj + '.active'));
            var $active = $(obj).eq(index);

            var $next;
            $next = $active.next().length ? $active.next() : $(obj + ':first');
            if ($(this).attr('id') == 'nxtf') {
                $next = $active.prev()
                if ($active.attr('href') == $(obj + ':first').attr('href')) {
                    $next = $(obj + ':last');
                }
            }

            $('#loader').fadeIn(function () {
                $(obj + '.active').removeClass('active');
                $next.addClass('active');
                $('<img src="' + imgbig + '" />').load(loadBigImg2($next.attr('href'), canvasid, $next.attr('capt' + capt)));
            })
        })

    })

    function loadBigImg2(imgbig, canvasid, capt) {

        $('#caption').fadeOut()
        $("#fullscreen img").fadeOut(function () {
            $('#caption').empty().hide();
            $('#loader').fadeOut()
            $(this).attr('src', '').attr('src', imgbig).attr('ids', canvasid).fadeIn();
            if ((capt) && (capt != '')) {
                $('#caption').html("<p>" + capt + "</p>")
                Cufon.replace('#caption p', { textShadow: '1px 1px 1px #130C02', fontFamily: 'Georgia' })
                $('#caption').fadeIn();
            }
        });
    }

}


function tabs() {
    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
    //On Click Event
    $("ul.tabs li").click(function () {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
}
