﻿// namespace
if(!window.com) com = new Object();
if(!BDTIC.com) BDTIC.com = new Object();
if(!BDTIC.com.IMSDS) BDTIC.com.IMSDS = new Object();
if(!BDTIC.com.IMSDS.AddThis) BDTIC.com.IMSDS.AddThis = new Object();
if(!BDTIC.com.IMSDS.AddThis.Config) BDTIC.com.IMSDS.AddThis.Config = new Object();

// config
BDTIC.com.IMSDS.AddThis.Config.AddThisScriptID = "BDTIC.com.IMSDS.AddThis.OnDemandJSAddThis";
BDTIC.com.IMSDS.AddThis.Config.AddThisScriptURL = "http://s7.addthis.com/js/250/addthis_widget.js#username=bdtic";
BDTIC.com.IMSDS.AddThis.Config.AddThisBookmarkURL = "http://www.addthis.com/bookmark.php?v=250&amp;username=bdtic";
BDTIC.com.IMSDS.AddThis.Config.AddThisImageURL = "http://s7.addthis.com/static/btn/v2/lg-share-zh.gif";
BDTIC.com.IMSDS.AddThis.Config.TILogoURL = "http://www.bdtic.com/dragonmen.gif";

//
BDTIC.com.IMSDS.AddThis.IncludeJS = function() {
    var head = document.getElementsByTagName("head")[0];
    var script = document.getElementById(BDTIC.com.IMSDS.AddThis.Config.AddThisScriptID);
    if(script) head.removeChild(script);
    script = document.createElement("script");
    script.setAttribute("id", BDTIC.com.IMSDS.AddThis.Config.AddThisScriptID);
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", BDTIC.com.IMSDS.AddThis.Config.AddThisScriptURL);
    head.appendChild(script);
}

BDTIC.com.IMSDS.AddThis.IE6SelectFix = function() {
    var ieVersion = navigator.appVersion.substr( 22, 3 );
    if( (ieVersion == "") || (ieVersion > "6.0") ) return;
    if( document.getElementById( "BDTIC.com.IMSDS.AddThis.IE6SelectFix.ieMat" ) ) return;
    var at15s = document.getElementById( "at15s" );
    if( at15s ) {
        var ieMat = document.createElement( "iframe" );
        if( document.location.protocol == "https:" ) ieMat.src = "http://www.bdtic.com/index.html";
        else if( window.opera != "undefined" ) ieMat.src = "";
        else ieMat.src = "javascript:false";
        ieMat.id = "BDTIC.com.IMSDS.AddThis.IE6SelectFix.ieMat";
        ieMat.scrolling = "no";
        ieMat.frameBorder = "0";
        ieMat.style.width = at15s.offsetWidth + "px";
        ieMat.style.height = at15s.offsetHeight + "px";
        ieMat.style.zIndex = "-1";
        ieMat.style.position = "absolute";
        at15s.insertBefore( ieMat, at15s.childNodes[ 0 ] );
    }
}

BDTIC.com.IMSDS.AddThis.MakeLink = function(url, title) {
    if(url == null) url = "[URL]";
    if(title == null) title = "[TITLE]";
    var html = "<a href=\"" + BDTIC.com.IMSDS.AddThis.Config.AddThisBookmarkURL + "\" ";
    html += "onmouseover=\"var rc = addthis_open(this, '', '" + url.replace("'", "") + "', '" + title.replace("'", "") + "'); BDTIC.com.IMSDS.AddThis.IE6SelectFix(); return rc;\"";
    html += "onmouseout=\"addthis_close()\" ";
    html += "onclick=\"return addthis_sendto()\">";
    html += "<img src=\"" + BDTIC.com.IMSDS.AddThis.Config.AddThisImageURL + "\" alt=\"\" style=\"border-style: none\" />";
    html += "</a>";
    document.write(html);
}
BDTIC.com.IMSDS.AddThis.FilterUnicodeTitle = function(text) {
    if(text == null) return null;
    var filteredText = text;
    filteredText = filteredText.replace(/([^\x01-\x7E])/g, function(s) { return "&amp;#" + s.charCodeAt(0) + ";" });
    return filteredText;
}
BDTIC.com.IMSDS.AddThis.FilterUnicodeContent = function(text) {
    if(text == null) return null;
    var filteredText = text;
    filteredText = filteredText.replace(/([^\x01-\x7E])/g, function(s) { return "&#" + s.charCodeAt(0) + ";" });
    return filteredText;
}

