window.addEvent("domready", function(){
  
  //instantiate slideshow
  var myStack = new Stack('stack1', {
    duration:800, 
    interval:6000, 
    width:355, 
    height:245, 
    transition: Fx.Transitions.backOut
  });

//form stuff
  
  //highlight text fields on focus
  $$('.textfield').each(function(el){
    var fieldHL = new Fx.Styles(el, { duration:500, transition: Fx.Transitions.Quad.easeInOut, wait:false });
    el.addEvents({
      'focus': function(){
        if((this.hasClass('name') && this.value == 'Full Name') || (this.hasClass('email') && this.value == 'Email Address')){
          this.value = '';
        }
        fieldHL.start({ 'opacity': 1, 'color': '#a9b7cd' });
      },
      'blur': function(){
        var color = '#a9b7cd';
        if(this.hasClass('name') && (this.value == '' || this.value == 'Full Name')){
          this.value = 'Full Name';
          color = '#343d4d';
        }else if(this.hasClass('email') && (this.value == '' || this.value == 'Email Address')){
          this.value = 'Email Address';
          color = '#343d4d';
        }
        fieldHL.start({ 'opacity': 0.7, 'color': color });
      }
    }, el);
    fieldHL.set({ 'opacity': 0.7 });
  });
  
  //function to hide/show 'continue...' button
  $('reg_continue').style.display = 'block';
  $('reg_continue').href = 'javascript:void(0);';
  toggleBtn = new Fx.Style($('reg_continue'), 'opacity', { duration: 500, wait:false });
  $('reg_continue').addEvents({
    'click': function(){ $('slideout').fireEvent('show'); }
  });
  $('team_name').addEvents({
    'keypress': function(evt){ var evt = new Event(evt); if(evt.key == 'enter'){ evt.stop(); $('slideout').fireEvent('show'); }}
  });
  $('reg_cancel').href='javascript:void(0);';
  $('reg_cancel').addEvents({
    'click': function(){ $('slideout').fireEvent('hide'); }
  });
  
  //slide down reg form when clicked
  regSlide = new Fx.Styles($('slideout'),{ duration:500, transition: Fx.Transitions.Circ.easeOut, wait:false });
  regSlide.fHeight = $('slideout').getSize();
  regSlide.fHeight = regSlide.fHeight['size']['y'];
  regSlide.set({'height':0, 'opacity':0});
  $('slideout').addEvents({
    'show': function(){
      // if($('team_name').value!=''){
        regSlide.start({ 'opacity': 1, 'height': regSlide.fHeight+15, 'margin-bottom':30 });
        toggleBtn.start(0);
      // }else{
      //   notify('error', 'Please enter a team name!');
      // }
    },
    'hide': function(){
      regSlide.start({ 'opacity': 0, 'height': 0, 'margin-bottom':0 });
      toggleBtn.start(1);
      $$('.textfield').each(function(el){
        if(el.hasClass('name')){
          el.value = "Full Name";
        }else if(el.hasClass('email')){
          el.value = "Email Address";
        }else if(el.hasClass('teamname')){
          el.value = '';
        }
      })
    }
  });

  //submit form
  // $('reg_submit').setProperty('type','button');//js is turned on, we'll use ajax to submit
  // var error=false;
  $('reg_submit').addEvents({
    'click': function(){
      $$('.textfield').each(function(el){
        if(el.value=='' || el.value=='Full Name' || el.value=='Email Address'){
          //notify('error', 'Please fill out all fields!');
          //error = true;
          //return;
          el.value = 'TBD';
        }
      });
      // if(error==false){
      //   //comment out the next 3 lines and uncomment the 4th to use traditional post submission
      //   $('reg_submit').addClass('sending');
      //   $('reg_submit').disabled = 'disabled';
      //   var postForm = new Ajax('###handlerFile.php###', {method: 'post', data: $('reg_form'), onComplete: function(t){ /*need to know server response*/ } }).request();
      //   // $('reg_form').submit();
      // }
    }
  });
  
  // //return status
  // regEcho = new Fx.Styles($('reg_notify'), {duration:500, transition: Fx.Transitions.Quad.easeInOut, wait:false});
  // regEcho.set({ 'opacity':0, 'height':0});
  // regEcho.busy = false;
  // function notify(type, string){
  //   if(regEcho.busy==false){
  //     $('reg_submit').disabled='';
  //     regEcho.busy = true;
  //     if($$('#reg_notify p').length>0){
  //       $$('#reg_notify p').each(function(el){ el.remove() });
  //     }
  //     var p = new Element('p', { 'class': type });
  //     p.setHTML(string);
  //     p.injectInside('reg_notify');
  //     regEcho.start({
  //       'opacity':1,
  //       'height': 10
  //     });
  //     (hideNotify).delay(3000);
  //   }
  // }
  // function hideNotify(){
  //   if(regEcho.busy == true){
  //     regEcho.start({
  //       'opacity':0,
  //       'height':0
  //     });
  //     regEcho.busy = false;
  //   }
  // }
  
});