﻿jQuery(function() {
    jQuery('form#formNewsletter label').each(function() {
        // style the label with JS for progressive enhancement
        jQuery(this).css({
            'position': 'absolute',
            'top': '6px',
            'left': '5px',
            'display': 'inline',
            'z-index': '99'
        });

        // grab the input value
        var inputval = jQuery(this).next('input').val();

        // grab the label width, then add 5 pixels to it
        var labelwidth = jQuery(this).width();
        var labelmove = labelwidth + 5;

        //onload, check if a field is filled out, if so, move the label out of the way
        if (inputval !== '') {
            jQuery(this).stop().animate({ 'left': '-' + labelmove }, 1);
        }

        // if the input is empty on focus move the label to the left
        // if it's empty on blur, move it back
        jQuery('input').focus(function() {
            var label = jQuery(this).prev('label');
           
            var value = jQuery(this).val();

            if (value == '') {
                label.stop().animate({ 'top': '-15px' }, 'fast');
            } else {
                label.css({ 'top': '-15px' });
            }
        }).blur(function() {
            var label = jQuery(this).prev('label');
            var value = jQuery(this).val();
            if (value == '') {
                label.stop().animate({ 'top': '6px' }, 'fast');
            }
        });
    })
});
