$(document).ready(function() {
    $('input.fancy-label').label();
    $('textarea.fancy-label').label();
    $('input.fancy-field').field();
    $('input.fancy').label().field();
    $('input[type="checkbox"]').checkbox();
	$('button.fancy, a.button').button();

	jQuery.each(jQuery.browser, function(i, val) {
		if(val == true) {
			$('body').addClass(i);
		}
	});
});



$.fn.label = function() {
    $(this).siblings('label').addClass('fancy');
    $(this).css({color: '#999999'});

    return this.focus(function() {
        if ($(this).val() == this.defaultValue) {
            $(this).val('');
            $(this).css({color: '#404040'});
        }
    }).blur(function() {
        if (!$(this).val().length) {
            $(this).val(this.defaultValue);
            $(this).css({color: '#999999'});
        }
    });
    
    return this;
};

$.fn.field = function() {
    $(this).wrap('<div class="fancy"></div>'); 
    return $(this).focus(function(){
        $(this).addClass('focus');
        $(this).parent().addClass('focus');
    }).blur(function(){
        $(this).removeClass('focus');
        $(this).parent().removeClass('focus');
    })
    return this;
};

$.fn.button = function() {
	$(this).wrapInner('<span></span>');
	return this;
};

$.fn.checkbox = function() {
    $(this).parent().addClass('fancy').children('label').prepend('<span></span>').end();
    return this.focus(function(){
        $(this).parent().addClass('focus');
    }).blur(function(){
        $(this).parent().removeClass('focus');
    }).click(function(){
        if($(this).is(':checked')){
            $(this).parent().addClass('checked');
        } else {
            $(this).parent().removeClass('checked');
        }
    });
    return this;
};


