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

