/* Author: 

*/
  
$(document).ready(function() {
  
  if (Modernizr.input.placeholder) {
    
  } else {
    
    $('[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();

    $('[placeholder]').parents('form').submit(function() {
      $(this).find('[placeholder]').each(function() {
        var input = $(this);
        if (input.val() == input.attr('placeholder')) {
          input.val('');
        }
      })
    });
    
  };
  
  $(".subscribe").click(function() {
	  if ($('#dimmer').hasClass('hide')) {
	    var email = $('#email').val(); // Sender email
		jQuery.get( 'mailing/?action=subscribe', {email : email}, handle_subscribe );
	  } else {
	  	var email = $('#email_popup').val(); // Sender email
	    jQuery.get( 'mailing/?action=subscribe', {email : email}, handle_subscribe_popup );
	  } 
  });
  
  $(".close").click(function() {
	  jQuery.get( 'mailing/?action=setcookie');
	  $('#dimmer').addClass('hide');
  });

  
  // Handles sending responce...
  function handle_subscribe( resp ){
	// if there are errors in the input...
	if( resp.status == 2 || resp.status == 0){
		$('#validation').removeClass('hidden');
	} else {
		$('#form').html('<p>'+ resp.message + '</p>');
	}
  }	
  
  // Handles sending responce...
  function handle_subscribe_popup( resp ){
	// if there are errors in the input...
	if( resp.status == 2 || resp.status == 0){
		$('.validation p').addClass('error');
		$('.subscribe_results_popup').show().html(resp.message).fadeIn('slow');
	} else {
		$('.subscribe_results_popup').show().html(resp.message).fadeIn('slow');
		$('#dimmer').addClass('hide');		
	}
  }	
 
  $(".partners").hover(function() {
    $("#partners ul").addClass('reveal');
  }, function() {
    $("#partners ul").removeClass('reveal');
  });

});


