$(function () {

    // Ajaxcalls miteinbeziehen in der Statistik.
    $('.track').live('click', function () {
        if (typeof i !== 'undefined') {
            $.get(i.src + '&c=' + Math.floor(Math.random() * 101));
        }
        if (typeof OEWA !== 'undefined' && typeof r !== 'undefined' && typeof t !== 'undefined') {
            $('body').append('<img width="0" height="0" src="' + OEWA + '?r=' + r + '&d=' + t + '&c=' + Math.floor(Math.random() * 101) + '" />');
        }
        if (typeof stat_ajaxcall !== 'undefined') {
            $('body').append('<img width="0" height="0" src="' + stat_ajaxcall + '" />');
        }
    });

    // Beim Seitenladen ein Statistikaufruf machen.
    if (typeof stat_url !== 'undefined') {
        $('body').append('<img width="0" height="0" src="' + stat_url + '" />');
    }

    // Bannerzählen.
    var typ = {};

    $('a[class*=stat-]').each(function () {
        var advertisement = $.map($(this).attr('class').split(' '), function (value) {
            return value.match(/stat-\D+/);
        });
        advertisement = advertisement.toString().replace(/stat-/, '');
        if (advertisement !== '') {
            typ[advertisement] = (typ[advertisement] === undefined) ? 1 : typ[advertisement] + 1;
        }
    });

    // Banneraufrufe an die Statistik weiterleiten.
    if (typeof banner_info !== 'undefined') {
        $('body').append('<img width="0" height="0" src="' + banner_info + '&params=' + $.param(typ).replace(/=/g, ':').replace(/&/g, ',') + '&type=1" />');
    }

    // Bannerclick miteinbeziehen in der Statistik.
    $('a[class*=stat-]').live('click', function () {
        if (typeof banner_info !== 'undefined') {
            var banner = $.map($(this).attr('class').split(' '), function (value) {
                return value.match(/stat-\D+/);
            });
            $('body').append('<img width="0" height="0" src="' + banner_info + '&banner=' + banner.toString().replace(/stat-/, '') + '&type=2" />');
        }
    });

    // Downloads miteinbeziehen in der Statistik.
    $('a[class*=download-]').live('click', function () {
        if (typeof download_info !== 'undefined') {
            var download = $.map($(this).attr('class').split(' '), function (value) {
                return value.match(/download-\D+/);
            });
            $('body').append('<img width="0" height="0" src="' + download_info + '&download=' + download.toString().replace(/stat-/, '') + '&type=3" />');
        }
    });

    // Suchen miteinbeziehen in der Statistik.
    $('#solr-form-submit').live('click', function () {
        var $this = $(this), $input = $this.parent().prev().prev().children('input');
        if (typeof solrform !== 'undefined') {
            $('body').append('<img width="0" height="0" src="' + solrform + '&formid=' + $input.closest('form').attr('id') + '&inputid=' + $input.attr('id') + '&inpuvalue=' + base64(unescape(encodeURIComponent($input.val()))) + '" />');
        }
    })
});
