var clipURL = null;
var clipHTML = null;
var copyURLText = null;
var copyHTMLText = null;
function $(id) { return document.getElementById(id); }
function $S(id) { return $(id).style; }
function copyinit() {
  if(!$('urlstat')) return;
  
  ZeroClipboard.setMoviePath('/common/zeroclipboard/ZeroClipboard.swf');
  
  clipURL = new ZeroClipboard.Client();
  clipURL.setHandCursor(true);
  clipURL.addEventListener('complete', done);
  clipURL.glue('urlstat');
  clipURL.setText($('urlcode').value);
  cpTxtURL = $('urlstat').innerHTML;
  
  clipHTML = new ZeroClipboard.Client();
	clipHTML.setHandCursor(true);
	clipHTML.addEventListener('complete', done);
	clipHTML.glue('htmlstat');
  clipHTML.setText($('htmlcode').value);
  cpTxtHTML = $('htmlstat').innerHTML;
}
function done(client, text) {
  if (client.domElement.id == 'urlstat') {
    hl = 'urlcode';
    cp = 'urlstat';
    uncp = 'htmlstat';
    txt = cpTxtHTML;
  }
  if (client.domElement.id == 'htmlstat') { 
    hl = 'htmlcode';
    cp = 'htmlstat';
    uncp = 'urlstat';
    txt = cpTxtURL;
  }
  $(hl).focus();
  $(hl).select();

  $(cp).innerHTML = '<b style="color:#393;">Copied</b>';
  $(uncp).innerHTML = txt;
}
function shortenCallback()
{
  if (TruncIt.success) alert('Callback: Success ' + TruncIt.source + '-->' + TruncIt.url);
  else                 alert('Callback: Error');
}
function lookupCallback()
{
  if (TruncIt.success) alert('Callback: Success ' + TruncIt.source + '-->' + TruncIt.url + ',' + TruncIt.type + ',' + TruncIt.desc);
  else                 alert('Callback: Error');
}
function tweetCallback()
{
  if (TruncIt.success) {
    var msg = unescape(TruncIt.msg);
    $('dst').value = msg;
    $('dstcnt').innerHTML = (msg.length < 1000) ? String(msg.length) : 'tilt';
    /*
    if(msg.length > 0) {
      $('sndtweet').href = 'http://twitter.com/home?status=' + escape(TruncIt.msg);
      $S('sndtweet').display = 'block';
    }
    */
  }
}
function shorten_tweet()
{
  var txt = $('text').value;
  if(txt.length) {
    TruncIt.tweet(txt, tweetCallback);
  }
  else
    $('dst').value = '<== Enter message to shorten';
  return false;
}
function tcnt(t)
{ 
  $('txtcnt').innerHTML = (t.value.length < 1000) ? String(t.value.length) : 'tilt';
}
function tabs(e) {
  if(e.id == 'tabsh') {
   $S('boxsh').display = 'block';
   $S('boxup').display = 'none';
   $S('boxtw').display = 'none';
  }
  else if(e.id == 'tabup') {
   $S('boxup').display = 'block';
   $S('boxsh').display = 'none';
   $S('boxtw').display = 'none';
  }
  else if(e.id == 'tabtw') {
   $S('boxtw').display = 'block';
   $S('boxsh').display = 'none';
   $S('boxup').display = 'none';
  }
  return false;
}
window.onload=copyinit;

