$(document).ready( function() {
  
  $('body').removeClass('javascript_disabled').addClass('javascript_enabled');

  $("ul.sf-menu").superfish({
    autoArrows: false
  });
  
  $('div#banner div#pics').cycle({
    fx: "fade",
    speed: "2000"
  });
  
  $('div#member_profiles ul').cycle({
    fx: "fade",
    pause: true,
    speed: "1000"
  });
   
    // open external link in new tab/window
    // use rel="external" instead of target="_blank"
    $('a[rel="external"]').click( function() {
        this.target = "_blank";
    });
    
    //email replacement
     $("span.safemailer").each(function(){
       exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
       match = exp.exec($(this).text());
       addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
       emaillink = match[2] ? match[2] : addr;
       subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
       $(this).after('<a href="mailto:'+addr+subject+'">'+ emaillink + '</a>');
       $(this).remove();
     });
     
    // clear specified input on focus, reset to default value if nothing entered
    // http://bassistance.de/2007/01/23/unobtrusive-clear-searchfield-on-focus/
    $.fn.clearTextInput = function() {
     return this.focus(function() {
       if( this.value == this.defaultValue ) {
         this.value = "";
       }
     }).blur(function() {
       if( !this.value.length ) {
         this.value = this.defaultValue;
       }
     });
    };
    $(".clearTextInput").clearTextInput();
    
    $('#action_bar form input.submit').hover(function() {
      $(this).css('background-position', '0 -22px');
    }, function() {
      $(this).css('background-position', '0 0');
    });
    
    $.fn.addCap = function() {
      $(this).after('<span class="cap"></span>');
    };

    $('#navigation li a.head').prepend('<span class="cap"></span>');
    $('a.button').addCap();
    $('input.button').addCap();
    
    $('#featured_items .item:gt(1)').css('border', '0');
    $('#featured_items .item .thumb img').before('<div class="overlay"></div>')
    
    $('.baseform input:text').addClass('text');
   
});