function ylc_urlencode(str) {
    str = escape(str);
    str = str.replace(/\+/g, '%2B');
    str = str.replace(/%20/g, '+');
    str = str.replace(/\*/g, '%2A');
    str = str.replace(/\//g, '%2F');
    str = str.replace(/@/g, '%40');
    str = str.replace(/#/g, '%23');
    return str;
}
var __d = function (msg) {
    if (document.getElementById("ylc_debug")) {
        document.getElementById("ylc_debug").innerHTML = document.getElementById("ylc_debug").innerHTML + "<br>" + msg;
        document.getElementById("ylc_debug").scrollTop = document.getElementById("ylc_debug").scrollHeight;
    }
};
var ylc_getdatediff = function (now_ms, gmt) {
    var dt_ms = Date.parse(gmt);
    var delta = now_ms - dt_ms;
    delta = Math.floor(delta / 1000);
    if (delta > 86400) {
        return '' + Math.floor(delta / 86400) + ' days ago';
    } else if (delta > 3600) {
        return '' + Math.floor(delta / 3600) + ' hours ' + Math.floor(delta / 60) + ' minutes ago';
    } else if (delta > 60) {
        return '' + Math.floor(delta / 60) + ' minutes ' + (delta % 60) + ' seconds ago';
    } else {
        return '' + (delta % 60) + ' seconds ago';
    }
};
var ylc_cleanup = function () {
    if (ylc_widget_refresh_interval > 0) {
        clearTimeout(ylc_settings[ylc_curidx]['ylc_timer']);
        ylc_settings[ylc_curidx]['ylc_timer'] = setTimeout("ylc_refresh_clbk(" + ylc_curidx + ");", (ylc_widget_refresh_interval * 1000) + Math.floor(Math.random() * 2000));
    }
    ylc_widget_refresh_interval = '';
    ylc_divname = '';
    ylc_width = '';
    ylc_height = '';
    ylc_scroll = '';
    ylc_widget_background = '';
    ylc_widget_border = '';
    ylc_tweet_textcolor = '';
    ylc_tweet_linkcolor = '';
    ylc_tweet_background = '';
    ylc_tweet_border = '';
    ylc_tweet_margin = '';
    ylc_tweet_fontsize = '';
    ylc_tweet_lang = '';
    ylc_hide_img = '';
    ylc_num_tweets = '';
    ylc_search = '';
    ylc_pre_html = '';
    ylc_post_html = '';
    ylc_mid_html = '';
    ylc_center_widget = '';
    ylc_tweet_newbackground = '';
    ylc_lastsearch = '';
    __d(ylc_curidx + " RELEASED the lock...");
    ylc_lock = -1;
};
var ylc_searchfunc_pre1 = function (arr) {
    var x = 1;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre2 = function (arr) {
    var x = 2;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre3 = function (arr) {
    var x = 3;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre4 = function (arr) {
    var x = 4;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre5 = function (arr) {
    var x = 5;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre6 = function (arr) {
    var x = 6;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre7 = function (arr) {
    var x = 7;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre8 = function (arr) {
    var x = 8;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre9 = function (arr) {
    var x = 9;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc_pre10 = function (arr) {
    var x = 10;
    if (x != ylc_lock) {
        __d(x + ": i don't have the lock! aborting!!");
        return false;
    }
    ylc_searchfunc(arr);
};
var ylc_searchfunc = function (arr) {
    clearTimeout(ylc_lock_timeout_timer);
    var ret = ylc_pre_html;
    var i = 0;
    var bg;
    var wasnew = 0;
    var now = new Date();
    var now_ms = now.getTime();
    if ((!arr || !arr.results[0]) && ylc_settings[ylc_curidx]['ylc_lastid'] == 0) {
        document.getElementById(ylc_divname).innerHTML = '0 Results to display.  Enter new search terms.';
        ylc_cleanup();
        return false;
    }
    if ((!arr || !arr.results[0]) && (ylc_lastsearch == ylc_search)) {
        __d(ylc_curidx + " --no new tweets--");
        ylc_cleanup();
        return false;
    }
    ret = ret + '<div style="color:' + ylc_tweet_textcolor + ';padding:3px 8px 5px 8px;' + ylc_results_style_misc + '">';
    var num_newtweets;
    if (!arr || !arr.results[0]) {
        num_newtweets = 0;
    } else {
        num_newtweets = arr.results.length;
    }
    var newptr = (ylc_settings[ylc_curidx]['ylc_ringptr'] - num_newtweets + 100) % 100;
    ylc_settings[ylc_curidx]['ylc_ringptr'] = newptr;
    __d(ylc_curidx + " num_newtweets " + num_newtweets);
    __d(ylc_curidx + " newptr " + newptr);
    for (i = 0; i < num_newtweets; i++) {
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100] = new Array(6);
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['user'] = arr.results[i].from_user;
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['tweet'] = arr.results[i].text;
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['tstamp'] = new Date(arr.results[i].created_at);
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['tstamp'] = ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['tstamp'].toLocaleString();
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['img'] = arr.results[i].profile_image_url;
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['id'] = arr.results[i].id;
        ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['search'] = ylc_search;
    }
    for (i = 0; i < ylc_num_tweets; i++) {
        if (!ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100] || ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['search'] != ylc_search) break;
        var user = ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['user'];
        var tweet = ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['tweet'];
        var tstamp = ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['tstamp'];
        var img = ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['img'];
        var tid = ylc_settings[ylc_curidx]['ylc_tweets'][(newptr + i) % 100]['id'];
        if (tid > ylc_settings[ylc_curidx]['ylc_lastid'] && ylc_settings[ylc_curidx]['ylc_lastid'] != 0) {
            bg = ylc_tweet_newbackground;
            wasnew = 1;
        } else {
            bg = ylc_tweet_background
        }
        var re = new RegExp("(([a-zA-Z]+:\/\/)([a-zA-Z][a-zA-Z0-9_\.-]*[a-zA-Z]{2,6})([a-zA-Z0-9~\#\/\._\?\&%-=]*[a-zA-Z0-9~\#\/_\?\&%-=]))", "g");
        tweet = tweet.replace(re, '<a style="' + ylc_tweet_linkcolor + '" target="_new" href=$1 >$1</a>');
        re = new RegExp("@([a-zA-Z0-9_]+)", "g");
        tweet = tweet.replace(re, '@<a style="' + ylc_tweet_linkcolor + '" target="_new" href=http://twitter.com/$1 >$1</a>');
        re = new RegExp("#([a-zA-Z0-9_]+)", "g");
        tweet = tweet.replace(re, '<a style="' + ylc_tweet_linkcolor + '" target="_new" href=http://search.twitter.com/search?q=%23$1 >#$1</a>');
        tweet = tweet.replace(/&/g, '&');
        ret = ret + '<div align="left" style="background:' + bg + ';font-size:' + ylc_tweet_fontsize + ';border:' + ylc_tweet_border + ';padding:2px;margin:' + ylc_tweet_margin + ';' + ylc_tweet_style_misc;
        if (tid > ylc_settings[ylc_curidx]['ylc_lastid'] && ylc_settings[ylc_curidx]['ylc_lastid'] != 0 && typeof(jQuery) == 'function' && typeof($) == 'function') {
            ret = ret + 'display:none;';
        }
        ret = ret + '" ';
        if (tid > ylc_settings[ylc_curidx]['ylc_lastid'] && ylc_settings[ylc_curidx]['ylc_lastid'] != 0) {
            ret = ret + ' class="ylc_new_tweet" ';
        }
        ret = ret + '>';
        if (!ylc_hide_img) {
            ret = ret + '<div style="float:left; width:25px; margin-right:6px; padding-top:2px;"><img src=' + img + ' height=' + ylc_img_size + ' width=' + ylc_img_size + ' align=left /></div>';
        }
        ret = ret + '<div style="float:left; width:230px;"><b><a style="' + ylc_tweet_linkcolor + '" target="_new" href=http://twitter.com/' + user + '>' + user + '</a></b>: ' + tweet + '<br><span class="ylc_tstamp" style="font-size:10px; color:#999999;">' + tstamp;
        ret = ret + '</span></div>';
        re = new RegExp("(http://twitpic.com/)([0-9a-zA-Z]*)");
        var m = re.exec(tweet);
        if (!m || m.length == 0 || m[2] == "photos" || m[2] == "photo" || m[2] == "tag") {} else {
            ret = ret + '<center><a href="http://twitpic.com/' + m[2] + '" target="_blank"><img src="http://twitpic.com/show/thumb/' + m[2] + '" border=0 height=150 width=150></a></center>';
        }
        ret = ret + '<div style="clear:both;"></div></div>';
        if (i < ylc_num_tweets - 1) ret = ret + ylc_mid_html;
    }
    ret = ret + ylc_post_html;
    ret = ret + '</div>';
    ylc_settings[ylc_curidx]['ylc_lastid'] = (arr.results[0] ? arr.results[0].id : ylc_settings[ylc_curidx]['ylc_lastid']);
    ylc_settings[ylc_curidx]['ylc_lastsearch'] = (wasnew ? '' : ylc_search);
    document.getElementById(ylc_divname).innerHTML = ret;
    if (typeof(jQuery) == 'function' && typeof($) == 'function') {
        $('#' + ylc_divname + ' .ylc_new_tweet').fadeIn("slow");
    }
    ylc_cleanup();
};
ylc_refresh_clbk = function (i) {
    if (ylc_lock != -1) {
        if (ylc_lock == i) {
            __d(i + ": trying to double lock!! aborting...");
            return false;
        }
        __d(i + ": " + ylc_lock + " already has lock, backing off...");
        setTimeout("ylc_refresh_clbk(" + i + ");", 1000 + Math.floor(Math.random() * 1000));
        return false;
    }
    __d(i + " GRABBED lock...");
    ylc_lock = i;
    ylc_lock_timeout_timer = setTimeout("ylc_lock_timeout(" + i + ");", 6500);
    if (ylc_lock != i) {
        setTimeout("ylc_refresh_clbk(" + i + ");", 1000 + Math.floor(Math.random() * 1000));
        return false;
    }
    ylc_divname = ylc_settings[i]['ylc_divname'];
    ylc_curidx = ylc_settings[i]['ylc_curidx'];
    ylc_width = ylc_settings[i]['ylc_width'];
    ylc_height = ylc_settings[i]['ylc_height'];
    ylc_scroll = ylc_settings[i]['ylc_scroll'];
    ylc_widget_background = ylc_settings[i]['ylc_widget_background'];
    ylc_widget_border = ylc_settings[i]['ylc_widget_border'];
    ylc_widget_refresh_interval = ylc_settings[i]['ylc_widget_refresh_interval'];
    ylc_tweet_textcolor = ylc_settings[i]['ylc_tweet_textcolor'];
    ylc_tweet_linkcolor = ylc_settings[i]['ylc_tweet_linkcolor'];
    ylc_tweet_background = ylc_settings[i]['ylc_tweet_background'];
    ylc_tweet_newbackground = ylc_settings[i]['ylc_tweet_newbackground'];
    ylc_tweet_border = ylc_settings[i]['ylc_tweet_border'];
    ylc_tweet_margin = ylc_settings[i]['ylc_tweet_margin'];
    ylc_tweet_fontsize = ylc_settings[i]['ylc_tweet_fontsize'];
    ylc_tweet_lang = ylc_settings[i]['ylc_tweet_lang'];
    ylc_hide_img = ylc_settings[i]['ylc_hide_img'];
    ylc_big_img = ylc_settings[i]['ylc_big_img'];
    ylc_img_size = ylc_settings[i]['ylc_img_size'];
    ylc_num_tweets = ylc_settings[i]['ylc_num_tweets'];
    ylc_search = ylc_settings[i]['ylc_search'];
    ylc_lastsearch = ylc_settings[i]['ylc_lastsearch'];
    ylc_pre_html = ylc_settings[i]['ylc_pre_html'];
    ylc_post_html = ylc_settings[i]['ylc_post_html'];
    ylc_mid_html = ylc_settings[i]['ylc_mid_html'];
    ylc_center_widget = ylc_settings[i]['ylc_center_widget'];
    ylc_widget_style_misc = ylc_settings[i]['ylc_widget_style_misc'];
    ylc_results_style_misc = ylc_settings[i]['ylc_results_style_misc'];
    ylc_tweet_style_misc = ylc_settings[i]['ylc_tweet_style_misc'];
    ylc_lastid = ylc_settings[i]['ylc_lastid'];
    if (ylc_lock != i) {
        __d(i + " failed 2nd lock check..." + ylc_lock + " has it...");
        setTimeout("ylc_refresh_clbk(" + i + ");", 1000 + Math.floor(Math.random() * 1000));
        return false;
    }
    __d(i + " lastid is " + ylc_settings[i].ylc_lastid);
    var sc = document.createElement('script');
    var h = document.getElementsByTagName('head')[0];
    sc.language = 'javascript';
    sc.type = 'text/javascript';
    sc.src = 'http://search.twitter.com/search.json?callback=ylc_searchfunc_pre' + ylc_curidx + '&' + ylc_tweet_lang + 'q=' + ylc_urlencode(ylc_search) + '&rpp=' + ylc_num_tweets + '&since_id=' + ylc_settings[i].ylc_lastid + '&rand=' + Math.floor(Math.random() * 10000000);
    h.appendChild(sc);
};
function ylc_lock_timeout(i) {
    __d("!!! forcing UNLOCK for " + i + "");
    ylc_cleanup();
}
var ylc_idx;
var ylc_curidx;
var ylc_lock;
var ylc_lock_timeout_timer;
var ylc_settings;
var ylc_divname;
var ylc_width;
var ylc_height;
var ylc_scroll;
var ylc_widget_background;
var ylc_widget_border;
var ylc_widget_refresh_interval;
var ylc_tweet_textcolor;
var ylc_tweet_linkcolor;
var ylc_tweet_background;
var ylc_tweet_newbackground;
var ylc_tweet_border;
var ylc_tweet_margin;
var ylc_tweet_fontsize;
var ylc_tweet_lang;
var ylc_hide_img;
var ylc_big_img;
var ylc_img_size;
var ylc_num_tweets;
var ylc_search;
var ylc_lastsearch;
var ylc_pre_html;
var ylc_post_html;
var ylc_mid_html;
var ylc_center_widget;
var ylc_widget_style_misc;
var ylc_results_style_misc;
var ylc_tweet_style_misc;
var ylc_trk;
var _gat;
if (!ylc_settings) ylc_settings = new Array(0);
if (!ylc_idx) ylc_idx = 0;
if (!ylc_lock) ylc_lock = -1;
if (!ylc_divname) ylc_divname = 'ylc_widget';
if (!ylc_width) ylc_width = '300px';
if (!ylc_height) ylc_height = '400px';
if (!ylc_scroll || ylc_scroll == 'yes') ylc_scroll = 'overflow:auto;';
else {
    ylc_scroll = '';
}
if (!ylc_widget_background) ylc_widget_background = '#fff';
if (!ylc_widget_border) ylc_widget_border = '1px solid #aaa';
if (!ylc_widget_refresh_interval) ylc_widget_refresh_interval = 10;
if (ylc_widget_refresh_interval < 8 && ylc_widget_refresh_interval != 0) ylc_widget_refresh_interval = 8;
if (!ylc_tweet_textcolor) ylc_tweet_textcolor = '#000';
if (!ylc_tweet_linkcolor) ylc_tweet_linkcolor = 'color:#00f;';
else {
    ylc_tweet_linkcolor = 'color:' + ylc_tweet_linkcolor + ';';
}
if (!ylc_tweet_background) ylc_tweet_background = '#f8f8f8';
if (!ylc_tweet_newbackground) ylc_tweet_newbackground = ylc_tweet_background;
if (!ylc_tweet_border) ylc_tweet_border = '1px solid #aaa';
if (!ylc_tweet_margin) ylc_tweet_margin = '1px';
if (!ylc_tweet_fontsize) ylc_tweet_fontsize = '14px';
if (!ylc_search) ylc_search = 'twitter';
else {
    ylc_search = ylc_search;
}
if (!ylc_num_tweets) ylc_num_tweets = 20;
if (!ylc_pre_html) ylc_pre_html = '';
if (!ylc_post_html) ylc_post_html = '';
if (!ylc_mid_html) ylc_mid_html = '';
if (ylc_center_widget == 'yes') ylc_center_widget = 'margin: 0 auto;';
else {
    ylc_center_widget = '';
}
if (!ylc_tweet_lang) ylc_tweet_lang = '';
else {
    ylc_tweet_lang = 'lang=' + ylc_tweet_lang + '&';
}
if (!ylc_widget_style_misc) ylc_widget_style_misc = '';
if (!ylc_results_style_misc) ylc_results_style_misc = '';
if (!ylc_tweet_style_misc) ylc_tweet_style_misc = '';
if (ylc_big_img == 'yes') ylc_img_size = 48;
else {
    ylc_img_size = 24;
}
if (ylc_hide_img == 'yes') ylc_hide_img = 1;
else {
    ylc_hide_img = 0;
    ylc_tweet_style_misc = ylc_tweet_style_misc + ';min-height:' + (ylc_img_size + 4) + 'px;';
}
ylc_idx++;
ylc_curidx = ylc_idx;
ylc_settings[ylc_idx] = new Array(40);
ylc_settings[ylc_idx]['ylc_divname'] = ylc_divname;
ylc_settings[ylc_idx]['ylc_curidx'] = ylc_curidx;
ylc_settings[ylc_idx]['ylc_width'] = ylc_width;
ylc_settings[ylc_idx]['ylc_height'] = ylc_height;
ylc_settings[ylc_idx]['ylc_scroll'] = ylc_scroll;
ylc_settings[ylc_idx]['ylc_widget_background'] = ylc_widget_background;
ylc_settings[ylc_idx]['ylc_widget_border'] = ylc_widget_border;
ylc_settings[ylc_idx]['ylc_widget_refresh_interval'] = ylc_widget_refresh_interval;
ylc_settings[ylc_idx]['ylc_tweet_textcolor'] = ylc_tweet_textcolor;
ylc_settings[ylc_idx]['ylc_tweet_linkcolor'] = ylc_tweet_linkcolor;
ylc_settings[ylc_idx]['ylc_tweet_background'] = ylc_tweet_background;
ylc_settings[ylc_idx]['ylc_tweet_newbackground'] = ylc_tweet_newbackground;
ylc_settings[ylc_idx]['ylc_tweet_border'] = ylc_tweet_border;
ylc_settings[ylc_idx]['ylc_tweet_margin'] = ylc_tweet_margin;
ylc_settings[ylc_idx]['ylc_tweet_fontsize'] = ylc_tweet_fontsize;
ylc_settings[ylc_idx]['ylc_tweet_lang'] = ylc_tweet_lang;
ylc_settings[ylc_idx]['ylc_hide_img'] = ylc_hide_img;
ylc_settings[ylc_idx]['ylc_big_img'] = ylc_big_img;
ylc_settings[ylc_idx]['ylc_img_size'] = ylc_img_size;
ylc_settings[ylc_idx]['ylc_num_tweets'] = ylc_num_tweets;
ylc_settings[ylc_idx]['ylc_search'] = ylc_search;
ylc_settings[ylc_idx]['ylc_lastsearch'] = ylc_search;
ylc_settings[ylc_idx]['ylc_pre_html'] = ylc_pre_html;
ylc_settings[ylc_idx]['ylc_post_html'] = ylc_post_html;
ylc_settings[ylc_idx]['ylc_mid_html'] = ylc_mid_html;
ylc_settings[ylc_idx]['ylc_center_widget'] = ylc_center_widget;
ylc_settings[ylc_idx]['ylc_widget_style_misc'] = ylc_widget_style_misc;
ylc_settings[ylc_idx]['ylc_results_style_misc'] = ylc_results_style_misc;
ylc_settings[ylc_idx]['ylc_tweet_style_misc'] = ylc_tweet_style_misc;
ylc_settings[ylc_idx]['lastid'] = 0;
ylc_settings[ylc_idx]['ylc_timer'] = '';
ylc_settings[ylc_idx]['ylc_tweets'] = new Array(100);
ylc_settings[ylc_idx]['ylc_ringptr'] = 0;
document.write('<div style="width:' + ylc_width + ';height:' + ylc_height + ';' + ylc_center_widget + ';padding:0px;margin:0px;' + '">');
document.write('<div id=' + ylc_divname + ' style="' + ylc_scroll + '' + ylc_center_widget + 'width:auto;height:' + ylc_height + ';background:' + ylc_widget_background + ';' + 'border:' + ylc_widget_border + ';' + ylc_widget_style_misc + '">');
document.write('<a href="http://whos.amung.us/stats/3iffs50u4co5/"><img src="http://whos.amung.us/widget/3iffs50u4co5.png" width="1" height="1" border="0" title="" /></a>');
document.write('</div>');
document.write('</div>');
if (ylc_search != '-') {
    document.write('<script src="http://search.twitter.com/search.json?callback=ylc_searchfunc&' + ylc_tweet_lang + 'q=' + ylc_urlencode(ylc_search) + '&rpp=' + ylc_num_tweets + '&since_id=0" type="text/javascript"></script>');
} else {}