//This is for the "Search" text on the search field of the sidebar.

jQuery.fn.hint = function (blurClass) {
  if (!blurClass) {
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) {
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

$(function(){
    // find all the input elements with title attributes
    $('input[title!=""]').hint();
});

//The comments author links on mouse hover are also from here

$(document).ready(function(){
    $('cite').hover(function() {
        $(this).children('span').show();
    },
    function() {
        $(this).children('span').hide();
    });
});

//Display the comment posting rules
$(document).ready(function(){
        $("#reqXHTML").click(function() {
        $("#rules").animate({"height": "toggle"}, { duration: 300 });
    });

});


//Display the subscription form
$(document).ready(function(){
        $('a#emailSubsTxt').click(function() {
        $("#subsFrm").animate({"height": "toggle"}, { duration: 300 });
        return false;
    });
        $('a#emailSubsImg').click(function() {
        $("#subsFrm").animate({"height": "toggle"}, { duration: 300 });
        return false;
    });
});

//Open all external links in an new window aka:: target="_blank"
$(document).ready(function(){
        $("a").filter(function() {
            return this.hostname && this.hostname !== location.hostname;
        }).attr('target', '_blank');
});

$(document).ready( function()
{
   PEPS.rollover.init();
});

PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();

      $(".boxSNW a").hover(
         function () { $(this).children().attr( 'src', PEPS.rollover.newimage($(this).children().attr('src')) ); },
         function () { $(this).children().attr( 'src', PEPS.rollover.oldimage($(this).children().attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.boxSNW a').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).children().attr('src') ) ); });
      });
   },

   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
      //return src.replace(/_o\./, '.');
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
      //return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   }
};

$(document).ready(function()
{
   $("#commentform").validate();
});
