
$(document).ready(function() {
/* fix emails */
 var m = 'mai' + 'lto' + '}';
 var e = 'co' + 'nta' + 'ct{' + 'j-c' + 'an.' + 'org' + '.je';
 e = e.replace(/{/, '@');
 m = m.replace(/}/, ':');
 $('#subscribe > img').remove();
 $('#contact').append('<ul><li><a href="' + m + e + '">' + e + '</a></li></ul>');
 $('#subscribe').append('<a href="' + m + e + '?subject=Please subscribe me to the J-CAN newsletter">' + e + '</a>');
 
 /* style search */
    var defaultStr = ' Search';
    var searchBox = $('#search .search');
    searchBox.focus(searchIsActive);
    searchBox.blur(searchIsDormant);
    $('#search label').css('display', 'none');
    $('#search').submit(function() {
      return (searchBox.attr('value') != defaultStr)
    });
    moveButton();
    searchIsDormant();
  
    function searchIsDormant() {
      if (searchBox.attr('value') == '')
        searchBox.css('color', 'silver').attr('value', defaultStr);
    }
  
    function searchIsActive() {
      if (searchBox.attr('value') == defaultStr)
        searchBox.css('color', 'black').attr('value', '');
    }
    
    function moveButton() {
      var searchButton = $('#search button');
      var top = searchBox.offset().top;
      var right = searchBox.offset().left + searchBox.outerWidth();
      var buttonLeft = right - searchButton.outerWidth();
      searchButton.css({
        'cursor': 'pointer',
        'border': 'none',
        'position': 'absolute',
        'top': top,
        'left': buttonLeft - 5
      });
    }
});


