/**
 * @fileOverview All JS-code for domain.nl
 * @author name
 * @since 1.0 - 2010-8-6
 * @version 1.0 - 2010-8-6
 */




if (typeof(nl) == "undefined") {
	var nl = {}
}
if (typeof (nl.kempischbedrijvenpark) == "undefined") {
    nl.kempischbedrijvenpark = {}
}






/**
 * @namespace Boiler plate class
 */
nl.kempischbedrijvenpark.Spotlight = (function() {
    var maxCount = 0;
    var iCount = 0;

    function setZIndex() {
        var zIndex = (maxCount + 1) * 10;

        jQuery("ul.spotlight li").each(function(i) {
            jQuery(this).css("z-index", zIndex);
            zIndex = zIndex - 10;
        });
    }

    function animateImage(opacity, animate, listItem) {
        if (opacity == 1) {
            listItem.show();
        }

        if (animate) {
            listItem.animate({ "opacity": opacity }, 500);
        } else {
            listItem.css("opacity", opacity);
        }

        if (opacity == 0) {
            listItem.hide();
        }
    }

    function setImages(index, animate) {
        jQuery("ul.spotlight li").each(function(i) {
            if (i != index) {

                animateImage(0, animate, jQuery(this));

            } else {

                animateImage(1, animate, jQuery(this));

            }
        });

        index++;
    }

    function startTimer(index) {
        iCount = index;

        jQuery("ul.spotlight").everyTime(5000, "spotlight", function(i) {
            if (iCount >= maxCount) {
                iCount = 0;
            } else {
                iCount++;
            }

            setImages(iCount, true);
        });
    }

    function stopTimer() {
        jQuery("ul.spotlight").stopTime("spotlight");
    }

    /* Start public */
    return {
        /**
        * nl.agroenco.Spotlight.Init()
        **/
        Init: function() {
            maxCount = (jQuery("ul.spotlight li").length - 1);

            setZIndex();
            
            setImages(0, false);

            startTimer(0);
        }
    }
    /* End public */
})();

