
 var s = "";

 var urlRegex = new RegExp("([^:]*):[/]*(?:www\.)*([^/]+)([^\?]*)(.*)");
 var spaceRegex =new RegExp("[ \t\n\r+]+","g");
 var scale=2; 

 var lastLat='',
     lastLng='',
     lastUser='';

var stopwords = [ "a", "about", "above", "accordingly", "after",
  "again", "against", "ah", "all", "also", "although", "always", "am", "among", "amongst", "an",
  "and", "any", "anymore", "anyone", "are", "as", "at", "away", "be", "been",
  "begin", "beginning", "beginnings", "begins", "begone", "begun", "being",
  "below", "between", "but", "by", "ca", "can", "cannot", "come", "could",
  "did", "do", "doing", "during", "each", "either", "else", "end", "et",
  "etc", "even", "ever", "far", "ff", "following", "for", "from", "further", "furthermore",
  "get", "go", "goes", "going", "got", "had", "has", "have", "he", "her",
  "hers", "herself", "him", "himself", "his", "how", "i", "if", "in", "into",
  "is", "it", "its", "itself", "last", "lastly", "less", "many", "may", "me",
  "might", "more", "must", "my", "myself", "near", "nearly", "never", "new",
  "next", "no", "not", "now", "o", "of", "off", "often", "oh", "on", "only",
  "or", "other", "otherwise", "our", "ourselves", "out", "over", "perhaps",
  "put", "puts", "quite", "s", "said", "saw", "say", "see", "seen", "shall",
  "she", "should", "since", "so", "some", "such", "t", "than", "thanks", "that", "the",
  "their", "them", "themselves", "then", "there", "therefore", "these", "they",
  "this", "those", "though", "throughout", "thus", "to", "too",
  "toward", "unless", "until", "up", "upon", "us", "ve", "very", "was", "we",
  "were", "what", "whatever", "when", "where", "which", "while", "who",
  "whom", "whomever", "whose", "why", "with", "within", "without", "would",
  "yes", "your", "yours", "yourself", "yourselves" ];

 function isStop(s)
 {
 
  for (var i=0; i<stopwords.length; i++)
  {
    if (s==stopwords[i]) return true;
  }

  return false;

 }

 function photoOnOff()
 {
   var o = document.getElementById('photo');
   if (o.style.display!='none') o.style.display='none';
   else                         o.style.display='block';
 }

 function linkurl(url, keepPath, addIcon) 
 {
  urlbits = urlRegex.exec(url);
  imgtxt = "";
  if (addIcon && urlbits[1]=='http') {
    imgtxt = ['<img src="http://',urlbits[2],'/favicon.ico" class="favicon" width="16" />'].join('');
  }
  if (keepPath) {
    visualUrl = [urlbits[2],urlbits[3]].join('');
  } else {
    visualUrl = [urlbits[2]];
  }
  return [imgtxt,' <a class=\'link1\' href="',url,'" target=\'_blank\'>',visualUrl,'</a>'].join('');
 }

 function lookup()
 {
   var v = document.forms['mf'].u.value;

   if (v=='') return false;

   document.forms['mf'].submit();
 
   return true;
 }
 
 function ShowLinks(graph) 
 {
  var photos=new Array();
  var old = false;
 
  foundnodes = graph["nodes"];
  for (var node in foundnodes) 
  {
    var info = foundnodes[node];

    if (info.attributes)
     if (info.attributes.photo)
     {
      olf = false;
      for (var i=0; i<photos.length; i++)
      {
        if (photos[i]==info.attributes.photo)
        {
          old=true;
          break; 
        }
      }
      if (!old)  
        photos[photos.length]=info.attributes.photo;
     }

    s+=linkurl(node,true,true)+"<br/>";
  }

  if (s == '') s="<span style='font-size:130%;color:red'>no data (yet?) ...</span>";

  if (photos.length>0)
  {
    s+="<br><span style='font-size:150%'>Photo: <a style='text-decoration:none' href='javascript:void(0' onClick='photoOnOff()'>+</a></span>";
    s+="<div id='photo' style='display:none'>";
    for (var i=0; i<photos.length; i++)
     {
        s+="<img style='padding-bottom:5px' src='"+photos[i]+"' alt='photo' border='0'/><br/>"
      }
       
    s+="</div>";
  }

  var share = "@"+lastUser+" info: http://tinfo.linkstore.ru?u="+lastUser;

  var s1="<br/><a class='link1' href='http://twitter.com?status="+encodeURIComponent(share)+"' target='_blank'>Twit this</a>"
        +" &nbsp; <a class='link1' href='/tinfo/index.jsp'>More ?</a>";

  if (s!='')
  {    
   document.getElementById('result').innerHTML = "<br><span style='font-size:150%'>Links:</span><br/>"+s+"<br/>&nbsp;";
  }

  document.getElementById('more').innerHTML = "<br>"+s1+"<br/>&nbsp;";
 }

