var newsletterBox = new Class(
{
  initialize: function() {
  
    this.backgroundColor = new Color('#29363E');
  
    this.count = 0;
    
    this.fieldContent = 'your email ...';
    this.myForm = $('myNewsletter');
    this.myTrigger = $('newsletterSubmit');
    this.myInput = $('newsletterEmail');

    //Show/Hide searchCategories
    this.fx = new Fx.Morph( $('searchCategories'), {
      duration:160,
      fps: 36,
      link:'cancel',
      transition: Fx.Transitions.Sine.easeIn,

      onStart: function(myTween){
      //alert (typeOf(myTween));
	  //      myTween.highlight('white');
      }
    });

    if (this.myInput.getProperty('value') === '') {
      this.myInput.setProperty('value',this.fieldContent);
      this.myInput.addEvent('click',function () {if (this.value === this.fieldContent) { this.value = '' }});
    }
    
    //Den regulären Submit Event der Form bei click unterbrechen
    this.myForm.addEvent('submit',function (e) {e.stop();});
    //und den click mit eigenem Submit versehen 
    this.myTrigger.addEvent('click',this.submit.bind(this));
    //Den Submit Button umfunktionieren
    //this.myTrigger.addEvent('click',this.enter.bind(this));

  },
 
  enter: function(){
    //this.fx.start({ 'opacity': '1'});
    this.myTrigger.removeEvents('click');
    this.myTrigger.addEvent('click',this.leave.bind(this));
  },
 
  leave: function() {
    //this.fx.start({ 'opacity': '0'});
    this.myTrigger.removeEvents('click');
    this.myTrigger.addEvent('click',this.enter.bind(this));
  },
  submit: function() {

    $check = this.myInput.getProperty('value');

    if ($check === '' || $check === this.fieldContent) {
      this.count++;
      var myColor = this.backgroundColor.setBrightness(24+this.count*3);

      this.myInput.setStyle('background-color',myColor);
      this.myInput.focus();
      this.myInput.select();

      if (this.count>=5) {
        this.myInput.setProperty('value','you may start typing now...');
        alert ('you clicked this button '+ this.count +' times \n and yet, nothing happened. \n\n Consider entering your email address.');
      }
    } else {
      this.myForm.removeEvents('submit');
    }

  }
}
)
 
window.addEvent('domready', function() {
  var myNewsletterBox = new newsletterBox();
});