// main
BDTIC.com.IMSDS.AddThis.Main = function(url, title, addthis_share_url, addthis_share_title, addthis_share_content) 
{
    addthis_pub = "texasinstruments";
    if(!window.addthis_config) {
        addthis_config = new Object();
        addthis_config.ui_cobrand = "BDTIC";
        addthis_config.services_compact = "email,print,google,facebook,delicious,twitter,mySpace,digg,live,baidu,more";
        addthis_config.ui_language = "zh";
		addthis_config.ui_click = "true";
    }
    if(!window.addthis_share) {
        addthis_share = new Object();
        addthis_share.title = BDTIC.com.IMSDS.AddThis.FilterUnicodeTitle(document.title);
        if(addthis_share_url != null) addthis_share.url = addthis_share_url;
        if(addthis_share_title != null) addthis_share.title = BDTIC.com.IMSDS.AddThis.FilterUnicodeTitle(addthis_share_title);
        if(addthis_share_content != null) addthis_share.content = BDTIC.com.IMSDS.AddThis.FilterUnicodeContent(addthis_share_content);
        addthis_share.templates = {
            twitter: '{{title}}, check out {{url}}',
            blogger: '<a href="{{url}}">{{title}}</a><br/>{{html}}',
            typepad: '<a href="{{url}}">{{title}}</a><br/>{{html}}',
            wordpress: '<a href="{{url}}">{{title}}</a><br/>{{html}}'
        };
    }
    if(title == null) title = document.title;
    BDTIC.com.IMSDS.AddThis.MakeLink(url, BDTIC.com.IMSDS.AddThis.FilterUnicodeTitle(title));
    var script = document.getElementById(BDTIC.com.IMSDS.AddThis.Config.AddThisScriptID);
    if(!script) BDTIC.com.IMSDS.AddThis.IncludeJS();
}
BDTIC.com.IMSDS.AddThis.TIComMainPages = function() {
    var browserTitle = document.title;
    var metaDesc = "";
    try {
        var metas = document.getElementsByTagName("meta");
        for(var i = 0; i < metas.length; i++) {
            var meta = metas[i];
            if(meta.name == "description") metaDesc = meta.getAttribute("content");
        }
    }
    catch(e) { }
    var title = browserTitle;
    //if(metaDesc.length > 0) title += ": " + metaDesc;
    var content = "";
    if(metaDesc.length > 0) content = metaDesc + "<br>";
    content += '<p><a href="http://BDTIC.com"><img src="' + BDTIC.com.IMSDS.AddThis.Config.TILogoURL + '" alt="TI Logo" style="border-style: none"></a></p>';
    BDTIC.com.IMSDS.AddThis.Main(null, title, null, title, content);
}
BDTIC.com.IMSDS.AddThis.TIComFolderPages = function() {
    var mainHeader = "[TITLE]";
    var subHeader = "";
    try { mainHeader = document.getElementById("mainHeader").firstChild.nodeValue; } catch(e) { }
    try { subHeader = document.getElementById("subHeader").firstChild.nodeValue; } catch(e) { }
    var title = mainHeader;
    //if(subHeader.length > 0) title += ": " + subHeader;
    var content = "";
    if(subHeader.length > 0) content = subHeader + "<br>";
    content += '<p><a href="http://BDTIC.com"><img src="' + BDTIC.com.IMSDS.AddThis.Config.TILogoURL + '" alt="TI Logo" style="border-style: none"></a></p>';
    BDTIC.com.IMSDS.AddThis.Main(null, title, null, title, content);
}

//
//BDTIC.com.IMSDS.AddThis.Main(null, null, null, null, null);
BDTIC.com.IMSDS.AddThis.TIComMainPages();
//BDTIC.com.IMSDS.AddThis.TIComFolderPages();
