/**
 * 
 * Author : vasile.orza
 * 
 * <input type="checkbox" name"test" />
 * 
 * $(":checkbox").checkbox()
 * 
 */
(function($) {
  $.fn.checkbox = function() {

    return this.each(function() {
      var $checkbox = $(this);
      if ($checkbox.is(":not(:checkbox)")) {
        return;
      }

      // remove markup generated by previous plugin calls
      if ($checkbox.parent().is(".checkbox")) {
        $checkbox.unwrap();
      }

      // add markup & behavior
      $(this).wrap(
                $("<div>").addClass("checkbox")
                          .addClass(this.className)
                          .toggleClass("checked", this.checked)
                          .attr("name", $checkbox.attr("name"))
                          .css("float", $checkbox.css("float"))
                          .css("margin-top", $checkbox.css("margin-top"))
                          .css("margin-right", $checkbox.css("margin-right"))
                          .css("margin-bottom", $checkbox.css("margin-bottom"))
                          .css("margin-left", $checkbox.css("margin-left"))
                          .css("name", $checkbox.attr("name"))
      )
      .change(function() {
        $(this).parent().toggleClass("checked", this.checked);
      })
      .focus(function() {
        $(this).parent().addClass("focus");
      })
      .blur(function() {
        $(this).parent().removeClass("focus");
      });
    });
  };
})(jQuery)

