/**
 *
 * The Blue Crab Steakhouse
 *
 * This file contains the global javascript classes and functions. Excluding
 * the mootools framework file, this is the only script file included for the
 * entire website. 
 *
 * @package bluecrab
 * @package bluecrab-scripts
 *
 * @author Rob Frawley <enterpc@robfrawley.com>
 * @copyright (c) 2009 Enterprise Computers
 *
 */

var MainNavigation = new Class({

  initialize: function(container) {
    
    if(!$(container)) return;
    
    this.container = $(container);
    this.listitems = this.container.getElements("li");
    
    this.assignEvents();
    
  },
  
  assignEvents: function() {

    this.listitems.each(function(li, i) {
      
      a = li.getElement('a');
      a.addEvents({
        'mouseenter': function(e) { new Event(e).stop(); this.handleMouseenter(e, li, a); }.bind(this),
        'mouseleave': function(e) { new Event(e).stop(); this.handleMouseleave(e, li, a); }.bind(this)
      });
      
    }.bind(this)); 
    
  },
  
  handleMouseenter: function(e, li, a) {},

  handleMouseleave: function(e, li, a) {}
  
});

var MenuEffects = new Class({

  initialize: function(container) {
    
    if(!$(container)) return;
    
    this.container = $(container);
    this.ulists = this.container.getChildren("ul");

    this.assignEvents();
    
  },
  
  assignEvents: function() {

    this.ulists.each(function(ul, i) {
      
      lis = ul.getChildren('li');
      lis.each(function(li, i) {
        
        clis = li.getElements('li');
        

      }.bind(this))

    }.bind(this)); 
    
  },
  
  handleMouseenter: function(e, li, a) {},

  handleMouseleave: function(e, li, a) {}
  
});

var GoogleMapForm = new Class({
  
  initialize: function(form, inputStartLocation) {
    
    /* do not continue class functionality if IDs do not exist */
    if(!$(form) || !$(inputStartLocation)) return;

    /* assign class variables used later in member functions */
    this.form = $(form);
    this.form = $(form);
    this.inputStartLocation = $(inputStartLocation);
    this.inputSubmit = $("submit");
		this.badd = "Example: 123 Main St. Middletown CT 06457";
    this.badd_error = "Please enter your starting address!";
		
    /* call appropriate actions/functions */
    this.inputStartLocation.setProperty("value", this.badd);
		this.assignEvents();
  },
  
	assignEvents: function() {

		this.inputStartLocation.addEvents({
		  'focus': function(e) { this.handleSlFocus() }.bind(this),
		  'blur': function(e) { this.handleSlBlur() }.bind(this)
		});

		this.inputSubmit.addEvent('click', function(e) { this.handleSubmit(e) }.bind(this));
		
	},
	
	handleSlFocus: function(e) {

	  this.inputStartLocation.setProperty("value", "");
	  this.inputStartLocation.removeClass('mt_form-input-error');
	  
	},
	
	handleSlBlur: function(e) {
	  
	  if(!this.inputStartLocation.getProperty("value")) {
	    this.inputStartLocation.setProperty("value", this.badd);
	  }
	  
	},
	
	handleSubmit: function(e) {
	  
	  if(this.inputStartLocation.getProperty("value") == this.badd ||
	     !this.inputStartLocation.getProperty("value") ||
	     this.inputStartLocation.getProperty("value") == this.badd_error) {
	    
	    e.stop();
	    this.inputStartLocation.addClass('mt_form-input-error');
	    this.inputStartLocation.setProperty("value", this.badd_error);
	    
	  } else {
	    
	    this.inputSubmit.setProperty("value", "Mapping...");
	    
	  }
	  
	},
	
});

window.addEvent('domready', function(){

  //new MainNavigation('Header_Navigation');
  //new MenuEffects('Content_Menu');
  new GoogleMapForm('GoogleMapDirections', 'saddr');

}.bind(this));
