//Drop Down Menu
var DropDownMenu = new Class({
  
  initialize: function(element){
    this.element = $(element);
    this.element.getChildren().each(function(element){
      element.set('opacity', 0.85);
      var div = element.getElement('div');
      if (div){
        div.set('slide', { wait: false, duration: 400, transition: 'cubic:out' }).slide('hide');
        element.addEvents({
          mouseenter: div.slide.bind(div, 'in'),
          mouseleave: div.slide.bind(div, 'out')
        });
      }
    }, this);
  }
  
});

//Slide Show
var SlideShow = new Class({
  
  Implements: Options,
  
  options: {
    width: 800,
    height: 600,
    duration: 3000
  },
  
  initialize: function(element, images, options){
    this.setOptions(options);
    this.images = images;
    
    var styles = {
      top: 0,
      left: 0,
      position: 'absolute',
      width: this.options.width,
      height: this.options.height,
      background: '#fff no-repeat center center'
    };
    
    this.image1 = new Element('div', { styles: styles });
    this.image2 = new Element('div', { styles: styles });
    
    this.image = new Element('img', {
      events: { load: this.load.bind(this) },
      styles: { top: -1000, left: -1000, position: 'absolute', visibility: 'hidden' }
    }).inject(document.body);
    
    this.container = new Element('div', {
      events: { click: this.launch.bind(this) },
      styles: { cursor: 'pointer', position: 'relative' }
    }).inject(element).adopt(this.image1, this.image2);
    
    this.rotate();
    this.rotate.periodical(this.options.duration, this);
  },
  
  load: function(){
    this.image1.setStyle('background-image', 'url(' + this.image.src + ')');
    this.image2.fade('out');
  },
  
  rotate: function(){
    var image = this.images.getRandom();
    this.image2.setStyle('background-image', 'url(' + this.image.src + ')').fade('show');
    this.image.src = image[0];
    this.href = image[1];
  },
  
  launch: function(){
    document.location = this.href;
  }
  
});

//email validation
function validateMailing(form) {
  with (form){
    var error = "The following fields were left blank:\n";
    if (name.value == "" || name.value == null) error += "\tName\n";
    if (email.value == "" || email.value == null || email.value.match("^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$") == null ) error += "\tEmail\n";
    if (error != "The following fields were left blank:\n"){ alert(error); return false; }
    return true;
  }
}








