// Copyright (c) 2007 Fark.com, LLC
// $Id: farkit.js 3658 2007-11-09 04:51:53Z mandrews $
//////////////////////////////////////////////////////////////////////////
// To add FarkIt buttons to your page, include this Javascript file and
// then add a call to this function:
//
//   farkItButton('This is the headline', 'http://this.is.the.url', size);
//
// If you omit the URL, it will automatically use the URL of the current page.
//
// If you omit the headline, it will look for a global Javascript variable
// called 'fark_headline' and use that if it's there.  If it isn't, it'll
// stay blank, and Fark will prompt for the headline when the button is
// clicked.
//
// If you omit the size, 80x20 is used.  SIZE IS CURRENTLY IGNORED; CHECK BACK
// IN MID NOVEMBER 2007 and we will have some options other than 80x20.
//
// So, if you want to prompt for a headline, use the default URL, and the default
// size, you can simply use the following syntax:
//
//   farkItButton();
//
// If you want to specify a headline and size but assume the default URL, use
// the following syntax:
//
//   farkItButton('Headline goes here','',size);

function farkItButton(h, u, s) {
  if (!IsDef(h)) {
    if (IsDef(window.fark_headline)) {
      h = window.fark_headline;
    } else {
      h = '';
    }
  }
  if (!IsDef(u)) {
    if (IsDef(window.fark_url)) {
      u = window.fark_url;
    } else {
      var URL = unescape(location.href); 
      u = URL;
    }
  }
  var size = 0;
  if (IsDef(s)) {
    // TODO larger size
    // document.write('<a href="http://cgi.fark.com/cgi/fark/farkit.pl?h=' + h + '&u=' + u + '" target="_blank"><img id="farkitButton" src="http://img.fark.com/pub/FarkItButton1_80x20.png" width="80" height="20" border="0"></a>');
  } else {
    document.write('<a href="http://cgi.fark.com/cgi/fark/farkit.pl?h=' + h + '&u=' + u + '" target="_blank"><img id="farkitButton" src="http://img.fark.com/pub/FarkItButton1_80x20.png" width="80" height="20" border="0"></a>');
  }
}

function IsDef(variable) {
  return (!(!( variable||false )))
}

