(function() {
		
	$.fn.replaceRadio = function(settings) {
		
		//Array of radio buttons selected for replacement
		var sArray = this;
		
		settings = jQuery.extend({
			// Settings go here 
		}, settings);
		
		//For each radio button, apply replace
		return sArray.each(function(){
			
		//Check for correct element type
		if($(this).attr('type') == 'radio') {

			var s = $(this);
			var sID = s.attr('id');
			var sName = s.attr('name');
			var sWidth = s.css('width');
			var sHeight = s.css('height');
			var maxOptions = 8;
			
			var sReplicaSelectedId = sID + "Selected";
			
			// Build container div
			var sReplica = '<div class="sr-radiobox ' + s.attr('class') + '" style="';
			sReplica += (sHeight) ? 'height:' + sHeight : '';
			sReplica += (sWidth) ? 'width:' + sWidth : '';
			sReplica += '">';
			
			// Build anchor
			sReplica += '<a href="#" class="sr-radioSelected-button" style="';
			sReplica += (sHeight) ? 'height:' + sHeight + 'px;' : '';
			sReplica += (sWidth) ? 'width:' + sWidth + 'px;' : '';
			sReplica += '" id="' + sReplicaSelectedId + '"></a>';
				
			sReplica += '</div>';
			
			// Write the replicated element
			s.after(sReplica);

			//Setup show/hide on hover 
			$(".sr-radiobox").hover(
				function(){$(this).addClass('sr-radioHover');},
				function(){$(this).removeClass('sr-radioHover');}
			);
			
			//Click handler for radio button
			$('a#' + sReplicaSelectedId).click(function(event){
				event.preventDefault();		//Prevent following link

				//Remove selected class from all radio buttons of this group
				$("input[name='" + sName + "']").attr('checked',false);	//remove all checks
				$('.sr-radioSelected').removeClass('sr-radioSelected');		//remove all classes

				//Add selected class to parent box
				$(this).parent().addClass('sr-radioSelected');			//add class
				$('input#' + sID).attr('checked', true);

				return false;
			})
			
			// Hide the original element
			s.hide();

		}//Close type check		

		});//Close for each element
	};//Close function
	
})(jQuery);
