﻿google.setOnLoadCallback(function() {
    $(document).ready(function() {

        // Nav Dropdown
        // Loop through each list item in the menu
        $("#navigation").find("li").each(function() {
            // Check if list element contains a dropdown, if yes - run hide and show function
            if ($(this).find(".dropdown").size() > 0) {
                $(this).hover(function() {
                    $(this).find(".dropdown").css({ "visibility": "visible" });
                    $(this).find("a:first").addClass("Selected");
                },
                function() {
                    $(this).find(".dropdown").css({ "visibility": "hidden" })
                    $(".Selected").removeClass("Selected");
                });
            };
        });

        $(".content:last").addClass("LastPanel");

        // Carousel
        // Check if carousel is in page, if yes - run.
        if ($("#Carousel").size() > 0) {

            // Focus the slider on arrow click, to counter select bug
            function Carousel_initCallback(carousel) {
                $('.jcarousel-next').click(function() {
                    carousel.stopAuto();
                    carousel.next();
                    $(this).focus();
                    return false;
                });
                $('.jcarousel-prev').click(function() {
                    carousel.stopAuto();
                    carousel.prev();
                    $(this).focus();
                    return false;
                });
                // Pause autoscrolling if the user moves with the cursor over the clip.
                carousel.clip.hover(function() {
                    carousel.stopAuto();
                }, function() {
                    carousel.startAuto();
                });
            };

            // Initiate Carousel
            // count number of items, find middle item
            var itemCount = $("#Carousel").find(".Item").size();
            var middleItem = Math.ceil(itemCount / 2);
            // Start
            $("#Carousel").jcarousel({
                scroll: 2,
                //start: middleItem,
                initCallback: Carousel_initCallback
            });
        };



    });
});

