function inputDefault(id, defaulttxt) {
  if($('#' + id).length = 0) {
    return;
  }

  $('#' + id).val(defaulttxt);
  
  $('#' + id).focus(function() {
    if($('#' + id).val() == defaulttxt) {
      $('#' + id).val('');
    }
  });
  
  $('#' + id).blur(function() {
    if($('#' + id).val() == '') {
      $('#' + id).val(defaulttxt);
    }
  });
}

function obscure(selector, height) {
  var oldheight = $(selector).css('height');
  if(parseInt(oldheight) > height) {
    $(selector).css('height', height + 'px');
    $(selector).after(
      $('<a />').addClass('morejs').attr('rel','nofollow').html('MORE').click(function() {
        if($(this).html() == 'MORE') {
          $(selector).animate({
            height: oldheight
          }, 500);
          $(this).html('CLOSE');
        }
        else {
          $(selector).animate({
            height: height
          }, 500);
          $(this).html('MORE');
        }
      })
    );
  }
}

(function($) {

  $(document).ready(function() {
    
    inputDefault('s', 'to search, type and hit enter');
    inputDefault('mce-EMAIL', 'type your email and subscribe to our newsletter');
    inputDefault('jm_email', 'subscribe to the blog by email');
    
    obscure('.upcoming-travel', 115);
    obscure('.countries-visited', 55);
    obscure('.additional-resources', 55);
    
    var sheight = $('#sidebar').css('height');
    var cheight = $('#content').css('height');
    
    if(parseInt(sheight) >= parseInt(cheight)) {
      $('#content').css('height', sheight);
    }
    else {
      $('#sidebar').css('height', cheight);
    }
    
    $('.widget_subcategoriesandarchives .widgettitle a').click(function() {
      var oldul, oldulclass, newulclass;
      if($(this).hasClass('selected')) {
        return;
      }
      
      oldul = $('.widget_subcategoriesandarchives .widgettitle a.selected');
      $('.widget_subcategoriesandarchives .widgettitle a.selected, .widget_subcategoriesandarchives h2.selected').removeClass('selected');
      oldulclass = $(oldul).attr('class') + 'list';
      $('.widget_subcategoriesandarchives .' + oldulclass).hide();
      
      newulclass = $(this).attr('class') + 'list';
      $('.widget_subcategoriesandarchives .' + newulclass).show();
      $(this).addClass('selected');
      $(this).parent().addClass('selected');
    });
    
  });
  
})(jQuery);