Redirector = new function(from)
{
    this.domain = window.location.host;
    this.from = window.location.href;
    Redirector = this;
    
    this.maskHrefs = function()
    {
        jQuery(function($) {
            $('a').each(function() {
                var href_from, href_to, i, temp;
                if (!(/(^| )direct( |$)/i.test(this.className))) {
                    href_from = this.href;
                    href_to = href_from.replace(new RegExp('^http:\\/\\/(.*?\\.)?' + Redirector.domain + '((\\/)|$)', 'i'), '/');
                    if (/^http:\/\/.*?((\/)|$)/i.test(href_to)) {
                        href_to = escape(href_to);
                        href_to = '/redirect/?to=' + href_to + '&from=' + escape(Redirector.from);
                        if (/(^| )redirect_item( |$)/i.test(this.className)) {
                            href_to += '&type=item';
                        }
                        if ($(this).closest('div.ganzara_banner').length > 0) {
                            href_to += '&from_type=banner&bid=' + $(this).closest('div.ganzara_banner').eq(0).attr('id').replace(/banner/, '');
                        } else if ($(this).closest('.jsSponsor').length > 0) {
                            href_to += '&from_type=sponsor';
                        } else if ($(this).closest('.rollBanner.jsPopularFirms').length > 0) {
                            href_to += '&from_type=popular_firm';
                        } else if ($(this).closest('#center_col').length > 0) {
                            href_to += '&from_type=content';
                        } else {
                            href_to += '&from_type=other';
                        }
                        this.href = href_to;
                    }
                }
            });
        });
    }
    
    this.normalFrom = function(url)
    {
        return (url && !/^((http:\/\/.*?\/)|(\/redirect\/))/i.test(this.normalizeLink(url)));
    }
    
    this.normalTo = function(url)
    {
        return (url != '' && !/^(\/redirect\/)/i.test(this.normalizeLink(url)));
    }
    
    this.normalizeLink = function(url)
    {
        url = url.replace(new RegExp('^http:\\/\\/(www\\.)?' + this.domain + '\\/', 'i'), '/')
        if (url != '/') {
            url = url.replace(/\/$/i, '');
        }
        return url;
    }
    
    {
        var ref;
        if (this.normalFrom(ref = this.normalizeLink(this.from))) {
            this.from = ref;
        } else if (this.normalFrom(ref = this.normalizeLink(from))) {
            this.from = ref;
        } else {
            this.from = '/';
        }
    }
}