function getMap(lat,lng, cl)
{
  var s = "<a";
  if (cl)
    s+=" class='"+cl+"'";

  s+=" href='http://bigmap.linkstore.ru?lat="+lat
   + "&lng="+lng
   + "&zml=10"
   + "&mrk=1"         
   + "' target='_blank'>"
   + lat+","+lng
   +"</a>";

  return s;
}

function TwitterLoc(t)
{
  if (!t) return;

  var o = document.getElementById("location");
  var name = t.screen_name;
  var loc = t.location;
  var s='';

  if (loc)
  {
    re = new RegExp("([-]?[0-9]{1,3}.[0-9]+),([-]?[0-9]{1,3}.[0-9]+)","g");
    loc = loc.replace(re, getMap('$1','$2'));
    s += loc+"<br/>&nbsp;<br/>";
  }

  if (t.description)
  {
    s+="<div style='text-align:left'><strong>Bio:</strong> "+t.description;
    s+="</div>";
  }

  if (t.url)
  {
    s+="<div style='text-align:left'><strong>URL:</strong> <a href='"+t.url+"' target='_blank'>"+t.url+"</a>";
    s+="</div>";
  }

  s+="<div style='text-align:left'>";
  s+="<strong>Since:</strong> "+t.created_at+"<br/>";
  if (t.verified)
    s+="<strong>Veirifed:</strong> "+t.verified+"<br/>";
  if (t.geo_enabled)
    s+="<strong>Geo enabled:</strong> "+t.geo_enabled+"<br/>";
  if (t.protected)
    s+="<strong>Protected:</strong> "+t.protected+"<br/>";
  if (t.time_zone)
    s+="<strong>Time zone:</strong> "+t.time_zone+"<br/>";
  s+="</div>";
   
  s+= "<table border='0' cellpadding='5px' cellspacing='7px'>"
   +  "<tr><td>"
   +  "<span id='following_count' class='number'>"+t.friends_count+"</span><br/>"
   +  "<a href='http://twitter.com/"+name+"/following' id='following_count_link' class='stat' rel='"+name+"' title='See who he/she is following' target='_blank'>"
   +  "<span class='label'>following</span>"
   +  "</a>"
   +  "</td><td>"
   +  "<span id='follower_count' class='number'>"+t.followers_count+"</span><br/>"
   +  "<a href='http://twitter.com/"+name+"/followers' id='follower_count_link' class='stat' rel='"+name+"' title='See who is following him/her'>"
   +  "<span class='label'>followers</span>"
   +  "</a>"
   +  "</td>"
   +  "<td>"
   +  "<span id='update_count' class='number'>"+t.statuses_count+"</span><br/>"
   +  "<a href='http://twitter.com/"+name+"' class='stat' title='See all tweets' rel='"+name+"' target='_blank'>"
   +  "<span class='label'>tweets</span>"
   +  "</a></td>"
   +  "</tr>"
   +  "</table><br/>";

  o.innerHTML = s;
}

