// Copyright (c) 2007 Fark, Inc
// $Id: farkit.js 8297 2009-10-10 00:22:56Z mmangler $
//////////////////////////////////////////////////////////////////////////
// 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', '80x20');
//
// 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.
//
// Valid sizes are '80x20', '100x20', '120x40', '16x16', '32x32', '29x40', '88x30'.
// If you omit the size, 80x20 is used.
//
// 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','','88x30');

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 img = 'FarkItButton1_80x20.png'; var imgw = 80; var imgh = 20;
  if (IsDef(s)) {
    if (s == '100x20') {
      img = 'FarkItButton2_100x20.gif'; imgw = 100; imgh = 20;
    } else if (s == '120x40') {
      img = 'FarkItButton2_120x40.gif'; imgw = 120; imgh = 40;
    } else if (s == '16x16') {
      img = 'FarkItButton2_16x16.gif'; imgw = 16; imgh = 16;
    } else if (s == '29x40') {
      img = 'FarkItButton2_29x40.gif'; imgw = 29; imgh = 40;
    } else if (s == '32x32') {
      img = 'FarkItButton2_32x32.gif'; imgw = 32; imgh = 32;
    } else if (s == '88x30') {
      img = 'FarkItButton2_88x30.gif'; imgw = 88; imgh = 30;
    } else if (s == '82x20') {
      img = 'FarkThisButton1_82x20.gif'; imgw = 82; imgh = 20;
    } else if (s == '129x32') {
      img = 'FarkThisButton1_129x32.gif'; imgw = 129; imgh = 32;
    }
  }
  document.write('<a href="http://www.fark.com/cgi/farkit.pl?h=' + h + '&u=' + u + '" target="_blank"><img id="farkitButton" src="http://img.fark.net/pub/' + img + '" width="' + imgw + '" height="' + imgh + '" border="0"></a>');
}

function IsDef(variable) {
  return (!(!( variable||false )))
}

