jQuery.fn.inlineFieldLabel = function(setLabel) 
{
  return this.each(function() {
    var textInput = $j(this); // your text input field
    var fieldLabel = setLabel || textInput.attr("title");
    
    if (textInput.val()=="") {
      textInput.addClass("intra-field-label").val(fieldLabel);
    }
    
    textInput.focus(function()
    {
      if (!textInput.hasClass("intra-field-label")) return;
      textInput.removeClass("intra-field-label").val("");
    });
    
    textInput.blur(function()
    {
      if (textInput.val()=="") textInput.addClass("intra-field-label").val( fieldLabel );
    });
    
    textInput.closest("form").submit(function() {
      if (!textInput.hasClass("intra-field-label")) return;
      textInput.val("");
    });
  });
};

jQuery.fn.betterFieldLabel = function(label){
  return this.each(function(){
    var $field = $j(this);
    var fieldPos = $field.position();
    var labelText = label || $field.attr("title");
    var $label = $j('<div class="intra-field-label">'+labelText+'</div>');
    $field
      .before($label)
      .css("zoom", "1")
      .focus(function(e){ 
        $label.hide(); 
      })
      .blur(function(e){
        if ($j(this).val()=="") $label.show(); 
      })
      // listen to change and onPropertyChange mainly to detect stuff like auto-fill
      // which should hide the label.
      .change(function(e){
        if ($j(this).val()=="") $label.show();
        else $label.hide();
      })
      .bind('onPropertyChange', function(e){
        if ($j(this).val()=="") $label.show();
        else $label.hide();
      });
    $label
      .css({
        position:"absolute",
        textAlign:$field.css("text-align"),
        left:fieldPos.left + "px",
        top:fieldPos.top + "px",
        width:$field.width() + "px",
        height:$field.height() + "px",
        lineHeight:$field.height() + "px"
      })
      .hide()
      .click(function(e) { $field.focus(); return false; })
      .parent().css("position", "relative");
    
    // reposition after a short delay. this is to avoid issues grabbing the position
    // if the div is invisible when initially laid out.
    setTimeout(function(){
      if ($field.val()=="") $label.show();
      var fieldPos = $field.position();
      $label.css({
        left:fieldPos.left + "px",
        top:fieldPos.top + "px",
        width:$field.width() + "px"
      });
    }, 150);
  });
};

jQuery.fn.initRollovers = function()
{
  var noPngRollover = (jQuery.browser.msie && parseFloat(jQuery.browser.version) < 7);
  if (noPngRollover) {
    // alert("IE6: no rollovers.");
    return this;
  }
  
  return this.each(function() {
    var $elt = jQuery(this);

    // get attributes and build a "hover" src string
    var src = $elt.attr("src");
    var ftype = src.substring(src.lastIndexOf("."), src.length).toLowerCase();
    
    var hoverSrc = src.replace(ftype, "_over"+ftype);
    
    var preloadImg = new Image();
    preloadImg.src = hoverSrc;
    
    $elt.attr("hoverSrc", hoverSrc)
        .attr("originalSrc", src)
        .mouseover(function(){
          var jThis = jQuery(this);
          jThis.attr("src", jThis.attr("hoverSrc"));
        })
        .mouseout(function(){
          var jThis = jQuery(this);
          jThis.attr("src", jThis.attr("originalSrc"));
        });
  });
};
