/* 
 * Radio button plugin
 * Replace native radio buttons with custom radio buttons
 *
 * @author Zach Waugh <zwaugh@gmail.com>
 * @version 1.0
 * @requires ui.core.js
 *
 * Copyright (c) 2009 Zach Waugh MIT License
 */

(function($) {

$.widget("ui.radio", {

	_init: function() {
		var self = this, options = this.options;
		
		this._group = this.element.attr('name');
				
		if (this.element.attr('checked'))
		{
			var html = '<a href="#" rel="' + this._group + '" class="ui-radio ui-widget ui-radio-checked"></a>';
		}
		else
		{
			var html = '<a href="#" rel="' + this._group + '" class="ui-radio ui-widget"></a>';
		}
		

		this.element.hide();
		this._checkbox = this.element;
		this.element = $(html).insertAfter(this.element);
		
		// Bind Events
		this.element.click(function(event){ return self._handleClick(event); })
	},
	
	_handleClick : function(event) {
		//var self = this;
		if (!this.element.hasClass('ui-radio-checked'))
		{
			$('a[rel=' + this._group + '].ui-radio-checked').removeClass('ui-radio-checked');
			this.element.addClass('ui-radio-checked');
			this._checkbox.attr('checked', 'checked');
		}
		
		return false;
	}
	
});

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

})(jQuery);