function SpotlightPanel(args) {
    var container = args.container;
    var refreshTime = args.refreshTime;
    var refreshSpotlightsTimeout;
    var nextSpotlightIndex = args.nextSpotlightIndex;
    
    var getSpotlightHtml = function(spotlight) {
        var advertUrl = navigationConfig.searchServerUrl + "/search/" + spotlight.advertId + 
            "/advert?channel=" + spotlight.channel;
        var spotlightHtml = "<a href='" + advertUrl + "'>" +
            "<img width='150' height='113' src='http://pictures.autotrader.ie/imgser-ie/servlet/media?id=" + spotlight.imageId + "&width=150&height=113'></a>" + 
            "<a class='make' href='" + advertUrl + "'>" + spotlight.title + "</a>" + 
            "<span>" + spotlight.formattedPrimaryPrice + "</span>";
        if (spotlight.formattedSecondaryPrice != null && spotlight.formattedSecondaryPrice != "") {
            spotlightHtml += "<span>(" + spotlight.formattedSecondaryPrice + ")</span>";
        }
        return spotlightHtml;
    }
    
    var refresh = function() {
        $.getJSON(navigationConfig.searchServerUrl + "/car-dealers/spotlights?dealerid=" + dealerId + 
            "&nextSpotlightIndex=" + nextSpotlightIndex + "&getResponseAsJson=true&jsoncallback=?",
            function(spotlights) {
                $(spotlights).each(
                    function(i) {
                        container.find(".spotlight:eq(" + i + ")").html(getSpotlightHtml(this));
                    }
                );
                if (spotlights.length < 4) {
                    nextSpotlightIndex = 0;
                } else {
                    nextSpotlightIndex = nextSpotlightIndex + 4;
                }
                refreshSpotlightsTimeout = 
                    setTimeout(function() {refresh();}, refreshTime);
            }
        );
    }
    
    this.beginSpotlightRotation = function() {
        refreshSpotlightsTimeout = setTimeout(function() {refresh();}, refreshTime);
    }
}

