(function($) {

    $(function() {

        // Rotators
        (function() {

            // Product Rotator

            // The transition fx.
            var fx = 'fade';

            // The inactive and active dot urls.
            var inactiveDotUrl = WP.template_url + "/images/inactive-square.png",
                activeDotUrl = WP.template_url + "/images/active-square.png";

            var dotContainer = $(".pager");
            var slides = $("#slides");
            // Create as many dots as there are slides.
            slides.children().each(function() {
                $("<img>", {
                    src: inactiveDotUrl,
                    alt: "square"
                }).appendTo($("<a>", {
                    href: "#"
                }).appendTo(dotContainer));
            });

            // Find all the created dots.
            var dots = dotContainer.find("img");

            // Moves the dot to correspond with the current slide.
            var dotHandler = function(current, next) {
                var offset = $(next).prevAll().size();
                dots.attr("src", inactiveDotUrl);
                dots.eq(offset).attr("src", activeDotUrl);
            };

            // Start the cycle plugin.
            slides.cycle({
                fx: fx,
                after: dotHandler,
                cleartypeNoBg: true
            });

            // This is for the awesomeness that is IE 7.
            slides.cycle("pause");
            slides.children().eq(0)
            .css({
                width: 810,
                height: 230
            });
            slides.cycle("resume");

            // Bind navigation controls to each dot.
            dotContainer.find("a").click(function() {
                var offset = $(this).prevAll().size();
                slides.cycle("stop");
                slides.cycle({
                    fx: fx,
                    after: dotHandler,
                    startingSlide: offset
                });
                slides.cycle("stop");
                return false;
            });

            // Client Rotator

            var news = $(".news-ticker #latest-posts");
            news.cycle({
                fx: 'scrollDown'
            });

            var searchform = "<li class='search'>"+searchFormHTML+"</li>";
            $('ul.main-navigation').append(searchform);

            $('input[type=text]').click(
                function() {
                    $(this).css('background-image', 'none');
                }
            );
        })();

    });

})(jQuery);


