$(document).ready(function() {
    if (!Modernizr.input.placeholder){
        $('input[type=text],input[type=url],input[type=email]').each(function() {
            if ($(this).attr('placeholder')) {
                placeholder = $('<span class="placeholder" rel="'+$(this).attr('id')+'">'+$(this).attr('placeholder')+'</span>');
                placeholder.hide();
                placeholder.mousedown(function() {
                    $('input').blur();
                    $('#'+$(this).attr('rel')).focus();
                });
                $(this).before(placeholder);
                $(this).focus(function() {
                    $('.placeholder[rel='+$(this).attr('id')+']').hide();
                })
                $(this).blur(function() {
                    if ($(this).val() == "") {
                        $('.placeholder[rel='+$(this).attr('id')+']').show();
                    }
                });
                $(this).change(function() {
                    if ($(this).val() == "") {
                        $('.placeholder[rel='+$(this).attr('id')+']').show()
                    }
                });
                if ($(this).val() == "") {
                    placeholder.show();
                }
            }
        });
    }
    $('select').each(function() {
        select = $(this);
        id = $(this).attr('id');
        options = $('option', this);
        container = $('<div class="proxy_select" id="wrapper_'+id+'">');
        label = $('<p class="value" rel="proxy_'+id+'">'+$(options[0]).text()+'</label>');
        option_ul = $('<ul id="proxy_'+id+'"/>');

        label.toggle(
            function() {
                $('#'+$(this).attr('rel')).slideDown('fast');
            },
            function() {
                $('#'+$(this).attr('rel')).slideUp('fast');
            }
        );
        select.hide();
        container.append(label);
        $(options).each(function(i) {
            if (i) {
                option_ul.append('<li rel="'+i+'">'+$(this).text()+'</li>');
            }
        });
        $('li', option_ul).mouseup(function() {
            label.text($(this).text());
            opt = options[$(this).attr('rel')];
            $(select).val($(this).text());
            option_ul.slideUp();
        });
        option_ul.hide();
        container.append(option_ul)
        $(this).after(container);
    });
});
