/**
 * cb-checkbox
 *
 * Author:     Johannes Wüller
 * Created On: 29.01.2010
 *
 * Usage:
 *    you can use cb-checkbox with any input checkbox. simply add __cb-cbox
 *    class to the target and call:
 *
 *       $.cbCheckbox();
 */
(function() {
   var initialized = false;
   jQuery.cbCheckbox = function() {
      if (!initialized) {
         jQuery('.__cb-cbox').each(function() {
            var checkbox = jQuery(this);
            overlay = jQuery('<div class="__cb-cbox-overlay"></div>').click(function() {
               if (jQuery(this).hasClass('__cb-cbox-active')) {
                  checkbox[0].checked = false;
                  jQuery(this).removeClass('__cb-cbox-active');
               } else {
                  checkbox[0].checked = true;
                  jQuery(this).addClass('__cb-cbox-active');
               }
            }).insertAfter(checkbox);
            jQuery(window).resize(function() {
               overlay.css({
                  top: parseInt(checkbox.offset().top)+'px',
                  left: parseInt(checkbox.offset().left)+'px'
               });
            }).resize();
            if (checkbox[0].checked) {
               overlay.click();
            }
         });
      } else {
         jQuery(window).resize();
      }
   };
})();

