TPConnect.app_url   = 'http://www.typepad.com/';
//http://profile.typepad.com/
TPConnect.embed_src = 'http://profile.typepad.com/services/embed/tpc/6a00d83451d48a69e200d8341c738d53ef/thread.js';
TPConnect.blog_xid  = '6a00d83451d48a69e200d8341c738d53ef';
TPConnect.post_xid = '6a00d83451d48a69e2010536c227b0970b';
TPConnect.user_xid = '';

//isolate our trivial js
( function() {
var tpe_url = TPConnect.tpc_url;
var tpe_title = TPConnect.tpc_title;
var tpe_message = TPConnect.tpc_message;
    
/* debug ==> 0 */

var tpe_referrer_uri = 'http://www.backinskinnyjeans.com/2009/01/lunging-your-way-to-the-bank.html';
var tpe_signin_uri = 'http://www.typepad.com/sitelogin?uri=http%3A%2F%2Fwww.backinskinnyjeans.com%2F2009%2F01%2Flunging-your-way-to-the-bank.html&fp=537789c2efb3d37fa37749de2090bfd7&view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=profile';
var tpe_host_url = 'http://profile.typepad.com/'; // can both these be in the same form?
var tpe_user_xid = '';
var tpe_sort = '';

//console.log("user xid = %s", tpe_user_xid);
//console.log("blog xid = %s", TPConnect.blog_xid);
//console.log("post xid = %s", TPConnect.post_xid);

////// Set up all query parameters

var tpe_href = window.location.href;
var tpe_date = new Date();
var tpe_hashIndex = tpe_href.indexOf('#');
if(tpe_hashIndex != -1) {
        tpe_href = tpe_href.substring(0, tpe_hashIndex);
}

if(typeof(tpe_url) == 'undefined') {
    tpe_url = tpe_href;
}
if(typeof(tpe_title) == 'undefined') {
    tpe_title = document.title || '';
}

if(typeof(tpe_message) == 'undefined') {
    tpe_message = '';
} else {
    var tpe_isUTF8 = false;
    if(/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { // if IE
            for(var i=0; i<tpe_message.length; i++) {
                    if(tpe_message.charCodeAt(i) > 256) {
                            tpe_isUTF8 = true;
                            break;
                    }
            }               
    }
    if(tpe_isUTF8) {
            tpe_message = '';
    } else {
            if(tpe_message.length > 400) {
                    tpe_message = tpe_message.substring(0, tpe_message.indexOf(' ', 350));
            }
    }
}

if(typeof(tpe_show_count) == 'undefined') {
        tpe_show_count = -1;
}
if(typeof(tpe_sort) == 'undefined') {
        tpe_sort = '';
}
if(typeof(tpe_show_threshold) == 'undefined') {
        tpe_show_threshold = 0;
}
if(typeof(tpe_container_id) == 'undefined') {
        tpe_container_id = 'tpc_thread';
}
if(typeof(tpe_category_id) == 'undefined') {
        tpe_category_id = '';
}
if(typeof(tpe_developer) == 'undefined') {
        tpe_developer = '';
}
if(typeof(tpe_iframe_css) == 'undefined') {
        tpe_iframe_css = '';
}

//<link rel="stylesheet" href="http://" type="text/css" media="screen" />
var tpe_style = document.createElement('link');
tpe_style.setAttribute('rel','stylesheet');
tpe_style.href = 'http://static.typepad.com/.shared:v32.8:typepad:en_us/css/connect/typepad/screen.css';
tpe_style.type = 'text/css';
tpe_style.media = 'screen';
document.getElementsByTagName('head')[0].appendChild(tpe_style);

//<link rel="stylesheet" href="http://" type="text/css" media="screen" />
var tpe_style = document.createElement('link');
tpe_style.setAttribute('rel','stylesheet');
tpe_style.href = 'http://static.typepad.com/.shared:v32.8:typepad:en_us/css/flyout-types.css';
tpe_style.type = 'text/css';
tpe_style.media = 'screen';
document.getElementsByTagName('head')[0].appendChild(tpe_style);

///// Setup some important divs that we'll use to build and grow the document
/// One DIV to hold them ALL
//<div id="tpe-content"></div>
var tpe_dataContainer = document.createElement('div');
tpe_dataContainer.id = 'tpe-content';
document.getElementById(tpe_container_id).appendChild(tpe_dataContainer);

//<div id="comments-loading"><img src="/.shared/images/spinner.gif" /></div>
var tpe_comments_loading = document.createElement('div');
tpe_comments_loading.id = 'comments-loading';
tpe_dataContainer.appendChild(tpe_comments_loading);

//<div class="comments-content" id="tpe-comments-content"></div>
var tpe_contentContainer = document.createElement('div');
tpe_contentContainer.id = 'tpe-comments-content';
tpe_dataContainer.appendChild(tpe_contentContainer);

//<div class="comments-pager" id="comments-pager"></div>
var tpe_comments_pager = document.createElement('div');
tpe_comments_pager.id = 'comments-pager';
tpe_dataContainer.appendChild(tpe_comments_pager);

//<div class="comments-signin" id="comments-signin"></div>
var tpe_comments_signin = document.createElement('div');
tpe_comments_signin.id = 'comments-signin';
tpe_comments_signin.innerHTML = '\n\n<p>Comments on this post are closed.<\/p>\n\n';
tpe_dataContainer.appendChild(tpe_comments_signin);

//<div class="comments-flyout" id="comments-flyout"></div>
var tpe_comments_flyout = document.createElement('div');
tpe_comments_flyout.id = 'comments-flyout';
tpe_dataContainer.appendChild(tpe_comments_flyout);

//<iframe id="tpc-flyout" src="http://static.typepad.com/.shared:v32.8:typepad:en_us//services/connect/flyout?user_id=xxx"></iframe>
var tpe_blogside_flyout = document.createElement('iframe');
tpe_blogside_flyout.id = "tpc-flyout";
tpe_blogside_flyout.className = "tpc-flyout hiddenBox";
tpe_blogside_flyout.scrolling = "no";
tpe_blogside_flyout.frameBorder = "0";
tpe_blogside_flyout.border = "0";
tpe_blogside_flyout.allowtransparency = "true";
tpe_comments_flyout.appendChild(tpe_blogside_flyout);





//<div class="comments-action" id="comments-action">
var tpe_action_iframe = document.createElement('div');
tpe_action_iframe.id = 'comments-action';
tpe_action_iframe.innerHTML = '<iframe id="action-iframe" width="0" height="0" frameborder="0"></iframe>';
tpe_dataContainer.appendChild(tpe_action_iframe);

var tpe_comments_logo = document.createElement('div');
tpe_comments_logo.innerHTML = '<a href="http://www.typepad.com/"><img style="margin-bottom:20px;border:none;" src="http://static.typepad.com/.shared:v32.8:typepad:en_us/images/tp-powered-badge.png" alt="powered by TypePad"/></a>';
tpe_dataContainer.appendChild(tpe_comments_logo);

///// Setup prerequisite static scripts

var tpe_scripts = document.createElement('script');
tpe_scripts.type = 'text/javascript';
tpe_scripts.src  = 'http://static.typepad.com/.shared:v32.8:typepad:en_us/js/yui/yahoo-dom-event.js?/js/yui/connection-min.js,/js/yui/json-min.js,/js/jsonrpc-client.js,/js/client-tc.js';
tpe_dataContainer.appendChild(tpe_scripts);


var allCommentsEl = document.getElementById('all-comments');
var commentsEl = tpe_contentContainer;

///// Finally, make the first call to build the comment thread
var tpe_script = document.createElement('script');
tpe_script.type = 'text/javascript';
tpe_script.src  = TPConnect.embed_src
                   + '?asset_id=' + TPConnect.post_xid
                   + '&d=0'
                   + '&p=1'
                   + '&permalink='       + encodeURIComponent(tpe_url)
                   + '&message='         + encodeURIComponent(tpe_message)
                   + '&title='           + encodeURIComponent(tpe_title)
                   + '&show_count='      + encodeURIComponent(tpe_show_count)
                   + '&sort_order='      + encodeURIComponent(tpe_sort)
                   + '&show_threshold='  + encodeURIComponent(tpe_show_threshold)
                   + '&category_id='     + encodeURIComponent(tpe_category_id)
                   + '&developer='       + encodeURIComponent(tpe_developer)
                   + '&ifrs='            + encodeURIComponent(tpe_iframe_css)
                   + '&ts='              + tpe_date.getTime();

if ( window.location.hash ) {
    var found = window.location.hash.match( /^#comment-(6a[a-z0-9]{32})$/ );
    if ( found )
        tpe_script.src += '&posted_comment=' + found[ 1 ];
}
tpe_dataContainer.appendChild(tpe_script);

} )();
