$(document).ready(function() {	
	// Build rounded corners
	$(".box").each(function(i) {
		// Progressive enhancement
		// - Reset overflow
		// - Reset background colors boxes
		$(this).css("overflow", "visible");
		$(this).css("background", "transparent");		
		// Wrap content in a DIV to give it padding
		$(this).wrapInner("<div class='box-content'></div>");
		// Add divs for background images corners
		$(this).append("<div class='box-Topleft'></div>");	
		$(this).append("<div class='box-Topright'></div>");
		$(this).append("<div class='box-Bottomleft'></div>");
		$(this).append("<div class='box-Bottomright'></div>");
		// Calculate the height and width of the parent
		var varHeight = $(this).height();
		var varWidth= $(this).width();
		var varHeight = varHeight+25;
		var varWidth = varWidth+45;
		// Set the height or width for the added divs
		$(this).find(".box-Topleft").css({'height' : varHeight-11});
		$(this).find(".box-Topright").css({'height' : varHeight-11});
		$(this).find(".box-Topleft").css({'width' : varWidth-11});
		$(this).find(".box-Bottomleft").css({'width' : varWidth-11});
	});	
});

/**
 * jQuery.labelify - Display in-textbox hints
 * Stuart Langridge, http://www.kryogenix.org/
 * Released into the public domain
 * @author Stuart Langridge
 * @version 1.3
 */
jQuery.fn.labelify = function(settings) {
  settings = jQuery.extend({
    text: "title",
    labelledClass: ""
  }, settings);
  var lookups = {
    title: function(input) {
      return $(input).attr("title");
    },
    label: function(input) {
      return $("label[for=" + input.id +"]").text();
    }
  };
  var lookup;
  var jQuery_labellified_elements = $(this);
  return $(this).each(function() {
    if (typeof settings.text === "string") {
      lookup = lookups[settings.text]; // what if not there?
    } else {
      lookup = settings.text; // what if not a fn?
    };
    // bail if lookup isn't a function or if it returns undefined
    if (typeof lookup !== "function") { return; }
    var lookupval = lookup(this);
    if (!lookupval) { return; }

    // need to strip newlines because the browser strips them
    // if you set textbox.value to a string containing them    
    $(this).data("label",lookup(this).replace(/\n/g,''));
    $(this).focus(function() {
      if (this.value === $(this).data("label")) {
        this.value = this.defaultValue;
        $(this).removeClass(settings.labelledClass);
      }
    }).blur(function(){
      if (this.value === this.defaultValue) {
        this.value = $(this).data("label");
        $(this).addClass(settings.labelledClass);
      }
    });
    
    var removeValuesOnExit = function() {
      jQuery_labellified_elements.each(function(){
        if (this.value === $(this).data("label")) {
          this.value = this.defaultValue;
          $(this).removeClass(settings.labelledClass);
        }
      })
    };
    
    $(this).parents("form").submit(removeValuesOnExit);
    $(window).unload(removeValuesOnExit);
    
    if (this.value !== this.defaultValue) {
      // user already started typing; don't overwrite their work!
      return;
    }
    // actually set the value
    this.value = $(this).data("label");
    $(this).addClass(settings.labelledClass);

  });
};

// Remove default view of the labels and place the text them in the input and texterea
$(document).ready(function() {
  $("#form1 label").hide();
  $("input").labelify({
    text: "label"
  });
  $("textarea").labelify({
    text: "label"
  });
});

// hide email
jQuery.fn.mailme = function() {
    var at = / at /;
    var dot = / dot /g;
    this.each( function() {
        var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
        var title = jQuery(this).attr('title')
        $(this)
            .after('<a href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
            .remove();
    });
};

$(function(){
	$('span.mailme').mailme();
});