function stringEndsWith(str, s){
  var reg = new RegExp(s + "$");
  return reg.test(str);
}

$(document).ready(function() {

  // Add 'retag' to tag names input if present
  if($('input#tagnames').length !== 0)
  {
    if($('input#tagnames').attr('value').length === 0)
    {
      $('input#tagnames').attr('value','retag ');
    }
  }

  // Change "login" link to "login (register)" and make more prominent
  $('#topbar #hlinks a').each(
    function(i)
    {
      if( this.innerHTML === "login" )
      {
        this.style.color = "#cc2222";
        this.style.fontSize = "16px";
        this.innerHTML = "click here to login (register)";
      }
      else if( this.innerHTML === "register" )
      {
        this.style.color = "#cc2222";
        this.style.fontSize = "16px";
        this.innerHTML = "click here to register";
      }
    }
  );

  $("<div class='addthis-outer'><div class='addthis roundme'><div class='addthis_toolbox addthis_default_style'><a class='addthis_button_facebook'></a><a class='addthis_button_twitter'></a><a class='addthis_button_linkedin'></a><a class='addthis_button_delicious'></a><a class='addthis_button_stumbleupon'></a><a class='addthis_button_google'></a><a class='addthis_button_digg'></a><a href='http://www.addthis.com/bookmark.php?v=250&amp;pub=basicallymoney' class='addthis_button_compact'>more...</a></div></div></div><script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#pub=basicallymoney'></script>").appendTo('#question .post-menu');

  // Round some corners (except for IE6, IE7)
  if ($.browser.msie && $.browser.version.substr(0,1)<8) { 
    // IE6, IE7; don't round.
  }
  else {
    $('.nav ul li').corner("5px");
    $('.system-message-color').corner("5px");
    $('.module').corner("7px");
    $('.roundme').corner("7px");
  }

  $(function() { 
    $(".module:has(h4:contains('Formatting Reference'))").html(
      '<h4>Formatting Reference</h4>' +
      '<p>_italic text_ or *italic text*</p>' +
      '<p>__bold text__ or **bold text**</p>' +
      '<p>2 spaces at end of line for line break</p>' +
      '<p>bulleted list: - or + or * before line items</p>' +
      '<p>&gt; blockquote</p>' +
      '<p>horizontal rule: --- on own line</p>' +
      '<p>for links, any of:<br>&lt;http://foo.com&gt;<br>[foo](http://foo.com)<br>&lt;a href="http://foo.com"&gt;foo&lt;/a&gt;</p>' +
      '<p><a href="http://meta.stackoverflow.com/questions/1777/what-html-tags-are-allowed" target="_blank">basic HTML</a> is also allowed</p>' +
      '<p style="text-align:right;"><a href="/editing-help" target="_edithelp">more about Markdown &raquo;</a></p>'
    );
  });
  // script to remove "code coloring" as well:
  window.styleCode = function() {};

  if( stringEndsWith(window.location, "src=so1") ||
      stringEndsWith(window.location, "src=so2") ||
      stringEndsWith(window.location, "src=so3") )
  {
    $("#additionalWelcome").fadeIn(1500);
    $("#additionalWelcome").html("<h1 style='border-bottom: dotted 1px white; padding-bottom: 8px; margin-bottom: 8px;'>Greetings,<br/> Stack Overflow User!</h1>");
  }

  if( stringEndsWith(window.location, "src=moms4mom.com") )
  {
    $("#additionalWelcome").fadeIn(1500);
    $("#additionalWelcome").html("<h1 style='border-bottom: dotted 1px white; padding-bottom: 8px; margin-bottom: 8px;'>Greetings,<br/> moms4mom.com user!</h1>");
  }

  if( stringEndsWith(window.location, "src=home4film.com") )
  {
    $("#additionalWelcome").fadeIn(1500);
    $("#additionalWelcome").html("<h1 style='border-bottom: dotted 1px white; padding-bottom: 8px; margin-bottom: 8px;'>Greetings,<br/> home4film.com user!</h1>");
  }

  if( stringEndsWith(window.location, "src=facebook.com") )
  {
    $("#additionalWelcome").fadeIn(1500);
    $("#additionalWelcome").html("<h1 style='border-bottom: dotted 1px white; padding-bottom: 8px; margin-bottom: 8px;'>Greetings,<br/> Facebook user!</h1>");
  }

}); // end document ready function
