(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() == "SPAN") { // found an image
                    // flickr uses "_s" suffix for small, and "_m" for big
                    // images respectively
                    
                    return el.innerHTML;
                }
                el = el.nextSibling;
            }
            
            return "";
        }
                
        YAHOO.util.Event.onDOMReady(function (ev) {
            var spotlight   = YAHOO.util.Dom.get("spotlight");
            
                var carousel    = new YAHOO.widget.Carousel("model",{
                        animation: { speed: 0.5 },
                        numVisible: 4,
                        revealAmount: 20
                        
                });
                       
            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)+"\" class=\"pngfix\">";
                }
            });
                
            carousel.render(); // get ready for rendering the widget
            carousel.show();   // display the widget
            
            var calloutY = YAHOO.util.Dom.getY('calloutTop');
            var wave = YAHOO.util.Dom.get('waveOverlay');
            YAHOO.util.Dom.setStyle(wave, 'top', ((calloutY-80)+'px'));
        });
    })();

