var sNetworks = function(){
    this._uri = this._parseUri(window.location.href);
    this.link = "http://"+this._uri.authority+this._uri.path;
    this.image_livejournal = '/images/livejournal.jpg';
    this.image_twitter = '/images/twitter.jpg';
    this.image_facebook = '/images/facebook.jpg';
    this.image_odnoklassniki = '/images/odnoklassniki.jpg';
    this.image_vkontakte = '/images/vkontakte.jpg';
    this.image_mail = '/images/mail.jpg';
    this.hint = 'Опубликовать в \'%name%\'';
    this.title = 'Ссылка';
    this.description = 'Описание ссылки';
    this.image = '';
    this._class = 'socialnetwork_buttons';
    //  ========= private
}
sNetworks.prototype = {
    // ========== public
    meta : function(){
        this._injectMetaNode({property:"og:title",content:this.title});
        this._injectMetaNode({property:"og:description",content:this.description});
        this._injectMetaNode({property:"og:url",content:this.link});
        this._injectMetaNode({name:"Title",content:this.title});
        this._injectMetaNode({name:"medium",content:'image'});
        this._injectMetaNode({name:"description",content:this.description});
        this._injectLinkNode("image_src",this.image);
        this._injectScriptNode("http://stg.odnoklassniki.ru/share/odkl_share.js");
    },
    // ========== private
    _parseUriOptions : {
        strictMode: false,
        key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
        q:   {
            name:   "queryKey",
            parser: /(?:^|&)([^&=]*)=?([^&]*)/g
        },
        parser: {
            strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
            loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
        }
    },
    _parseUri : function (str) {
        var o   = this._parseUriOptions;
            m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
            uri = {},
            i   = 14;

        while (i--) uri[o.key[i]] = m[i] || "";

        uri[o.q.name] = {};
        uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
            if ($1) uri[o.q.name][$1] = $2;
        });
        return uri;
    },
    _injectScriptNode : function(src){
        try{ document.write("<scr"+"ipt type='text/javascript' src='"+src+"'></scr"+"ipt>"); }
        catch(e){
            // strict XHTML mode, no document.write
            var head = document.getElementsByTagName("head")[0];
            var script = document.createElement("script");
            script.setAttribute("type", "text/javascript.appendC");
            head.appendChild(script);
            script.src = src;
        }
    },
    _injectLinkNode : function(rel,href){
        try{ document.write("<li"+"nk rel='"+rel+"' href='"+href+"'></li"+"nk>"); }
        catch(e){
            // strict XHTML mode, no document.write
            var head = document.getElementsByTagName("head")[0];
            var link = document.createElement("link");
            link.setAttribute("rel", rel);
            head.appendChild(link);
            link.href = href;
        }
    },
    _injectMetaNode : function(arrg){
        try{ document.write("<me"+"ta property='"+property+"' content='"+content+"'></me"+"ta>"); }
        catch(e){
            // strict XHTML mode, no document.write
            var head = document.getElementsByTagName("head")[0];
            var meta = document.createElement("meta");
            if(arrg.property!=null) meta.setAttribute("property", arrg.property);
            if(arrg.content!=null) meta.setAttribute("content", arrg.content);
            if(arrg.name!=null) meta.setAttribute("name", arrg.name);
            head.appendChild(meta);
        }
    },
    drawButton_livejournal : function(){
        var name = "LiveJournal";
        var title = this.hint.replace('%name%',name);
        var event = "";
        if(this.title!='') event+= '<h2>'+this.title+'</h2><br />';
        if(this.description!='') event+= this.description+'<br />';
        if(this.image!='') event+= '<br /><img src="'+this.image+'" height="100px"><br />';
        event+= '<a href="'+this.link+'">'+this.link+'</a>';
        var subject = this.title;
        var button = '<a rel="nofollow" href="http://www.livejournal.com/update.bml?event='+encodeURIComponent(event)+'&subject='+encodeURIComponent(subject)+'" target="_blank" title="'+title+'" class ="'+this._class+'" target="_blank" rel="nofollow"><img src="'+this.image_livejournal+'" alt="'+title+'" width="33"></a>';  
        document.write(button);  
    },
    drawButton_twitter : function(){
        var name = "Twitter";
        var title = this.hint.replace('%name%',name);
        var button ='<a rel="nofollow" target="_blank" href="http://twitter.com/share?url='+encodeURIComponent(this.link)+'&text='+encodeURIComponent(this.title)+'" title="'+title+'" class ="'+this._class+'" rel="nofollow"><img src="'+this.image_twitter+'" alt="'+title+'"  width="33"></a>';
        document.write(button);
    },
    drawButton_facebook : function(){
        var name = "Facebook";
        var title = this.hint.replace('%name%',name);
        var button ='<a rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u='+encodeURIComponent(this.link)+'" title="'+title+'" class ="'+this._class+'"><img src="'+this.image_facebook+'" alt="'+title+'" width="33"></a>';
        document.write(button);
    },
    drawButton_odnoklassniki : function(){
        var name = "Одноклассники.ru";
        var title = this.hint.replace('%name%',name);
        var button = '<a class="'+this._class+'"  href="'+this.link+'" onclick="ODKL.Share(this);return false;" title="'+title+'" target="_blank" rel="nofollow" ><img src="'+this.image_odnoklassniki+'" alt="'+title+'" width="33"></img></a>';
        document.write(button);
    },
    drawButton_vkontakte : function(){
        var name = "Вконтакте.ru";
        var title = this.hint.replace('%name%',name);
        var button = '<a href="http://vkontakte.ru/share.php?url='+encodeURIComponent(this.link)+'&title='+encodeURIComponent(this.title)+'&description='+encodeURIComponent(this.description)+'&image='+encodeURIComponent(this.image)+'" target="_blank" rel="nofollow" title="'+title+'" class ="'+this._class+'"><img src="'+this.image_vkontakte+'"  width="33" alt="'+title+'"></a>';
        document.write(button);
    },
    drawButton_mail : function(){
        var name = "Мой мир";
        var title = this.hint.replace('%name%',name);
        var button = '<a href="http://connect.mail.ru/share?share_url='+encodeURIComponent(this.link)+'&title='+encodeURIComponent(this.title)+'&imageurl='+encodeURIComponent(this.image)+'" target="_blank" rel="nofollow" title="'+title+'" class ="'+this._class+'"><img src="'+this.image_mail+'"  width="33" alt="'+title+'"></a>';
        document.write(button);
    }
}
