
$(function(){
	replaceForms();
});

function replaceForms(){
	// to test a page without "pretty" styles use query "pretty=false"
	if ($.urlParam('pretty') != 'false'){
		//replaceTextInputs();
		replaceInsideSubmits();
		replaceRadios();
		replaceCheckboxes();
		//replaceSelects();
		//replaceTextareas();
		$('body').addClass('pretty');
	}
}

function replaceInsideSubmits(){
	$('div.submit_inside input.submit').addClass('submit_inside').removeClass('submit');
}

function replaceRadios(){
	$('input[type="radio"]').each(function(){
		if (!$(this).hasClass('pretty')){
			var span = $('<span />').addClass('radio');
			$(this).before(span);
			span.append($(this));
			if ($(this).attr('checked')) span.addClass('radio_checked');
			$(this).hover(function(){
				$(this).parent().addClass('radio_over');
			}, function(){
				$(this).parent().removeClass('radio_over');
			}).mousedown(function(){
				$(this).parent().addClass('radio_down').removeClass('radio_over');
			}).mouseup(function(){
				$(this).parent().removeClass('radio_down');
			}).blur(updateRadio).change(updateRadio).focus(updateRadio);
			$(this).addClass('pretty');
			if ($(this).attr('disabled')) span.addClass('disabled');
		}
	});
	$(document).mouseup(function(){
		$('input[type="radio"]').parent().removeClass('radio_down');
	});
}

function updateRadio(e){
	if ($(this).attr('checked')){
		$('input[name="'+ $(this).attr('name') +'"]').parent().removeClass('radio_checked');
		$(this).parent().addClass('radio_checked').removeClass('radio_down').removeClass('radio_over');
	}
}

function replaceCheckboxes(){
	$('input[type="checkbox"]').each(function(){
		if (!$(this).hasClass('pretty')){
			var span = $('<span />').addClass('checkbox');
			$(this).before(span);
			span.append($(this));
			if ($(this).attr('checked')) span.addClass('checkbox_checked');
			$(this).hover(function(){
				$(this).parent().addClass('checkbox_over');
			}, function(){
				$(this).parent().removeClass('checkbox_over');
			}).mousedown(function(){
				$(this).parent().addClass('checkbox_down').removeClass('checkbox_over');
			}).mouseup(function(){
				$(this).parent().removeClass('checkbox_down');
			}).blur(updateCheckbox).change(updateCheckbox);
			$(this).addClass('pretty');
			if ($(this).attr('disabled')) span.addClass('disabled');
		}
	});
	$(document).mouseup(function(){
		$('input[type="checkbox"]').parent().removeClass('checkbox_down');
	});
}

function updateCheckbox(e){
	if ($(this).attr('checked')){
		$(this).parent().addClass('checkbox_checked').removeClass('checkbox_down').removeClass('checkbox_over');
	} else {
		$(this).parent().removeClass('checkbox_checked').removeClass('checkbox_down');
	}
}

$( document ).ready( function()
{
	$( '.default_text' ).click( function( e )
	{
		this.value = '';
	} );
} );


