﻿(function ($) {
    $(function () {
        $("#menu ul span").css("opacity", "0");
        $("#menu ul span").css("display", "block");
        $("#menu ul span").hover(function () {
            $(this).stop().animate({ opacity: 1 }, "slow");
        }, function () {
            $(this).stop().animate({ opacity: 0 }, "slow");
        });
        $("#tipHome, #tipEAgora, #tipAltoAstral, #tipPorAi, #tipDonaAstro, #tipACasaOferece, #tipEuLila").tipsy({ gravity: $.fn.tipsy.autoWE.North, fade: true, html: true, delayIn: 1000, opacity: 0.85 });
        Ajax.GetTagsList();
        $(".siteMap a").click(function () {
            if ($(".siteMapList").is(":hidden")) {
                $(".siteMapList").slideDown(1, function () {
                    $("html, body").animate({ scrollTop: $(document).height() }, 1);
                });
            } else {
                $(".siteMapList").slideUp(1, function () {
                    $("html, body").animate({ scrollTop: $(document).height() }, 1);
                });
            }
        });
        var liSoma = 0;
        $(".siteMapList").css("display", "block");
        $(".siteMapList ul li").each(function (index) {
            liSoma += $(this).outerWidth();
        });
        var margin = (parseInt((($(".siteMapList").innerWidth() - liSoma) / $(".siteMapList ul li").length) / 2));
        $(".siteMapList ul li").each(function (index) {
            $(this).css({ 'margin-left': margin + 'px', 'margin-right': margin + 'px' });
        });
        $(".siteMapList").css("display", "none");
    });
    var Ajax = {
        Loader: function (selector) {
            $(selector).html('<p class="loading"><img src="' + getURLRoot() + '/App_Themes/Default/Images/Icons/AjaxLoader.gif" alt="..." /></p>');
        },
        GetTagsList: function () {
            Ajax.Loader(".tagCloud");
            $.ajax({
                type: "GET",
                url: getURLRoot() + "/Tags/List",
                success: function (data) {
                    Ajax.WriteTagsList(data);
                }
            });
        },
        WriteTagsList: function (data) {
            $(".tagCloud").html('');
            $.each(data, function (i, val) {
                $("<a>").text(val.Name).attr({ href: (getURLRoot() + "/tags/posts/" + val.TagID) }).appendTo(".tagCloud");
            });
            $(".tagCloud a").randomClass(['magenta', 'purple', 'blue', 'green'], { randomness: 'successive' });
        }
    };
})(jQuery);