function TwitterProc(tml)
{
  if (tml.length>0)
  {
   var image = tml[0].user.profile_image_url;
   var name  = tml[0].user.screen_name;

   
   var s ="<img src='"+image+"' border='0' width='73px' height='73px' alt=''/><br/>&nbsp;<br/>";
   document.getElementById('face').innerHTML=s;

   s="";

   var replies = new Array();

   var limit = 10;

   for (var i=0; i<tml.length; i++)
   {
     var elem = tml[i];
     var txt = elem.text;

     if (lastLat=='' && lastLng=='')
      {
        if (elem.geo)
         if (elem.geo.coordinates)
         {
           lastLat = elem.geo.coordinates[0];
           lastLng = elem.geo.coordinates[1]; 
         }   
      }


     if (i<limit) 
       s+=txt+" "; 

     if (txt.indexOf("@")==0)
     {
       var j = txt.indexOf(" ");
       if (j>2)
       {
         var r = txt.substring(1,j);
         if (r.indexOf(":")==r.length-1) 
           r = r.substring(0,r.length-1);

         addReply(replies,r,elem.in_reply_to_status_id,elem.id);
        }  
     }

    } 

      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");
      s =  s.replace(re, ' ');
       
      re = new RegExp("[0-9]","g");
      s =  s.replace(re, ' ');

      re = new RegExp('["«»]','g');
      s =  s.replace(re, ' ');

      re = new RegExp('&lt;','g');
      s =  s.replace(re, ' ');

      re = new RegExp('&gt;','g');
      s =  s.replace(re, ' ');

      re = new RegExp('&quot;','g');
      s =  s.replace(re, ' ');

      s = SkipNoise(s);

      re = new RegExp("[-+>=~<():,@.\t'\"{}%!?\/\\\\]","g");
      s =  s.replace(re, ' ');
      
    var elems = s.split(" ");
    var cloud=[];
    var tag;
    var max = 0; 
    var res;
              
    for (var i=0; i<elems.length; i++)
    {     
      tag = elems[i].toLowerCase();
      if (tag.length>3 && !isStop(tag))
      {
        res = -1;

        for (var j=0; j<cloud.length; j++)
          if (cloud[j].el==tag)
           {
               res = j;
               j = cloud.length+1;               
           }


           if (res<0)
           {
             cloud[cloud.length] = { count: 1, el: tag };
             max = Math.max(1, max);
           }
           else 
           {
             cloud[res].count += 1;
             max = Math.max(cloud[res].count, max);
           }

       }
          
   }
      
    s='';    
    for (var i = 0; i < cloud.length; i++) {
      if (cloud[i].count>=2)
       //s+='<a class="link1" style="font-size:' + Math.ceil((cloud[i].count / max) * scale) + 'em" href="http://search.twitter.com/search?q='+cloud[i].el+'" target="_blank">' + cloud[i].el + '</a> &nbsp; ';
       s+='<a class="link1" style="font-size:' + Math.ceil((cloud[i].count / max) * scale) + 'em" href="http://got.linkstore.ru?q='+encodeURIComponent(cloud[i].el)+'" target="_blank">' + cloud[i].el + '</a> &nbsp; ';
      else
       s+='<span style="color:blue;font-size:' + Math.ceil((cloud[i].count / max) * scale) + 'em">' + cloud[i].el + '</span> &nbsp; ';
    }

    var ans = "<span style='font-size:150%'>Recent topics:</span><br/><br/> "+ s;

    if (replies.length>0)
    {
      ans += "<br/><br/><span style='font-size:150%'>Recently replied to:</span><br/><br/>";
      for (var i=0; i<replies.length; i++)
      {
       ans+="<a class='link1' href='http://tinfo.linkstore.ru?u="+replies[i].r+"'>"+replies[i].r+"</a> ";
       if (replies[i].id)
        ans+="<a style='text-decoration:none' target='_blank' href='http://tdialog.linkstore.ru?"+replies[i].id+"' target='_blank'><img alt='' border='0' src='/tinfo/thread.png'/></a>&nbsp; ";
       else
        ans+="&nbsp; ";
      }
    }

    if (lastLng!='' && lastLat!='')
    {
      ans += "<br/><br/><span style='font-size:150%'>Last known location:</span><br/><br/>";
      
      ans += getMap(lastLat, lastLng, 'link1');
    }

    ans += "<br/><br/><span style='font-size:150%'>Reads:</span><br/><br/>";

    ans+="<a class='link1' href='http://tlink.linkstore.ru?u="+name+"'>links from friends</a> &nbsp; ";
    ans+="<a class='link1' href='http://rt.linkstore.ru?u="+name+"'>retweets from friends</a> &nbsp; ";
    ans+="<a class='link1' href='http://tbuzz.linkstore.ru?u="+name+"'>buzz from friends</a> &nbsp; ";

    document.getElementById('cloud').innerHTML = ans;
  }
}

function SkipNoise(s0)
{
 var re = new RegExp('this','g');
 var s =  s0.replace(re, ' ');

 re = new RegExp('that','g');
 s =  s.replace(re, ' ');

 re = new RegExp('just','g');
 s =  s.replace(re, ' ');

 re = new RegExp('from','g');
 s =  s.replace(re, ' ');

 re = new RegExp('than','g');
 s =  s.replace(re, ' ');

 re = new RegExp('have','g');
 s =  s.replace(re, ' ');

 return s;

}

function addReply(ara, r, rId, sId)
{
  for (var i=0; i<ara.length; i++)
   if (ara[i].r==r) return;
 
  var rr = new Object();
  rr.r = r;

  if (rId)
    rr.id=sId;
  
  ara[ara.length]=rr;
  
}

function getTwitterFace(user)
{
  lastLat='';
  lastLng='';
  lastUser = user;
  var cbscript = document.createElement("script");
  cbscript.src = 'http://twitter.com/statuses/user_timeline/'+user+'.json?callback=TwitterProc&count=20';
  cbscript.type = 'text/javascript';
  document.body.appendChild(cbscript);
}

function getLocation(user)
{
  var cbscript = document.createElement("script");
  cbscript.src = 'http://twitter.com/users/show/'+user+'.json?callback=TwitterLoc';
  cbscript.type = 'text/javascript';
  document.body.appendChild(cbscript);
}




