var LittleTritone = function(d, set) {var $ = function(id) { return document.getElementById(id); };if (!set.scname) {return;};var jumpURL = 'http://twitter.com/' + set.scname;var baseURL = 'http://twitter.com/statuses/user_timeline.json?screen_name=' + set.scname + '&callback=JSONP.';var contID = set.contID || 'LittleTritoneDisplayPane';var clWidth       = set.clWidth || 180;var clLabelImage  = set.clLabelImage || 'http://lab.f-sp.net/_api/lt/pts/w/label.gif';var clLabelWidth  = set.clLabelWidth || 11;var clLabelMargin = set.clLabelMargin || 5;var clBorderColor = set.clBorderColor || '#888888';var clBGColor     = set.clBGColor || '#ffffff';var hdFontSize         = set.hdFontSize || 10;var hdMargin           = set.htMargin || 5;var hdLinkColor        = set.hdLinkColor || '#51c051';var hdCreatedTimeColor = set.hdCreatedTimeColor || '#ada39d';var tlHeight     = set.tlHeight || 194;var tlUpButton   = set.tlUpButton || 'http://lab.f-sp.net/_api/lt/pts/w/green_bu.gif';var tlDownButton = set.tlDownButton || 'http://lab.f-sp.net/_api/lt/pts/w/green_bd.gif';var tlButtonSize = set.tlButtonSize || 10;var tlMargin     = set.tlMargin || 5;var tlIconWidth  = set.tlIconWidth || 42;var tlIconHeight = set.tlIconHeight || 42;var tlBGColor    = set.tlBGColor || '#efefef';var tlFontColor  = set.tlFontColor || '#000000';var tlFontSize   = set.tlFontSize || 10;var tlLinkColor  = set.tlLinkColor;var tlJustify    = set.tlJustify;var ftTextColor = set.ftTextColor || '#c1c1c1';if (tlJustify === void(0)) {tlJustify = true;};var maxURLLength    = set.maxURLLength || 20;var updateInterval  = set.updateInterval || 120000;var scname = set.scname;var script_id;var current_stream = [];var current_itemID = 0;var currenttime;var timerID;var loaded = false;var username;var usericon;var create_time;var canvas;var btUp;var btDown;if (updateInterval < 60000) {updateInterval = 60000;};var showTL = function(){var url = get_jsonp_url('show');if (!url) {return;};JSONP.get(url);};var updateTL = function(){var url = get_jsonp_url('update');if (!url) {return;};JSONP.get(url);};var get_jsonp_url = function(cbname){if (!cbname) {return;};return baseURL + cbname;};var internal_show_timeline = function(json){$(contID).style.width = clWidth + 'px';var cl = d.createElement('div');with(cl.style) {border          = clBorderColor + ' 1px solid';backgroundColor = clBGColor;};$(contID).appendChild(cl);var lb = d.createElement('img');set_float(lb, 'left');lb.src = clLabelImage;with(lb.style) {margin      = clLabelMargin + 'px';marginRight = clLabelMargin - 1 + 'px';};cl.appendChild(lb);var div = d.createElement('div');set_float(div, 'right');with(div.style) {backgroundColor = tlBGColor;width           =  (clWidth - clLabelWidth - clLabelMargin * 3 - 2) + 'px';height          = tlHeight + 'px';margin          = clLabelMargin + 'px';marginLeft      = '0px';marginRight     = clLabelMargin + 1 + 'px';};var cv = d.createElement('div');with(cv.style) {margin     = tlMargin + 'px';fontSize   = tlFontSize + 'px';lineHeight = Math.round(tlFontSize * 1.5) + 'px';color      = tlFontColor;};if (tlJustify) {cv.style.textAlign = 'justify';};canvas = d.createElement('div');usericon = d.createElement('div');set_float(usericon, 'left');with(usericon.style) {width       = tlIconWidth + 'px';marginRight = tlMargin + 'px';};cv.appendChild(usericon);cv.appendChild(canvas);div.appendChild(cv);cl.appendChild(div);var btp = d.createElement('div');with(btp.style) {clear        = 'both';textAlign    = 'right';marginRight  = clLabelMargin + 1 + 'px';marginBottom = clLabelMargin + 'px';};btUp = d.createElement('img');btUp.src     = tlUpButton;btUp.onclick = streamScrollUp;btUp.style.marginRight = clLabelMargin + 'px';btDown = d.createElement('img');btDown.src     = tlDownButton;btDown.onclick = streamScrollDown;btp.appendChild(btUp);btp.appendChild(btDown);cl.appendChild(btp);var ft = d.createElement('div');with(ft.style) {padding     = hdMargin + 'px';paddingLeft = (clLabelWidth + clLabelMargin) + 'px';borderTop   = clBorderColor + ' 1px dotted';fontSize    = hdFontSize + 'px';lineHeight  = Math.round(hdFontSize * 1.5) + 'px';fontWeight  = 'bold';};username = d.createElement('div');create_time = d.createElement('div');create_time.style.color = hdCreatedTimeColor;ft.appendChild(username);ft.appendChild(create_time);cl.appendChild(ft);var ltt = d.createElement('div');with(ltt.style) {backgroundColor = clBorderColor;textAlign       = 'center';fontSize        = hdFontSize + 'px';lineHeight      = hdFontSize + 'px';};var logo = d.createElement('img');logo.src = 'http://lab.f-sp.net/_api/lt/pts/footlabel.gif';logo.style.border = 'none';var anc = d.createElement('a');anc.setAttribute('href', 'http://lab.f-sp.net/');anc.setAttribute('target', '_blank');with(anc.style) {color          = ftTextColor;textDecoration = 'none';};anc.appendChild(logo);ltt.appendChild(anc);cl.appendChild(ltt);json2tl(json);};var internal_update_timeline = function(json){json2tl(json);};var set_float = function(obj, dir){if (d.all) {obj.style.styleFloat = dir;}else {obj.style.cssFloat = dir;};};var set_user_info = function(obj){var img = d.createElement('img');img.src = obj.profile_image_url;with(img.style) {width  = tlIconWidth + 'px';height = tlIconHeight + 'px';border = 'none';};var anc    = d.createElement('a');anc.href   = jumpURL;anc.target = '_blank';anc.appendChild(img);usericon.appendChild(anc);username.innerHTML = "<a href='" + jumpURL + "' target='_blank' style='text-decoration:none; color:" + hdLinkColor + ";'>" + obj.name + " (" + scname + ")</a>";};var json2tl = function(json){if (!loaded) {set_user_info(json[0].user);};current_stream = [];current_itemID = 0;var date = new Date();currenttime = date.getTime();var i;for (i=0; i<json.length; i++) {var tlitem = json[i].text;var url = tlitem.match(/http:\/\/[\x21-\x7e]+/gi);if (url) {url = url[0];var lt = "<a href='" + url + "' target='_blank'";if (tlLinkColor) {lt += " style='color:" + tlLinkColor + "'";};lt += ">";if (url.length > maxURLLength) {url = url.substring(0, maxURLLength) + '...';};lt += url + "</a>";tlitem = tlitem.replace(/http:\/\/[\x21-\x7e]+/gi, lt);};var created = json[i].created_at.split(' ');created     = created[1] + ', ' + created[2] + ' ' + created[5] + ' ' + created[3] + ' GMT' + created[4];created     = Date.parse(created);var dt      = created;created     = Math.round((currenttime - created) * 0.001);if (created < 5) {created = '5秒以内';}else if (created < 30) {created = '30秒前';}else if (created < 60) {created = '1分前';}else {created = Math.round(created / 60);if (created < 60) {created = created + '分前';}else {var hour   = Math.floor(created / 60);var minute = created - hour * 60;if (hour < 24) {created = hour + '時間' + minute + '分前';}else {created = Math.round(hour / 24);if (created == 1) {created = '昨日';}else {created = created + '日前';};};};};current_stream[i] = [tlitem, created];};loaded = true;show_current_item();};var show_current_item = function(){canvas.innerHTML      = current_stream[current_itemID][0];create_time.innerHTML = current_stream[current_itemID][1];if (current_itemID < 1) {btUp.style.visibility = 'hidden';}else {btUp.style.visibility = 'visible';};if (current_itemID >= current_stream.length - 1) {btDown.style.visibility = 'hidden';}else {btDown.style.visibility = 'visible';};setTimeout(updateTL, updateInterval);};var get_child_id = function(num){num = +num;return contID + '_child' + num;};JSONP = {get : function(url){if (script_id) {d.body.removeChild($(script_id));};script_id = url;var s     = d.createElement('script');s.charset = 'UTF-8';s.id      = url;s.src     = url;s.type    = 'text/javascript';d.body.appendChild(s);},show : function(json){internal_show_timeline(json);},update : function(json){internal_update_timeline(json);}};var stream_scroll_by = function(num){var newid = current_itemID + num;if (newid < 0 || newid >= current_stream.length) {return;};current_itemID = newid;show_current_item();};var streamScrollUp = function(){stream_scroll_by(-1);};var streamScrollDown = function(){stream_scroll_by(1);};window.onload = showTL;};
