(function(){
  
  // Define Encoder
  function encoder(str) {
    // encode the characters that bugs the test case
    str = str.replace(/\+/g, '%2B');
    str = str.replace(/&amp;/g,'%26');
    str = str.replace(/&/g , '%26');
    // URI safe encoding
    str = encodeURIComponent(str);
    // repace chars to sync with Ruby URI.encode/decode
    str = str.replace(/%2F/g,'/');
    // return a URL Safe string
    return str
  }
  // button dimensions depending on the skin
  var h = '23px';
  var w = '185px';
  if (typeof fanopic_url == 'undefined') {
    var fanopic_url = window.location.href;
  } else if (fanopic_url.match(/^\[/)) {
    var fanopic_url = window.location.href;
  }
  var url = encoder(fanopic_url);
  // place the button
  document.write("<iframe src='http://bg.fanopic.com/widgets/button?url="
    + url
    + (typeof fanopic_bgcolor  =='string'? ("&amp;bgcolor="  + fanopic_bgcolor)  :'')
    + "' height='"+ h + "'; width='" + w 
    + "'; frameborder='0' scrolling='no'></iframe>")
})()
