var viewportWidth = jQuery(window).width();
var viewportHeight = jQuery(window).height();

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = jQuery(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function doMenu() {
    jQuery('ul.superfish').superfish({
        delay: 200,                            // one second delay on mouseout 
        animation: { opacity: 'show', height: 'show' },  // fade-in and slide-down animation 
        speed: 'fast',                          // faster animation speed 
        autoArrows: false,                           // disable generation of arrow mark-up 
        dropShadows: false                            // disable drop shadows 
    });
}

function doCarousel() {
    // http://caroufredsel.frebsite.nl/configuration.php

    $.fn.carouFredSel.defaults.items.visible = 1;
    $.fn.carouFredSel.defaults.direction = "up";

    jQuery("#carousel").carouFredSel({
        scroll: {
            mousewheel: true, // Determines whether the carousel can be scrolled via the mousewheel. To enable this feature, you'll need to include the jquery.mousewheel plugin.
            fx: "scroll", // none, scroll, directscroll, fade, crossfade, cover, uncover
	        easing: "swing",
	        // swing, linear
            // Easing plugin transitions:
            //      easeInQuad, easeOutQuad, easeInOutQuad
            //      easeInCubic, easeOutCubic, easeInOutCubic
            //      easeInQuart, easeOutQuart, easeInOutQuart
	        //      easeInQuint, easeOutQuint, easeInOutQuint
	        //      easeInSine, easeOutSine, easeInOutSine
	        //      easeInExpo, easeOutExpo, easeInOutExpo
	        //      easeInCirc, easeOutCirc, easeInOutCirc
	        //      easeInElastic, easeOutElastic, easeInOutElastic
	        //      easeInBack, easeOutBack, easeInOutBack
	        //      easeInBounce, easeOutBounce, easeInOutBounce
	        duration: 1500,
	        pauseOnHover: true,
            queue: false
        },
        auto: {
            delay: 500 // Additional delay in milliseconds before the carousel starts scrolling the first time. Hint: This can also be a negative number.
        },
        // items: 1,
        // direction: "right",
        effect: "easeOutSine",
        pagination: {
		    container: "#carousel_pag",
		    keys: true
	    }
    });
}

function doInit() {
    jQuery("ka_01_body").removeClass("noscroll");
    if (parseInt(viewportWidth) < 1000 && parseInt(viewportWidth) > 989) {
        jQuery("ka_01_body").addClass("noscroll");
    }
}

function doFlaps() {
    var viewportWidth = parseInt(jQuery(window).width());
    if (parseInt(viewportWidth) >= 1300) {
        jQuery(".flap").show();
        jQuery(".flap").height(jQuery(document).height()).width((viewportWidth - 1300) / 2);
    }
    else {
        jQuery(".flap").hide();
    }
}

jQuery(document).ready(function () {
    Cufon.replace('h1,h2,h3,h4,h5', { fontFamily: 'kunstakademie-wetter', hover: true });
    doInit();
    doMenu();
    doCarousel();
    equalHeight(jQuery(".bot"));
    doFlaps();
});

jQuery(window).resize(function() {
    viewportWidth = jQuery(window).width();
    viewportHeight = jQuery(window).height();
    // scrollbar yes or no
    if (parseInt(viewportWidth) < 1000 && parseInt(viewportWidth) > 989) {
        jQuery("ka_01_body").addClass("noscroll");
    }
    else {
        jQuery("ka_01_body").removeClass();
    }
    doFlaps();
});

function DoPageRebuild() {
    Cufon.replace('h1,h2,h3,h4,h5', { fontFamily: 'kunstakademie-wetter', hover: true });

    viewportWidth = jQuery(window).width();
    viewportHeight = jQuery(window).height();
    // scrollbar yes or no
    if (parseInt(viewportWidth) < 1000 && parseInt(viewportWidth) > 989) {
        jQuery("ka_01_body").addClass("noscroll");
    }
    else {
        jQuery("ka_01_body").removeClass();
    }

    doFlaps();
    // alert("DoPageRebuild - DONE");
}


