// JavaScript Document


      $(document).ready(function(){
	
			$('.register').click(function() {
				
				close_maps();
				target = $(this).attr('rel');
				$('#' + target).addClass('active_box');
				
				window.location = '#' + target;
				
				
			});	
			$('.map_contact').click(function() {
				
				close_maps();
				target = $(this).attr('href');
				$(target).addClass('active_box');
				
				window.location = '#' + target;
				
				return false;
				
			});
			$('.map_close').click(function() {
				
				close_maps();
				
			});
			function close_maps () { 
			
				$('.contact_box').removeClass('active_box');
			
			}
			$('.fbox_link').click(function() {
				
				var target = this;
				target = $(target).attr('href');
				var theClass = $('#contact_form').attr('class');
				var theClass2 = $('#graphic_box').attr('class');
				
				if (theClass2 == 'open') {

					$('.open_active').slideUp('slow', function() {
						
						$('.open_active').removeClass('open_active');
						$(target).slideDown('slow');
						$(target).addClass('open_active');
						$('#footer').css('display','block');
					});
					
				} 
				
				if (theClass == 'expanded') { 
						$(target).slideDown('slow');
						$(target).addClass('open_active');
						$('#graphic_box').addClass('open')
						$('#footer').css('display','block');
				}
				else { 
					$('#contact_form').slideDown('slow', function() { 

						var theLink = $('a.expand_form');

						$(theLink).removeClass('expand_form');
						$(theLink).addClass('colapse_form');
						$('#contact_form').addClass('expanded');

						$(target).slideDown('slow');
						$(target).addClass('open_active');
						$('#graphic_box').addClass('open');

					});  }
				return false;
			});
				
			$('.expand_form').click(function () {
			
				if ($('.expand_form').attr('rel') == 'down') {
			
				$('#contact_form').slideDown('slow', function() { 
				
					var theLink = $('a.expand_form');					
					$(theLink).addClass('colapse_form');
					$('#contact_form').addClass('expanded');
					$('.expand_form').attr({'rel':'up'});
					$('#footer').css('display','block');
				});
					
				return false;
				
				} else if ($('.expand_form').attr('rel') == 'up') {
					
					var theClass2 = $('#graphic_box').attr('class');

						if (theClass2 == 'open') { return false; }

						$('#contact_form').slideUp('slow', function() { 

							var theLink = $('a.expand_form');						
							$(theLink).removeClass('colapse_form');						
							$('#contact_form').removeClass('expanded');						
							$('.expand_form').attr({'rel':'down'});
											
						});

					return false; 

				}	
				
			});
		
			$('#subnav2 a').click(function() {
									
				var theLink = this;
															
				//unactivate all links
				$('#feature_box div.active').slideUp('slow', function () {
					
					$('#subnav2 a').removeClass('active');
					$('#feature_box div').removeClass('active');
					
					$('#subnav2').animate({width: 'hide'},'slow');
					$('.tw_progs').removeClass('active');
					$('.tw_progs').addClass('sactive');
					
					$('#subnav2').fadeTo(200, 1, function() { fade_display() });
					
				});
				
				function fade_display() {
					
					//activate this link
					$(theLink).addClass('active');
					var target = $(theLink).attr('href');
					target = target + "_s";
				//	$(target).fadeIn('slow');					
					$(target).slideDown('slow', function () { 
						$(target).addClass('active');
						});
					
				};
				
					//show new navigation
				
					return false; 
					
				
			});
			
			$('.subnav').click(function() {
				
				var target = $(this).attr('href');
				$('#subnav a').removeClass('active');
				$('#subnav a').removeClass('sactive');
				$('#subnav2 a').removeClass('active');
				$(this).addClass('active');
				
				$('#feature_box div.active').slideUp('slow', function() {
					$('#feature_box div.active').removeClass('active');
					target = target + "_s";
					//$(target).fadeIn('slow');
					$(target).fadeTo(200, 1).slideDown('slow', function() { $(target).addClass('active'); });
				});
				
			})
			
			$('.rollover2').click(function() {
				
				var target = $(this).attr('href');
				
				$('#feature_box div.active').fadeOut('slow', function() {
					
					target = target + "_s";
					$(target).addClass('active');
					$(target).fadeIn('slow');
					
				});
				
			});
			
			$('.reset_home').click(function() {
				
				$('#feature_box div.active').fadeOut('slow', function () {
				
					$('#feature_box div.active').removeClass('active');
					$('#first').fadeIn('slow');
					$('#first').addClass('active');
				
					$('#subnav a').removeClass('active');
					$('.reset_home').addClass('active');
				
				});
				
			});
			
			$('.error').hide();
			
			
				$(".ebutton").click(function() {

			      $('.error').hide();
			  	  var name = $("input#ename").val();
			  		if (name == "") {
			        $("label#ename_error").show();
			        $("input#ename").focus();
			        return false;
			      }
			  		var email = $("input#eemail").val();
			  		if (email == "") {
			        $("label#eemail_error").show();
			        $("input#eemail").focus();
			        return false;
			      }

					var phone = $("input#ephone").val();
					var company = $("input#ecompany").val();
					var message = $("textarea#emessage").val();
					var attend = $("input#eattendees").val();


					$('.ebutton').attr("disabled", "true"); //disable the button

				var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&company=' + company + '&attendees=' + attend + '&message=' + message;
				//  alert (dataString);return false;
				  $.ajax({
				    type: "POST",
				    url: "event_process.php",
				    data: dataString,
				    success: function() {
				      $('.theform_e_message').html("<div id='the_message'></div>");
				      $('#the_message').html("<h3>Thank you for your interest</h3>")
				      .append("<p>We will be in touch soon.</p>")
				      .hide()
				      .fadeIn(1500, function() {
				        $('#the_message').append("-Toyota Way Academy");
						$('.ebutton').removeAttr('disabled');  //disable the button
				      });
				    }
				  });


				  return false;

			    });
			
			
		    $(".button").click(function() {

		      $('.error').hide();
		  	  var name = $("input#cb_name").val();
		  		if (name == "") {
		        $("label#cb_name_error").show();
		        $("input#cb_name").focus();
		        return false;
		      }
		  		var email = $("input#cb_email").val();
		  		if (email == "") {
		        $("label#cb_email_error").show();
		        $("input#cb_email").focus();
		        return false;
		      }
				
				var phone = $("input#cb_phone").val();
				var company = $("input#cb_company").val();
				var message = $("textarea#cb_message").val();
				
				var subject = $("textarea#cb_subject").val();
				
		  		var interested = $("select#cb_interested").val();
		  		if (interested == "") {
		        $("label#cb_interested_error").show();
		        $("select#cb_interested").focus();
		        return false;
		      }
		
			$('.button').attr("disabled", "true"); //disable the button
		
			var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&company=' + company + '&interested=' + interested + '&message=' + message;
			//  alert (dataString);return false;
			  $.ajax({
			    type: "POST",
			    url: "/process.php",
			    data: dataString,
			    success: function() {
			      $('.theform_cb').html("<div id='the_message'></div>");
			      $('#the_message').html("<h2>Thank you for your interest</h2>")
			      .append("<p>We will be in touch soon.</p>")
			      .hide()
			      .fadeIn(1500, function() {
			        $('#the_message').append("-Toyota Way Academy");
					$('.button').removeAttr('disabled');  //disable the button
			      });
			    }
			  });
			  return false;

		    });
		
			$('.tw_progs').click(function(){
				
				var theLink = this;
				var status = $(theLink).attr('class');

				if (status == 'tw_progs sactive') {
				
					$('#subnav2').animate({width: 'show'},'slow');
				
					var theLink = this;
					$('#subnav a').removeClass('active');
					$(theLink).addClass('active');
					
					return false;
				
				}
				
				if (status == 'tw_progs active') {
					$('#subnav2').animate({width: 'hide'}, 'slow');
					$('#subnav a').removeClass('active');
					$('#subnav').removeClass('sactive');
					$('home').addClass('active');
				
					return false;
				} 
				if (status != 'active') {
					
						$('#subnav2').animate({width: 'show'},'slow');

							var theLink = this;
							$('#subnav a').removeClass('active');
							$(theLink).addClass('active');

							return false;
					
					
				}
				
			});
		  
	
				  
      });

