    (function () {
        // Get the image link from within its (parent) container.
        function getImage(parent) {
            var el = parent.firstChild;
                    
            while (el) { // walk through till as long as there's an element
                if (el.nodeName.toUpperCase() == "IMG") { // found an image
                    // flickr uses "_s" suffix for small, and "_m" for big
                    // images respectively
                    return el.src.replace(/_s\.jpg$/, "_m.jpg");
                }
                el = el.nextSibling;
            }
            
            return "";
        }
                
        YAHOO.util.Event.onDOMReady(function (ev) {
            var spotlight  = YAHOO.util.Dom.get("spotlight"),
                carousel   = new YAHOO.widget.Carousel("container"),
		numItems   = carousel.get("numItems"),
                numVisible = carousel.set("numVisible", 1),
                paginator;
                       
            carousel.on("itemSelected", function (index) {
                // item has the reference to the Carousel's item
                var item = carousel.getElementForItem(index);

                if (item) {
                    spotlight.innerHTML = "<img src=\""+getImage(item)+"\">";
                }
            });
            carousel.set("autoPlayInterval", 9000);
            carousel.set("isCircular", true);
            carousel.render();
            carousel.show();
            carousel.startAutoPlay();
                
            paginator     = new YAHOO.widget.Paginator({
                    containers   : "pagination",
                    rowsPerPage  : 1,
                    template     : "{PageLinks}",
                    totalRecords : Math.ceil(numItems / numVisible)
            });

            paginator.subscribe("changeRequest", function (state) {
                carousel.set("selectedItem", (state.page - 1) * numVisible);
                paginator.setState(state);
            });

            carousel.on("pageChange", function (page) {
                // Paginator's page begins from 1
                // Also, we need to suppress this triggering a changeRequest
                // event.
                paginator.setPage(page + 1, true);
            });
            
            paginator.render();
        });
    })();