/**
 * fix department scrollable height
 * fuck chrome not ie this time
 */
function fix() {
    $("document").ready(function() {
    
        
        setTimeout(function() {
            var tallest = 0;
            $("#departments ul li").each(function() {
                if ($(this).height() > tallest) {
                    tallest = $(this).height();
                }            
            });
            $("#departments .items-out").height(tallest);
            $("#departments ul").children().css({'min-height': tallest});
        }, 100);
    });
}

$("document").ready(function() {
    /**
     * init scrollable plugin for departments section
     */
    if ($("#departments .items-out .items .item").size() > 5) {
        $("#departments .items-out").scrollable({
            'onSeek':function() {
                if (this.getIndex() >= this.getSize() - 5) {
                    $("#departments .nav .next").addClass("toBegin");
                }
            }
        });
    }
    var scrollable = $("#departments .items-out").data("scrollable");
    $("#departments .nav a").click(function() {
        if ($(this).hasClass("toBegin")) {
            scrollable.seekTo(0);
            $(this).removeClass("toBegin");
        }
        return false;
    });
    
    /**
     * init tabs
     */
    $(".tabs-out ul.tabs").tabs(".tabs-out .panes > div ");
    
    /**
     *  show complete firmenportrait
     */
    if($(".firmenportrait").length > 0 || $(".produktportrait").length > 0){
    	$("#moreLink").click(function(){
    		if($("#mainContent").is(':visible')){
        		$("#mainContent").hide();
    		}else{
        		$("#mainContent").fadeIn();
    		}
    		return false;
    	});
    
	    /**
	     * initiate slideshow (firmenportrait)
	     */
    	if($("#slideshow").length > 0){
		    $('#slideshow').fadeSlideShow({
		    	width: 325, // Weite der SlideShow
		    	height: 245, // Höhe der Slideshow
		    	speed: 'slow', // Animationsgeschwindigkeit
		    	interval: 3000, // Zeit zwischen Bildwechsel 1000 = 1 Sekunde
		    	PlayPauseElement: 'fssPlayPause', // ID für Play / Pause Element
		    	PlayText: 'Play', // Play Text
		    	PauseText: 'Pause', // Pause Text
		    	NextElement: 'fssNext', // ID für den weiter Button
		    	NextElementText: 'n&auml;chstes >', // Text für den weiter Button
		    	PrevElement: 'fssPrev', // ID für den zurück Button
		    	PrevElementText: '< vorheriges', // Text für den zurück Button
		    	ListElement: 'fssList', // ID für die Bilder-Liste
		    	ListLi: 'fssLi', // Klasse für LI-Elemente in der Bilder-Liste
		    	ListLiActive: 'fssActive', // Klasse für aktives Element in der Bilder-Liste
		    	addListToId: false, // Bilder-Liste in ein HTML Element mit der ID ... einfügen
		    	allowKeyboardCtrl: false, // Keyboardsteuerung erlauben
		    	autoplay: true 
		    });
		    $("#slideshow li img").show();
    	};  	
	    
	    $(".empfehlen").click(function(){
	    	$("#overlayRecommend").show();
	    	return false;
	    });
	    
	    $('.newsList').jScrollPane();	    

        if($(".produktportrait").length > 0) {
            function mycarousel_initCallback(carousel) {
                // Pause autoscrolling if the user moves with the cursor over the clip.
                carousel.clip.hover(function() {
                    carousel.stopAuto();
                }, function() {
                    carousel.startAuto();
                });
            };
            
            // custom fade in/out functions for jcarousel
            function mycarousel_fadeOut(carousel) {
                var JCcontainerID = carousel.clip.context.id;
                $('#' + JCcontainerID).fadeOut();
            };
            function mycarousel_fadeIn(carousel) {
                var JCcontainerID = carousel.clip.context.id;
                $('#' + JCcontainerID).fadeIn();
            };
            
            $('#produktSlider').jcarousel({
                scroll                  : 1,
                wrap                    : "circular",
                auto                    : 5,
                itemFallbackDimension   : 319,
                initCallback            : mycarousel_initCallback,
                itemLoadCallback        : {
                    onBeforeAnimation: mycarousel_fadeOut,
                    onAfterAnimation: mycarousel_fadeIn
                }
            });
        }


    };	 
    
    if($(".landingpage").length > 0) {
    	if($("#slideshow").length > 0){
		    $('#slideshow').fadeSlideShow({
		    	width: 325, // Weite der SlideShow
		    	height: 245, // Höhe der Slideshow
		    	speed: 'slow', // Animationsgeschwindigkeit
		    	interval: 3000, // Zeit zwischen Bildwechsel 1000 = 1 Sekunde
		    	PlayPauseElement: 'fssPlayPause', // ID für Play / Pause Element
		    	PlayText: 'Play', // Play Text
		    	PauseText: 'Pause', // Pause Text
		    	NextElement: 'fssNext', // ID für den weiter Button
		    	NextElementText: 'n&auml;chstes >', // Text für den weiter Button
		    	PrevElement: 'fssPrev', // ID für den zurück Button
		    	PrevElementText: '< vorheriges', // Text für den zurück Button
		    	ListElement: 'fssList', // ID für die Bilder-Liste
		    	ListLi: 'fssLi', // Klasse für LI-Elemente in der Bilder-Liste
		    	ListLiActive: 'fssActive', // Klasse für aktives Element in der Bilder-Liste
		    	addListToId: false, // Bilder-Liste in ein HTML Element mit der ID ... einfügen
		    	allowKeyboardCtrl: false, // Keyboardsteuerung erlauben
		    	autoplay: true 
		    });
		    $("#slideshow li img").show();
    	};
    	
    	$('.newsList').jScrollPane();
        
    	function mycarousel_initCallback(carousel) {
    		// Pause autoscrolling if the user moves with the cursor over the clip.
    	    carousel.clip.hover(function() {
    	        carousel.stopAuto();
    	    }, function() {
    	        carousel.startAuto();
    	    });
    	};
    	
    	// custom fade in/out functions for jcarousel
    	function mycarousel_fadeOut(carousel) {
    		var JCcontainerID = carousel.clip.context.id;
    		$('#' + JCcontainerID).fadeOut();
    	};
    	function mycarousel_fadeIn(carousel) {
    	    var JCcontainerID = carousel.clip.context.id;
    	    $('#' + JCcontainerID).fadeIn();
    	};
    	
    	$('#produktSlider').jcarousel({
            scroll 					: 1,
            wrap					: "circular",
            auto 					: 5,
            itemFallbackDimension 	: 319,
            initCallback			: mycarousel_initCallback,
            itemLoadCallback		: {
                onBeforeAnimation: mycarousel_fadeOut,
                onAfterAnimation: mycarousel_fadeIn
    		}
        });
    	
    	$('#herstellerSlider').jcarousel({
            scroll 					: 1,
            wrap					: "circular",
            auto 					: 5,
            itemFallbackDimension 	: 319,
            initCallback			: mycarousel_initCallback,
            itemLoadCallback		: {
                onBeforeAnimation: mycarousel_fadeOut,
                onAfterAnimation: mycarousel_fadeIn
    		}
        });
    };
    
    /**
     * initiate modal form (lightbox-style window for contact form)
     */
    $(function() {
    	$('.nyroModal').nyroModal();
    });
});

$(function(){
    $('#featured .entry').columnize({
        lastNeverTallest: true
    });
});
