$('#other').hide();

(function($) {
$.fn.cleanform = function(settings) {
	var config = {
		width : '300px'
	};

	if (settings) $.extend(config, settings);

	this.each(function() {
		$('input[type="text"]',this).not('.exclude').each(function(i) {
			$(this).wrap('<div class="input-wrapper" id=' + $(this).attr('id') + ' style="position: relative; float: left; margin-bottom: 5px;"></div>');
			var label = $('body').find('label[for="' + $(this).attr('name') + '"]');
			label.hide();
			$(this).parent().append('<span style="position: absolute; left: 10px; top: 5px; font-weight: bold; font-size: 1.25em;">' + label.text() + '</span>');
			$(this).css({'backgroundColor' : 'transparent','border' : '0','width' : '100%','margin' : '2px 4px'});
			
			$(this).parent().hover(
				function () {
					$(this).addClass('hover');
				},
				function () {
					$(this).removeClass('hover');	
			});
			$(this).focus(function() {
				$(this).parent().addClass('selected');		   
			});
			$(this).blur(function() {
				$(this).parent().removeClass('selected');	
				if ($(this).attr('value') == '') {$(this).parent().find('span').show();	}	
			});
			$(this).keypress(function() {
				$(this).parent().find('span').hide();
			});
		});
		
		
		$('input[type="checkbox"]',this).not('.exclude').each(function(i) {
			$(this).wrap('<div class="cbOverlay"></div>');
			$(this).parent().prepend('<div class="checkbox"></div>');
			$(this).hide();
			var label = $('body').find('label[for="' + $(this).attr('id') + '"]');
			label.hide();
			$(this).parent().prepend(label.text());
			$(this).parent().click(function() {
				var input = $(this).find('input');
				var checkbox = $(this).find('.checkbox');
				(input.attr('checked') ? (input.attr('checked',false), checkbox.removeClass('on')) : (input.attr('checked',true), checkbox.addClass('on')));
				$('input[rel="'+ input.attr('id') +'"]').parent().toggleClass('hide');
				if (input.attr('name') == 'other') { $('#other-details').toggle(); };
			});
		});
		$('input[type="radio"]',this).not('.exclude').each(function(i) {
			$(this).parent().wrapInner('<div class="radioOverlay"></div>');
			$(this).parent().prepend('<div class="radio"></div>');
			$(this).hide();
			if ($(this).attr('rel') != false) { $(this).parent().toggleClass('hide'); }
			$(this).parent().click(function() {
				var input = $(this).find('input');
				var radio = $(this).find('.radio');
				$('input[name="' + input.attr('name') + '"]').attr('checked',false).parent().find('.radio').removeClass('on');
				input.attr('checked',true);
				radio.addClass('on');
			});
		});
		$('#reset').click(function() {
			$('#other-details').hide();
			$('.input-wrapper span').show();
			$(this).find('input').attr('checked', false);
			$('.cbOverlay').find('.checkbox').removeClass('on');
			$('.radioOverlay').find('.radio').removeClass('on');
		});
		$(function(){
			$.extend($.fn.disableTextSelect = function() {
				return this.each(function(){
					if($.browser.mozilla){//Firefox
						$(this).css('MozUserSelect','none');
					}else if($.browser.msie){//IE
						$(this).bind('selectstart',function(){return false;});
					}else{//Opera, etc.
						$(this).mousedown(function(){return false;});
					}
				});
			});
			$('.cbOverlay').disableTextSelect();
			$('.radioOverlay').disableTextSelect();
		});
	});
	return this;
};
})(jQuery);
