jQuery(function(){

//Big carousel on startpage

    var jQuerycarouselDiv=jQuery("#carouselDiv");
    var jQuerycarouselImageDiv=jQuery("#carouselImageDiv");
    var jQuerycarouselTitleDiv=jQuery("#carouselTitleDiv");
    var jQuerycarouselDescriptionDiv=jQuery("#carouselDescriptionDiv");
    var jQuerycarouselImage=jQuery("#carouselImage");
    var jQuerycarouselToogleImage=jQuery("#carouselToogleImage");
    var jQuerycarouselH1=jQuery("#carouselTitleDiv h1:last");
    var jQuerycarouselH2=jQuery("#carouselTitleDiv h1:first");
    var jQuerycarouselH3=jQuery("#carouselDescriptionDiv h2");
    var jQuerycarouselH4=jQuery("#carouselDescriptionDiv h1");
    var jQuerycarouselP=jQuery("#carouselDescriptionDiv p");
    var jQuerycarouselLink=jQuery("#carouselLink");
    var jQuerycarouselControls=jQuery("#carouselControlDotsDiv ul");


    jQuery("#carouselData li").each(function(){
        var jQueryitem=jQuery(this);
        var image=jQueryitem.children("img").attr("src");
        var h1=jQueryitem.children("h1").html();
        var h2=jQueryitem.children("h2").html();
        var h3=jQueryitem.children("h3").html();
        var h4=jQueryitem.children("h4").html();
        var link=jQueryitem.children("h6").html();
        var p=jQueryitem.children("p").html();
        jQuerycarouselControls.append('<li><img class="carouselDot" width="8" height="8" alt="" /></li>');
        jQuerycarouselControls.children("li:last").children("img").data({image: image, h1: h1, h2: h2, h3: h3, h4: h4, p: p, link: link});

    });
    jQuery("img.carouselDot").attr("src", "/templates/_default_/i/carousel_dot.png");
    jQuerycarouselControls.children("li:first").children("img").attr("src", "/templates/_default_/i/carousel_dot_filled.png");
     var carouseSize=jQuery("img.carouselDot").size();
    jQuery("img.carouselDot").click(function(){
        
        jQueryitem=jQuery(this);
        n=jQuery("img.carouselDot").index($(this));
        if (n==carouseSize) n=0
        jQuery("img.carouselDot").attr("src", "/templates/_default_/i/carousel_dot.png")
        .removeClass('carouselDotActive');
        jQueryitem.attr("src", "/templates/_default_/i/carousel_dot_filled.png");
        jQueryitem.addClass('carouselDotActive');

        jQuerycarouselLink.attr('href',jQueryitem.data("link"));

        jQuerycarouselToogleImage.attr("src", jQuerycarouselImage.attr("src"))
        .fadeOut(1500);
        jQuerycarouselImage.attr("src", jQueryitem.data("image"));

        jQuerycarouselTitleDiv.fadeOut("fast", function(){
            jQuerycarouselH1.html(jQueryitem.data("h1"));
            jQuerycarouselH2.html(jQueryitem.data("h2"));
            jQuerycarouselTitleDiv.fadeIn("slow");
        });

        jQuerycarouselDescriptionDiv.fadeOut(500, function(){
            jQuerycarouselH3.html(jQueryitem.data("h3")+' <span class="b-car-icon"></span>');
            jQuerycarouselH4.html(jQueryitem.data("h4"));
            jQuerycarouselP.html(jQueryitem.data("p"));
            jQuerycarouselDescriptionDiv.fadeIn(500);
        });



    });



   // jQuery("img.carouselDot:first").click();

var n=0;

    jQuerycarouselDiv.everyTime(4000, 'carouselTimer', function() {
        n++;
        if(carouseSize==n)n=0;
        jQuery("img.carouselDot").eq(n).click();

    });

     jQuerycarouselDiv.mouseover(function(){
        jQuerycarouselDiv.stopTime('carouselTimer');
    });

    jQuerycarouselDiv.mouseout(function(){
        jQuerycarouselDiv.everyTime(4000, 'carouselTimer', function() {
            n++;
            if(carouseSize==n)n=0;
            jQuery("img.carouselDot").eq(n).click();

        });
    });


//End of big carousel on startpage



    jQuery("#projectsCarousel").jcarousel({
        vertical: true,
     //   wrap: 'circular',
        animation: 450,
        scroll: 1,
        initCallback: projectsCarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

 


    jQuery("#newsCarousel").jcarousel({
  //      wrap: 'circular',
        animation: 450,
        scroll: 1,
        vertical: true,
        initCallback: newsCarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });


/*

    jQuery("#eventsCarousel").jcarousel({
        wrap: 'circular',
        animation: 450,
        scroll: 1,
        initCallback: eventsCarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
             */

});

    function newsCarousel_initCallback(carousel) {
        jQuery('#newsCarouselNextButton').bind('click', function() {
            carousel.next();
            return false;
        });

        /*jQuery('#newsCarouselNextButton').bind('mouseover', function() {
            jQuery(this).attr("src", "/i/button_right_blue.png");
            return false;
        });

        jQuery('#newsCarouselNextButton').bind('mouseout', function() {
            jQuery(this).attr("src", "/i/button_right_white.png");
            return false;
        });  */

        jQuery('#newsCarouselPrevButton').bind('click', function() {
            carousel.prev();
            return false;
        });

       /* jQuery('#newsCarouselPrevButton').bind('mouseover', function() {
            jQuery(this).attr("src", "/i/button_left_blue.png");
            return false;
        });

        jQuery('#newsCarouselPrevButton').bind('mouseout', function() {
            jQuery(this).attr("src", "/i/button_left_white.png");
            return false;
        });   */
    };


    function projectsCarousel_initCallback(carousel) {
        jQuery('#projectsCarouselNextButton').bind('click', function() {
            carousel.next();
            return false;
        });

      /*  jQuery('#projectsCarouselNextButton').bind('mouseover', function() {
            jQuery(this).attr("src", "i/button_right_blue.png");
            return false;
        });

        jQuery('#projectsCarouselNextButton').bind('mouseout', function() {
            jQuery(this).attr("src", "i/button_right_white.png");
            return false;
        }); */

        jQuery('#projectsCarouselPrevButton').bind('click', function() {
            carousel.prev();
            return false;
        });

       /* jQuery('#projectsCarouselPrevButton').bind('mouseover', function() {
            jQuery(this).attr("src", "i/button_left_blue.png");
            return false;
        });

        jQuery('#projectsCarouselPrevButton').bind('mouseout', function() {
            jQuery(this).attr("src", "i/button_left_white.png");
            return false;
        });  */
    };


    function eventsCarousel_initCallback(carousel) {
        jQuery('#eventsCarouselNextButton').bind('click', function() {
            carousel.next();
            return false;
        });

        jQuery('#eventsCarouselNextButton').bind('mouseover', function() {
            jQuery(this).attr("src", "/i/button_right_blue.png");
            return false;
        });

        jQuery('#eventsCarouselNextButton').bind('mouseout', function() {
            jQuery(this).attr("src", "/i/button_right_white.png");
            return false;
        });

        jQuery('#eventsCarouselPrevButton').bind('click', function() {
            carousel.prev();
            return false;
        });

        jQuery('#eventsCarouselPrevButton').bind('mouseover', function() {
            jQuery(this).attr("src", "/i/button_left_blue.png");
            return false;
        });

        jQuery('#eventsCarouselPrevButton').bind('mouseout', function() {
            jQuery(this).attr("src", "/i/button_left_white.png");
            return false;
        });
    };
