$(function() {
    
    // IE6 CSS fix
    var msie6 = (/MSIE 6/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (msie6) {
        $('head').append('<link rel="stylesheet" type="text/css" media="all" href="/css/ie6/layout.css" />');
        $('head').append('<link rel="stylesheet" type="text/css" media="all" href="/css/ie6/default.css" />');
    }
    // IE7 CSS fix
    var msie7 = (/MSIE 7/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (msie7) {
        $('head').append('<link rel="stylesheet" type="text/css" media="all" href="/css/ie7/layout.css" />');
        $('head').append('<link rel="stylesheet" type="text/css" media="all" href="/css/ie7/default.css" />');
    }

    // Chats
    $('#gmChat').chat({
        updateTime:             15000,
        sleepTime:              60000,
        sleepUpdateTime:        120000,
        urlSend:                "/chat/gm/add/",
        urlGet:                 "/chat/gm/get/",
        messagePrefix:          "gmM"
    });
    $('#chat').chat();

    // Server status
    $('#serverStatus').serverStatus({
        callback: function() {
            $("img").tooltip({});
            $(".tooltipBlock").tooltip({});
            $.fixIE();
        }
    });

    // Statistics
    $('#stats').statistics();

    // Stripes
    $('.table').stripe({});

    // Tooltips for images, spans and divs
    $('img, span, div').tooltip({});

    // Pagers
    $('#vipMembers').pager({
        callback:   function() {
            // Stripes
            $('.table').stripe({});
        }
    });
    $('#changelog').pager({
        url:            "/changelog/get/",
        filter:         "#filterChangelog",
        select:         "#selectChangelog",
        main:           "#changelogMain",
        loader:         ".changelog-loading",
        callback:       function() {
            $('body').editor({
                editUrl:            "/changelog/edit/",
                editButtons:        ".edit",
                deleteUrl:          "/changelog/delete/",
                deleteButtons:      ".delete",
                callback:   function() {
                    $("#filterChangelog").keydown();
                }
            });
        }
    });

    $(".eventLog").eventViewer({});

    $("#wowMainMenu").armory({
        tabs:   {
            character:  {
                icon:           "#characterTabIcon",
                url:            "/armory/character/characterTab/"
            },
            spellbook:  {
                icon:           "#spellbookTabIcon",
                url:            "/armory/character/spellbookTab/"
            }
        },
        afterOpen:      function() {
            $(".tooltipItem").tooltip({
                itemUrl:        "/armory/item/"
            });
        },
        guidElement:    ".characterGuid"
    });

    $("#localization").i18nFlags({
        languages:         [ "cs", "sk", "en" ]
    });

});
