(function() {
		
	$.fn.replaceCheck = function(settings) {
		
		//Array of check buttons selected for replacement
		var sArray = this;
		
		settings = jQuery.extend({
			// Settings go here 
		}, settings);
		
		//For each check button, apply replace
		return sArray.each(function(){
			
		//Check for correct element type
		if($(this).attr('type') == 'checkbox') {

			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-checkbox ' + s.attr('class') + '" style="';
			sReplica += (sHeight) ? 'height:' + sHeight : '';
			sReplica += (sWidth) ? 'width:' + sWidth : '';
			sReplica += '">';
			
			// Build anchor
			sReplica += '<a href="#" class="sr-checkSelected-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);

			// Hide the original element
			s.hide();

			//If already set to checked (by default) show this in the new control
			if( $('input#' + sID).attr('checked') == true ) {
				$('a#' + sReplicaSelectedId).parent().addClass('sr-checkSelected');	//add class
			}

			//Setup show/hide on hover 
			$(".sr-checkbox").hover(
				function(){$(this).addClass('sr-checkHover');},
				function(){$(this).removeClass('sr-checkHover');}
			);
			
			//Click handler for check button
			$('a#' + sReplicaSelectedId).click(function(event){
				event.preventDefault();		//Prevent following link

				//If already selected, un-select this box
				if($(this).parent().hasClass('sr-checkSelected')) {
					$(this).parent().removeClass('sr-checkSelected');	//remove class
					$('input#' + sID).attr('checked',false);		//set checked attribute
				}
				//Else select this box
				else {
					//Add selected class to parent box
					$(this).parent().addClass('sr-checkSelected');	//add class
					$('input#' + sID).attr('checked', true);	//set checked attribute
				}
				return false;
			});
			
		}//Close type check		

		});//Close for each element
	};//Close function
	
})(jQuery);
