// DD_belatedPNG fix for IE6
if (typeof DD_belatedPNG !== 'undefined') {
	var PNG_fix_selectors = [
		'selector-1',
		'selector-2'
	];
	DD_belatedPNG.fix(PNG_fix_selectors.join(','));
}

$(document).ready(function onload(){
    //hide error box
    $('#join_form_error').hide();
    
    //art rollover
/* disable for launch 
    $(".art-by").hide();
    $(".art-image").hover(
      function() { 
        $(".art-by").show();
      },function() { 
        $(".art-by").hide();
    });
*/    
    //clear placeholders on click
    // from https://gist.github.com/379601
    $('[placeholder]').focus(function() {
      var input = $(this);
      if (input.val() == input.attr('placeholder')) {
        input.val('');
        input.removeClass('placeholder');
      }
    }).blur(function() {
      var input = $(this);
      if (input.val() == '' || input.val() == input.attr('placeholder')) {
        input.addClass('placeholder');
        input.val(input.attr('placeholder'));
      }
    }).blur();
    
    //join form validation
    $('form#join_form #id_go').click(function(data) {
      //validate email
      //regex from http://www.regular-expressions.info/regexbuddy/email.html
      var email_regex = new RegExp(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i);
      var email_entered = $("#join_form input[name=email]").val();
      var email_match = email_regex.test(email_entered);
      if (email_entered === "" | !email_match) {
        $('#join_form_error').text('Please enter a valid email address.').show();
        $("#join_form input[name=email]").focus();
        return false;
      } else {
          $("#join_form_error").hide();
      }

      //check if name empty
      var name = $("#join_form input[name=name]").val();
      if (name === "" || name === "name") {
        $('#join_form_error').text('Please enter your name.').show();
        $("#join_form input[name=name]").focus();
        return false;
      } else {
          $('#join_form_error').hide();
      }

      //validate zip
      var zip_regex = new RegExp(/^\d{5}([\-]\d{4})?$/);
      var zip_entered = $("#join_form input[name=zip]").val();
      var zip_match = zip_regex.test(zip_entered);
      if (zip_entered === "" | !zip_match) {
        $('#join_form_error').text('Please enter your zip code, or 00000 if you do not live in the US.').show();
        $("#join_form input[name=zip]").focus();
        return false;
      } else {
          $("#join_form_error").hide();
      }
    })
});
