﻿$(document).ready
(
    function() 
    {
        function RotateDay(feature) 
        {
            if (doAnimate) 
            {
                feature.fadeOut
                (
                    "fast",
                    function(feature) 
                    {
                        return function() 
                        {
                            $("div.weathermenu div.day").hide();
                            
                            feature.fadeIn
                            (
                                "slow",
                                function() 
                                {
                                    var lastdiv = $('div.weathermenu div.day:last').attr("id");

                                    if ($(this).attr("id") == lastdiv) 
                                    {
                                        setTimeout
                                        (
                                            function() 
                                            {
                                                RotateDay($("div.weathermenu div.day:first"));
                                            }, 5000
                                        );
                                    }
                                    else 
                                    {
                                        setTimeout
                                        (
                                            function() 
                                            {
                                                RotateDay($(feature.next()));
                                            }, 5000
                                        );
                                    }
                                }
                            );
                        };
                    }
                    (feature)
                );
            }
        }

        var doAnimate = true;
        RotateDay($("div.weathermenu div.day:first"));
    }
);