$(function() {

    $('#header-contact').html('<small>Need help? Call, Text or Email us</small><br />' +
                                '<a href="/page/contact-us.html"><strong class="big">(415) 997 9909</strong></a><br />' +
                                '<a href="/page/contact-us.html">HelpMe@Unanchor.com</a>');

    $('#social-links').html(
            '<a href="http://twitter.com/Unanchor" target="_blank" class="social-text"> \
                <img src="/images/twitter.png" alt="Follow Unanchor on Twitter" /> \
                <span>Follow us on Twitter</span> \
            </a><br /> \
            <a href="http://www.facebook.com/#!/group.php?gid=148240651855784" target="_blank" class="social-text"> \
                <img src="/images/travel-writing.png" alt="Join our I Love Travel Writing Facebook Group" /> \
                <span>Love Travel Writing?</span> \
            </a>'
            );

    //****** FEEDBACK FORM (FOOTER) ************//
    $('#feedbackform').submit(function() {

        // get all the inputs into an array.
        var values = {}; 
        $.each($('#feedbackform').serializeArray(), function(i, field) {
            values[field.name] = field.value;
        }); 

        $('#feedbackresponse').html('');

        $.ajax({
          url: "/mail/feedback",
          type: "POST",
          data: ( values ),
          dataType: "html",
          success: function(msg){
             if(msg == 'Invalid email address.') {
                $('#feedbackresponse').html(msg).css('color', '#ff0000');
             } else {
                 $('#feedback').html(msg).css('color', '#00aa00');
             }
          },
          error: function(msg){
             $('#feedbackresponse').html(msg).css('color', '#ff0000');
          }   
        }); 

        return false;

    }); 

    $('#feedbackmessage').focus(function() {
        $('#feedbackemail').show();
    });
    $('#feedback-text').html('How can we improve this site?');





/**
 *
 * Placeholder - implements placeholder text for form inputs that goes away when they gain focus, returns on blur
 *
 * If the browser has HTML5 support via 'placeholder' attribute, use that, otherwise falls-back to JavaScript implementation.
 *
 */
  $.fn.placeholder = function() {
    // Test for native placeholder support
    var test_element = document.createElement('input');
    if ('placeholder' in test_element && !$.browser.webkit) {
      return this;
    }

    function Placeholder(input) {
      this.input = input;
      this.text = this.input.attr('placeholder');
    }

    Placeholder.prototype.show = function() {
      if (this.input.val() === '') {
        this.input.val(this.text).addClass('placeholder');
      }
    };

    Placeholder.prototype.hide = function() {
      if (this.input.val() === this.text && this.input.hasClass('placeholder')) {
        this.input.val('').removeClass('placeholder');
      }
    };

    Placeholder.prototype.init = function() {
      var self = this;
      this.input
        .bind('focus', function() {
          self.hide();
        })
        .bind('blur', function() {
          self.show();
        });
      this.show();
    };


    var placeholder;
    return this.each(function() {
      placeholder = new Placeholder($(this));
      placeholder.init();
    });
  };

    $('.placeholder').placeholder();
});



