$(function () {

    var animation;

    function startAnimate(elem) {
        animation = window.setTimeout(function () {
            elem.animate({ right: '-23px' }, 1000);
        }, 10000);
    }

    var url = "/resources/functions/freeaccount/freeaccount"

    var cont = $("div.Contact, div.ImageGallery, div.TextLayout1, div.Guestbook, div.Diary");
    if (cont.length > 0) {
        var functionName = cont.attr("class").toLowerCase();
        if (functionName)
            url += "." + functionName;
    }

    var r = new RegExp(/^[a-z][a-z0-9+\-.]*:\/\/(?:[^\/?#]+)(\.[a-zA-Z]{2,3})(?:\:\d+)?(?:\/\S*)?$/g);
    if (r.exec(location.href)) {
        var topDomain = RegExp.$1;
        if (topDomain == ".se" || topDomain == ".no" || topDomain == ".uk")
            url += topDomain;
    }

    url += ".html";
    $.get(url, null, function (result) {
        if (result) {
            var elem = $("div.FreeAccount");
            elem.html(result).mouseenter(function () {
                window.clearTimeout(animation);
                $(this).stop().css("right", "-2px");
            }).mouseleave(function () {
                startAnimate(elem);
            });
            startAnimate(elem);
        }
    },
    "html");
});

