function menu() {
this.states = new Array("Alabama","Alaska ","Arizona","Arkansas","California","Colorado","Connecticut","DC","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming");

this.states_urls = new Array("alabama","alaska","arizona","arkansas","california","colorado","connecticut","district-of-columbia","delaware","florida","georgia","hawaii","idaho","illinois","indiana","iowa","kansas","kentucky","louisiana","maine","maryland","massachusetts","michigan","minnesota","mississippi","missouri","montana","nebraska","nevada","new-hampshire","new-jersey","new-mexico","new-york","north-carolina","north-dakota","ohio","oklahoma","oregon","pennsylvania","rhode-island","south-carolina","south-dakota","tennessee","texas","utah","vermont","virginia","washington","west-virginia","wisconsin","wyoming");

    
  if (typeof menu._initialized == "undefined") {
     
    menu.prototype.build = function () {
      $ev("select_state_home", "mousedown", this.select_state_home_drop, this, true);
      $ev("username", "click", this.clear_email, this, true);
      $ev("pass_text", "click", this.change_bg, this, true);
      $ev("pass_text", "keypress", this.change_bg, this, true);
      $ev("pass_text", "focus", this.change_bg, this, true);
      $ev("pass_text", "change", this.change_bg, this, true);
      $ev("login_button", "click", this.check_vals, this, true);
    }
 

    menu.prototype.select_state_home_drop = function () {
      $evR("select_state_home", "mousedown", this.select_state_home_drop);
      this.state_select_home = $("select_state_home");      
      for (i=0;i<50;i++){
        new_op = new Option(this.states[i],this.states_urls[i])
        this.state_select_home.options[i+1] = new_op;
      } 
      $ev("select_state_home", "change", this.select_state_redirect);
    }
 
    
    menu.prototype.select_state_redirect = function () {
      selected_state = this.options[this.selectedIndex].value;
      if (selected_state != -1){
        window.location.href = "/"+selected_state+"/";
      }
    }
    
    
    menu.prototype.clear_email = function () {
      $evR("username", "click", this.clear_email);
      this.username = $("username");
      this.username.value = "";
    }
    
    menu.prototype.change_bg = function () {
      $evR("pass_text", "click", this.change_bg);
      $evR("pass_text", "keypress", this.change_bg);
      $evR("pass_text", "focus", this.change_bg);
      $evR("pass_text", "change", this.change_bg);
      $("password").style.display = "block";
      $("password").focus();
      $("pass_text").style.display = "none";
    }
    
    
    menu.prototype.check_vals = function () {
      this.change_bg();
      this.email = $("username");
      this.pass  = $("password"); 
      this.login_form  = $("login_form"); 
      this.focus_set = false;
      
      if (this.email.value.length == 0){
        this.error_message = "Enter your email address.";
        this.error_div     = "username";
        if(!this.focus_set) { this.email.focus(); this.focus_set = true; }
        this.passed = false;
      } else if (this.email.value == "email"){
        this.email.value = "";
        this.error_message = "Enter your email address.";
        this.error_div     = "username";
        if(!this.focus_set) { this.email.focus(); this.focus_set = true; }
        this.passed = false;
      } else if (this.pass.value.length == 0){
        this.error_message = "Enter a password.";
        this.error_div     = "password";
        if(!this.focus_set) { this.pass.focus(); this.focus_set = true; }
        this.passed = false;
        this.change_bg();
      } else {
        this.passed = true;
      }
     
      if (this.passed){ 
        this.login_form.submit(); 
      } else { 
        this.error_tip = new YAHOO.widget.Overlay("error_tip", {context:[this.error_div,"tl","bl"], visible:false, width:"200px", zIndex:1500 });
        this.error_tip.setBody('<div class="error_message">'+this.error_message+'</div>'); 
        this.error_tip.render(document.body); 
        this.error_tip.show();
        $ev(this.error_div, "keypress", this.hide_error, this, true);
        $ev(this.error_div, "blur", this.hide_error, this, true);
      }
    }
    
    
    menu.prototype.hide_error = function () {
      $evR(this.error_div, "keypress", this.hide_error);
      $evR(this.error_div, "blur", this.hide_error);
      this.error_tip.hide();
    }
     
     
    menu.prototype.reload_menu = function () {
      this.ajax  = new ajaxtester(); this.ajax.test();
      if (typeof(this.send_call) == "undefined") this.send_call = new send_call(this, "menu");
			this.send_call.set_call("reload_menu");
			this.send_call.send(this.ajax.ajax_support);
    }
    

  	menu.prototype.return_call = function (response_text, call) { 
  		switch(call){
    		case "reload_menu":
    		  var m = $JSON(response_text);
          dash_loader.jobvana_uid = m.uid;
    		  $("main_nav").innerHTML = m.code;
    		break;
  		}
  	};
    
  	
  	/*
  	* Logout Function
  	*/
  	menu.prototype.logout = function () {
  	  FB.getLoginStatus(function(response) { 
        if (response.session) {
          FB.logout(function(response) {
            window.location.replace('/logout/');
          }); 
        } else {
          window.location.replace('/logout/');
        }
      });
  	};
  	
  	
    menu._initialized = true;
  } 
}
