(function norm_uri(l, h) { if(l.host.match(/^www\.([^.]+)\.([^.]+)\.([^.]+)/) && l.host != (h = l.host.replace(/^www\./,''))) l.host = h; })(window.location||documenet.location);
 
(function set_fb_like(title) {
//     var title = '<!-- IF TOPIC_TITLE -->{TOPIC_TITLE}<!-- ELSE -->{PAGE_TITLE}<!-- ENDIF --> :: {SITENAME} ';
    if(!title) title = window.forum_title;
    var l = window.location || documenet.location,
        h = l.host.replace(/^www\./,''), 
        p = l.pathname.replace(/\/$/,'/index.php'), 
        s = l.search.substr(1).split('&').sort().join('&').replace(/(&)?sid=[^&]+/, ''), 
        u = l.protocol + '//' + h + p + (s?'?'+s:'');

//         console.log(u);

    var counters = {};
    function set_tmr(f, l, c, n) {
        if(!c) c = 100;
        if(!n) n = f.name;
        if(l === undefined) l = counters&&counters[n]; else if(l && !counters) counters = {};  
        if(l-->0) {
          setTimeout(f, c);    
          counters[n] = l;
        } else {
          l=0;
          if(counters) { 
             delete counters[n];
             for(l in counters) break;
             if(!l) counters = null;
          } 
        }
        return l 
    }

    function set_gp1_button(l) {   
        var gp1 = document.getElementById('g+1'), g = gp1 && gp1.firstChild;
        if(!gp1 || g.nodeName.toUpperCase() != 'DIV') return set_tmr(arguments.callee,l); 
        g.setAttribute('height', h+'px');
        g.style.marginTop  = '-5px';
        set_tmr(arguments.callee,0);
    }
    
    function set_tw_button(l) {
        var tw = document.getElementById('twit');   
        if(!tw) return set_tmr(arguments.callee,l);
        var href = 'http://twitter.com/?status=' + encodeURI(title) + u;
        tw.setAttribute('height', h+'px');
        tw.setAttribute('href', tw.href = href);
        set_tmr(arguments.callee,0);
    }

    function set_fb_like_button(l) {
       var fl = document.getElementById('fb_like');
       if(!fl) return set_tmr(arguments.callee,l);
       var w=100, h=21;
       u = encodeURIComponent(u);
       fl.setAttribute('src', 'http://www.facebook.com/plugins/like.php?href='+u+'&layout=button_count&show_faces=false&action=like&colorscheme=light&width='+w+'&height='+h);
       fl.setAttribute('height', h+'px');
       fl.setAttribute('width', w+'px');
       //fl.parentNode.title = u;
       set_tmr(arguments.callee,0);
    }

    set_gp1_button(30);
    set_tw_button(30);
    set_fb_like_button(30);
        
})();

