(function () {

    var code = '6fce748032310e71cba4745c7bdd6bd5';
    var context = 'http://counter.localhost.ge/';
    var basedomain = '';

    var scripts = document.getElementsByTagName('script');
    var thisScript = scripts[scripts.length - 1];

    var img = document.createElement('img');

    thisScript.parentNode.insertBefore(img, thisScript);

    var loaded = false;
    var popup, tween;
    img.src = context + 'counterimage.php?basedomain=' + basedomain + '&referrer=' + escape(document.referrer) + '&code=' + code + '&backcolor=c0c0c0';
    img.onclick = function () {
        location = context + 'topsites.php?code=' + code;
    };
    img.style.cursor = 'pointer';
    img.onmouseover = function () {
        if (window.Foobar) {
            if (!loaded) {
                tween = $.Tween({
                    frames: 10,
                    tweener: 'STRONG_INOUT',
                    change: function (e) {
                        popup.css({ opacity: e }).show();
                    },
                    finish: function () {
                        if (tween.current() == 0) popup.hide();
                    }
                });
                loaded = true;
                popup = $.Popup().setSize(140,70).setConstraint(img, 'EAST_INSIDE', 'NORTH_OUTSIDE').css({
                    background: '#fff',
                    border: '1px solid #68a'
                });
                var image = new Image();
                image.onload = function () {
                    var detailedImage = Foobar('img', {
                        src: image.src,
                        css: {
                            opacity: 0,
                            border: 0
                        }
                    });
                    popup.add(detailedImage);
                    $.tween({
                        frames: 10,
                        tweener: 'STRONG_IN',
                        change: function (e) {
                            detailedImage.css({ opacity: e });
                        }
                    });
                };
                image.src = context + 'detailedimage.php?code=' + code + '&basedomain=' + basedomain;
            }
            tween.foreward();
        }
    };
    img.onmouseout = function () {
        if (loaded) tween.backward();
    };
})();

