$j = jQuery;

self.PortfolioManager = {
    aImages: [],
    iActiveIndex: 0,
    iTimeout: null,
    init: function() {
        var oSelf = self.PortfolioManager;
        var iLen = window.aImageFilenames.length;
        /* preload all images */
        for (i=0; i<iLen; i++) {
            oSelf.aImages[i] = new Image(778, 350);
            oSelf.aImages[i].src = "img/" + window.aImageFilenames[i];
        }
        $j("#placeholder_content").css("background-image", "url(" + $j("#placeholder_content img").attr("src") + ")");
        oSelf.showNext();
    },
    destruct: function() {
        window.clearTimeout(self.PortfolioManager.iTimeout);
        self.PortfolioManager = null;
    },
    showNext: function() {
        var oSelf = self.PortfolioManager;
        // activate another thumbnail
        oSelf.iActiveIndex++;
        if (oSelf.iActiveIndex>=oSelf.aImages.length) {
            oSelf.iActiveIndex = 0;
        }
        $j("#placeholder_content img").css("display", "none").attr(
            "src",
            oSelf.aImages[oSelf.iActiveIndex].src
            ).fadeIn("slow", function() {
                $j("#placeholder_content").css("background-image", "url(" + $j("#placeholder_content img").attr("src") + ")");
                oSelf.iTimeout = window.setTimeout("self.PortfolioManager.showNext()", 2000)
            });
    }
};

$j(document).ready(function(){
    self.PortfolioManager.init();
});

$j(window).unload(function() {
    self.PortfolioManager.destruct();
});

