/* 
 * Checkbox plugin
 * Create custom checkboxes that behave like native checkboxes
 *
 * @author Zach Waugh <zwaugh@gmail.com>
 * @version 1.1
 * @requires ui.core.js
 *
 * Copyright (c) 2009 Zach Waugh MIT License
 */

(function($) {

$.widget("ui.checkbox", {

	_init: function() {
		var self = this, options = this.options;
		
		if (this.element.attr('checked'))
		{
			var html = '<a href="#" class="ui-checkbox ui-widget ui-checkbox-checked"></a>';
		}
		else
		{
			var html = '<a href="#" class="ui-checkbox ui-widget"></a>';
		}
		
		this.element.hide();
		this._checkbox = this.element;
		this.element = $(html).insertBefore(this.element); //now inserts before element, allows form to send, custom for big tree site
		
		// Bind Events
		this.element.click(function(event){ return self._handleClick(event); });
	},
	
	_handleClick : function(event) {
		if (this.element.hasClass('ui-checkbox-checked'))
		{
			this.element.removeClass('ui-checkbox-checked');
			this._checkbox.removeAttr('checked').triggerHandler('click');
		}
		else
		{
			this.element.addClass('ui-checkbox-checked');
			this._checkbox.attr('checked', 'checked').triggerHandler('click');
		}
		
		return false;
	}
	
});

$.extend($.ui.checkbox, {
	version: "1.7.1",
	defaults: {
	}
});

})(jQuery);
