$(document).ready(function() {
    $('#slideshow').cycle({
        fx:     'fade',
        speed:  1000,
        timeout: 4500,
        pager:  '#slideNav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#slideNav li:eq(' + (idx) + ') a';
        }
    });
	
	$("#contact").validate();
	$("#emailForm").validate();
	
	$(".yay, .oops").hide();
	$(".yay, .oops").fadeIn(2000);
	
	$('#slideNav').click(function(){       
		$('#slideshow').cycle('pause');
	});
	$('.popup').click(function(){
		var id = this.id+"Shell";
		$('.bioCell').hide();
		$('#'+id).show();
		$('#bioBox').fadeIn('fast');
	});	
	$('#bioBox').click(function(){
		$('#bioBox').fadeOut('fast')
	});	
	$('.bioCell .bioNext').click(function(){
		var id = "bio"+$(this).attr("rel")+"Shell";
		$('.bioCell').hide();
		$('#'+id).show();
		return false;
	});	
	$('.bioCell .bioPrevious').click(function(){
		var id = "bio"+$(this).attr("rel")+"Shell";
		$('.bioCell').hide();
		$('#'+id).show();
		return false;
	});	
	$('.tabsNav li a').click(function(){ 
		pos = "current-"+this.id;      
		$('.tabsShell').attr("id",pos);
	}); 
						   
	$('#contactUs').click(function(){
		$('div.contactUsShell').toggle();
	});
	$('.closeContact').click(function(){
		$('div.contactUsShell').hide();
	});

	$('.text-input').css({backgroundColor:"#FFFFFF"});
	$('.text-input').focus(function(){
		$(this).css({backgroundColor:"#FFDDAA"});
	});
	$('.text-input').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
	});
	
	$('.rightContactForm .text-input').removeClass('error');
	$('.rightContactForm .text-input').focus(function(){
		$(this).removeClass('error');
	});
	$('.rightContactForm .text-input').blur(function(){
		$(this).removeClass('error');
	});

 	$("#contactForm .submit").click(function() {
	  var name = $("input#name").val();
		if (name == "") {
  		$('#name').css({backgroundColor:"#ED1C24"});
	      return false;
	    }
		var email = $("input#email").val();
		if (email == "") {
  		$('#email').css({backgroundColor:"#ED1C24"});
	      return false;
	    }
		var subject = $("input#subject").val();
		if (subject == "") {
  		$('#phone').css({backgroundColor:"#ED1C24"});
	      return false;
	    }
		var phone = $("input#phone").val();
		if (phone == "") {
  		$('#phone').css({backgroundColor:"#ED1C24"});
	      return false;
	    }
		var message = $("#message").val();
		if (message == "") {
  		$('#message').css({backgroundColor:"#ED1C24"});
	      return false;
	    }
		
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&phone=' + phone + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
	      type: "POST",
	      url: "/media/js/bin/process.php",
	      data: dataString,
	      success: function() {
			  
	        $('.contactFormShell').hide();
	        $('.successShell').html("<h2>Contact Form Submitted!</h2>")
	        .append("<p>We will be in touch soon.</p>")
	      }
	     });
	    return false;
	});

 	$("#leftContactShell .submit").click(function() {
	    var name = $("input#rightname").val();
		if (name == "") {
  		$('#rightname').addClass('error');
	      return false;
	    }
		var email = $("input#rightemail").val();
		if (email == "") {
  		$('#rightemail').addClass('error');
	      return false;
	    }
		var phone = $("input#rightphone").val();
		if (phone == "") {
  		$('#rightphone').addClass('error');
	      return false;
	    }
		var subject = name+" at "+email+" has requested more information, please contact them as soon as possible.";
		var message = subject;
		
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&phone=' + phone + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
	      type: "POST",
	      url: "../media/js/bin/process.php",
	      data: dataString,
	      success: function() {
	        $('#leftContactShell').html("<h2>Contact Form Submitted!</h2>")
	        .append("<p>We will be in touch soon.</p>")
	      }
	     });
	    return false;
	});

	$('#jobList > li > ul').hide();

    $('#jobList > li').click(function (event) {

        if (this !== event.target) {
            return false;
        }

        if ($('#jobList').is(':animated')) {
            return false;
        }

        $heading = $(this);
        $('#jobList > li > ul').slideUp(100);
		$heading.children("ul:hidden").slideDown(300);



    });


 });

