jQuery.fn.checkMyBox = function(image, width, height)
{

  path = '/images/{image}.jpg'.replace('{image}', image);

  this.wrap('<span class="check_my_box"></span>');
  this.before('<img style="position: relative; border: 0px solid transparent;" src="' + path + '" alt="checkbox" />');
  this.hide();

  this.parent().bind('click', function()
  {
    element = jQuery(this);
    if (element.hasClass('check_my_box_checked'))
    {
      element.children('img').css('top', '0px');
      element.children('input').attr('checked', false);
      element.removeClass('check_my_box_checked');
    }
    else
    {
      element.children('img').css('top', '-' + height + 'px');
      element.children('input').attr('checked', true);
      element.addClass('check_my_box_checked');
    }
  }).css({
    position: 'relative',
    display: 'block',
    width: width + 'px',
    height: height + 'px',
    overflow: 'hidden',
    cursor: 'pointer'
  });

  this.bind('change', function()
  {
    if (jQuery(this).is(':checked') == jQuery(this).parent().hasClass('check_my_box_checked'))
    {
      return;
    }
    if (jQuery(this).is(':checked'))
    {
      jQuery(this).parent().addClass('check_my_box_checked');
    }
    else
    {
      jQuery(this).parent().removeClass('check_my_box_checked');
    }
  });

};

jQuery.fn.placeholder = function(label, default_class)
{

  this.data('placeholder_label', label);

  if (this.val() == '' || this.val() == label)
  {
    this.addClass(default_class).val(label);
  }

  this.focus(function()
  {
    element = jQuery(this);
    if (element.val() == element.data('placeholder_label'))
    {
      element.removeClass(default_class).val('');
    }
  })

  this.blur(function()
  {
    element = jQuery(this);
    if (element.val() == '')
    {
      element.addClass(default_class).val(label);
    }
  });
}

jQuery.fn.fadeToggle = function(speed)
{
  if (this.is(':visible'))
  {
    this.fadeOut(speed);
  }
  else
  {
    this.fadeIn(speed);
  }
}


jQuery.fn.toggleSidebar = function(remove, add)
{
  this.hide();
  id = '#' + add + '_' + this.attr('id').replace(remove + '_', '');
  this.data('toggler_id', id);

  path = '/images/design/menu_arrow.gif';

  toggler = jQuery(id);
  toggler.html('<img src="' + path + '" alt="" />').data('toggle_id', '#' + this.attr('id'));
  toggler.click(function()
  {
    jQuery(jQuery(this).toggleClass(add + '_open').data('toggle_id')).slideToggle();
  });
}

jQuery(document).ready(function()
{
  jQuery('a[rel="new_window"]').attr('target', '_blank');
});

