$(document).ready(function() {
	
	//Profile effect
	//Melissa bio
	$('#melissa_img').click(function() {		
		$(this).next().toggle();		
		$('#dean_img').next().hide();		
		$('#dan_img').next().hide();
		$('#darin_img').next().hide();			
	});
	//Dean bio
	$('#dean_img').click(function() {		
		$(this).next().toggle();		
		$('#melissa_img').next().hide();		
		$('#dan_img').next().hide();
		$('#darin_img').next().hide();			
	});
	//Dan bio
	$('#dan_img').click(function() {		
		$(this).next().toggle();		
		$('#melissa_img').next().hide();		
		$('#dean_img').next().hide();
		$('#darin_img').next().hide();			
	});
	//Darin bio
	$('#darin_img').click(function() {		
		$(this).next().toggle();		
		$('#melissa_img').next().hide();		
		$('#dean_img').next().hide();
		$('#dan_img').next().hide();			
	});
	
	//Ajax contact form
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var comments = $("textarea#comments").val();
		if (comments == "") {
      $("label#comments_error").show();
      $("textarea#comments").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&comments=' + comments;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h3>Contact Form Submitted!</h3>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
	
	//Products cycling
	
	$('#sheet_metal_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager1'
	});
	$('#glass_fragile_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager2'
	});
	$('#seat_trim_interior_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager3'
	});
	$('#structural_frame_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager4'
	});
	$('#suspension_brake_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager5'
	});
	$('#engine_transmission_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager6'
	});	
	$('#nonreturnable_bins_gal').cycle({
		timeout: 4800,
		fx:      'fade',
		pager:   '#pager7'
	});
	
	//Products
	//Change the behavior of a href
	$('#product_list li a').click(function(e) {
		e.preventDefault();		
	})
	//Hide them all to start
	$('.product_gallery').hide();
	$('.pager').hide();
	//Show this one by default
	$('#sheet_metal_gal').show();
	$('#pager1').show();	
	//Go through each link to show and hide
	$('#show_sheet').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#sheet_metal_gal').show();
		$('#pager1').show();		
	});
	$('#show_glass').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#glass_fragile_gal').show();
		$('#pager2').show();
	});
	$('#show_seat').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#seat_trim_interior_gal').show();
		$('#pager3').show();
	});
	$('#show_structural').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#structural_frame_gal').show();
		$('#pager4').show();
	});
	$('#show_suspension').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#suspension_brake_gal').show();
		$('#pager5').show();
	});
	$('#show_engine').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#engine_transmission_gal').show();
		$('#pager6').show();
	});
	$('#show_bins').click(function(){
		$('.product_gallery').hide();
		$('.pager').hide();
		$('#nonreturnable_bins_gal').show();
		$('#pager7').show();
	});
	
	//Case Studies
	//Change the behavior of a href
	$('.case_study_example li a').click(function(e) {
		e.preventDefault();		
	})
	//Hide them all to start
	$('.cs_gallery').hide();
	//Show this one by default
	$('#steering_cs_gal').show();	
	//Go through each link to show and hide
	$('#cs_steering').click(function(){
		$('.cs_gallery').hide();
		$('#steering_cs_gal').show();		
	});
	$('#cs_sunroof').click(function(){
		$('.cs_gallery').hide();
		$('#sunroof_cs_gal').show();		
	});
	$('#cs_rotor').click(function(){
		$('.cs_gallery').hide();
		$('#rotor_cs_gal').show();		
	});
	$('#cs_seat').click(function(){
		$('.cs_gallery').hide();
		$('#seat_cs_gal').show();		
	});
	$('#cs_repaired').click(function(){
		$('.cs_gallery').hide();
		$('#repaired_cs_gal').show();		
	});
	
	
	//Column heights
	var left = $('.interior_left').height();
	var right = $('.interior_right').height();
	
	if (left > right && left < 799)
	{
		$('.interior_right').height(left);
	}
	else if ( left > right && left > 800) {
		$('#content.interior_left').css({
			'background' : 'url(../images/steel_bg_bottom.png)',
			'background-repeat' : 'repeat-x',
			'background-position' : 'bottom left'
			});
		$('.interior_right').height(left);
	}
	else {
		$('.interior_left').height(right);
	}
    
    
    
    $(".product-detail").click(
  function () {
    
    var currentId = $(this).attr('id');
    
    
    $('.product_container').hide('fast');
   // $('#'+currentId).css('border','1px solid #084582');


   // alert(currentId);
    $('#product'+currentId).show('slow');
  },
  function () {
    
  }
  
  
  

);


  /** keep product detail div on top */
  var $scrollingDiv = $(".product_container");
 
		$(window).scroll(function(){			
			$scrollingDiv
				.stop()
				.animate({"marginTop": (Math.max(0, $(window).scrollTop() - 200)) + "px"}, "slow");
		
		});




});


