/*----------------------------------------------------------

* File Name: home.js

----------------------------------------------------------*/
(function ($) {
    //Set up the variables.
    var $this = $("#slide-content"),
        $children = $this.children(".slide"),
        $max = $children.length,
        $pause;
    //Position and hide the slides.
    function style_nodes(node /* HTML elements */ ) {
        var i = 0;
        node.each(function () {
            $(this).css({
                "position": "absolute",
                "top": 0,
                "left": 0,
                "z-index": 5
            });
            if (i > 0) {
                $(this).hide();
            }
            i += 1;
        });
    };
    //Create the timer function.
    function animate_slides(node /* HTML elements */ , int /* Integer */ ) {
        var i = int || 0;
        $pause = setTimeout(function () {
            $children.eq(i).stop(true, true).fadeOut(750);
            //Ternary operator for incrementing i.
            i = (i < ($max - 1)) ? i += 1 : i = 0;
            $children.eq(i).stop(true, true).fadeIn(750);
            //Re-run the animation.
            animate_slides(node, i);
        }, 8000);
    };
    //Self initiating function to get things started.
    (function init() {
        style_nodes($children);
        animate_slides($children);
    })();
})(jQuery);
