﻿$(document).ready(function() {

    $.fn.wait = function(time, type) {
        time = time || 3000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };

    $('.RightNavItem').show();
    $('.PageContentServicesRightNav').wait(800).slideDown("slow", function() { Highlight(0, 'a.RightNavLink'); });

    function Highlight(startIndex, selector) {
        // Cyles through all elements that match the selector one by one
        var length = $("'" + selector + "'").length - 1;
        // Only do this if the selector yields any elements
        if (length >= 0) {
            $("'" + selector + ':eq(' + startIndex + ')')
                  .animate({ anything: '+=200' }, 200,
                    function() { HighlightOn(this); })
                  .animate({ anything: '-=200' }, 200,
                    function() {
                        HighlightOff(this);
                        if (startIndex < length) {
                            Highlight(startIndex + 1, selector);
                        }
                    }
        );
        }
    }

    function HighlightOn(t) {
        //alert(a);
        $(t).css({ "color": "#62BB46", "font-weight": "normal" });
    }
    function HighlightOff(t) {
        $(t).css({ "color": "#666666", "font-weight": "normal" });
    }

});
